public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/99258] New: volatile struct access optimized away
@ 2021-02-24 18:17 borysp at invisiblethingslab dot com
  2021-02-24 18:58 ` [Bug tree-optimization/99258] " pinskia at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: borysp at invisiblethingslab dot com @ 2021-02-24 18:17 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 99258
           Summary: volatile struct access optimized away
           Product: gcc
           Version: 10.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: borysp at invisiblethingslab dot com
  Target Milestone: ---

Access to a volatile struct is optimized away, if the size of the struct is
>16B (at least on x64 cpu with sse). Small repro:
[borys@mowmiwuju test]$ cat a.c
struct A {
    long a;
    long b;
};

struct B {
    long a;
    long b;
    long c;
};

void f(volatile struct A* x) {
    *x;
}

void g(volatile struct B* x) {
    *x;
}
[borys@mowmiwuju test]$ gcc --version 
gcc (GCC) 10.2.0
[borys@mowmiwuju test]$ gcc -Wall -Wextra -std=c11 -O2 -c a.c
[borys@mowmiwuju test]$ objdump -d -Mintel a.o

a.o:     file format elf64-x86-64


Disassembly of section .text:

0000000000000000 <f>:
   0:   f3 0f 6f 07             movdqu xmm0,XMMWORD PTR [rdi]
   4:   c3                      ret    
   5:   66 66 2e 0f 1f 84 00    data16 cs nop WORD PTR [rax+rax*1+0x0]
   c:   00 00 00 00 

0000000000000010 <g>:
  10:   c3                      ret 


Testing on https://godbolt.org/ indicates this issue is present in all gcc
versions. clang emits correct code for this test case.

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

end of thread, other threads:[~2024-06-05  7:01 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-24 18:17 [Bug tree-optimization/99258] New: volatile struct access optimized away borysp at invisiblethingslab dot com
2021-02-24 18:58 ` [Bug tree-optimization/99258] " pinskia at gcc dot gnu.org
2021-02-25  8:19 ` [Bug middle-end/99258] " rguenth at gcc dot gnu.org
2021-02-25  9:15 ` jakub at gcc dot gnu.org
2024-06-05  7:01 ` rguenth 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).