public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/113106] New: Missing CSE with cast to volatile
@ 2023-12-21 10:38 ubizjak at gmail dot com
  2023-12-21 10:41 ` [Bug c/113106] " ubizjak at gmail dot com
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: ubizjak at gmail dot com @ 2023-12-21 10:38 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113106

            Bug ID: 113106
           Summary: Missing CSE with cast to volatile
           Product: gcc
           Version: 12.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ubizjak at gmail dot com
  Target Milestone: ---

The following testcase:

--cut here--
int a;

int foo(void)
{
  return *(volatile int *) &a + a;
}
--cut here--

compiles with -O2 to:

        movl    a(%rip), %eax
        addl    a(%rip), %eax
        ret

with more detail:

#(insn:TI 6 7 8 2 (set (reg:SI 0 ax [orig:98 _1 ] [98])
#        (mem/v/c:SI (symbol_ref:DI ("a") [flags 0x2] <var_decl
0x7f59db15ac60a>) [1 MEM[(volatile int *)&a]+0 S4 A32])) "vol.c":5:10 85
{*movsi_internal}
#     (nil))
        movl    a(%rip), %eax   # 6     [c=5 l=6]  *movsi_internal/0
#(insn 8 6 14 2 (parallel [
#            (set (reg:SI 0 ax [102])
#                (plus:SI (reg:SI 0 ax [orig:98 _1 ] [98])
#                    (mem/c:SI (symbol_ref:DI ("a") [flags 0x2] <var_decl
0x7f59db15ac60 a>) [1 a+0 S4 A32])))
#            (clobber (reg:CC 17 flags))
#        ]) "vol.c":5:31 271 {*addsi_1}
#     (expr_list:REG_UNUSED (reg:CC 17 flags)
#        (nil)))
        addl    a(%rip), %eax   # 8     [c=9 l=6]  *addsi_1/1

This may be compiled to:

        movl    a(%rip), %eax
        addl    %eax, %eax
        ret

since only one read uses volatile.

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2023-12-21 15:11 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-21 10:38 [Bug c/113106] New: Missing CSE with cast to volatile ubizjak at gmail dot com
2023-12-21 10:41 ` [Bug c/113106] " ubizjak at gmail dot com
2023-12-21 10:44 ` ubizjak at gmail dot com
2023-12-21 12:50 ` rguenth at gcc dot gnu.org
2023-12-21 12:57 ` ubizjak at gmail dot com
2023-12-21 13:02 ` ubizjak at gmail dot com
2023-12-21 13:29 ` [Bug rtl-optimization/113106] " rguenth at gcc dot gnu.org
2023-12-21 15:08 ` ubizjak at gmail dot com
2023-12-21 15:11 ` pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).