https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113964
Bug ID: 113964 Summary: repeat copy of struct Product: gcc Version: 13.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: absoler at smail dot nju.edu.cn Target Milestone: --- here's the code: ``` struct S1 { uint32_t f0; uint8_t f1; uint64_t f2; uint64_t f3; int32_t f4; }; union U8 { struct S1 f0; int32_t f1; int64_t f2; uint8_t f3; const int64_t f4; }; /* --- GLOBAL VARIABLES --- */ struct S1 g_16 = {4294967293UL,1UL,1UL,0xA9C1C73B017290B1LL,0x5ADF851FL}; union U8 g_37 = {{1UL,1UL,0x2361AE7D51263067LL,0xEEFD7F9B64A47447LL,0L}}; struct S1 g_50 = {0x0CFC2012L,1UL,0x43E1243B3BE7B8BBLL,0x03C5CEC10C1A6FE1LL,1L}; /* --- FORWARD DECLARATIONS --- */ void func_32(union U8 e) { e.f3 = e.f0.f4; g_16 = e.f0 = g_50; } ``` and compiled with gcc-13.2.0 -O2, generated binary code is: ``` 0000000000401400 <func_32>: func_32(): /root/myCSmith/test/output2.c:54 401400: movzbl 0x2c79(%rip),%eax # 404080 <g_50> 401407: movdqa 0x2c71(%rip),%xmm0 # 404080 <g_50> 40140f: movdqa 0x2c79(%rip),%xmm1 # 404090 <g_50+0x10> 401417: movups %xmm0,0x8(%rsp) 40141c: mov %al,0x8(%rsp) 401420: mov 0x2c72(%rip),%eax # 404098 <g_50+0x18> 401426: movups %xmm1,0x18(%rsp) 40142b: movdqu 0x8(%rsp),%xmm2 401431: mov %eax,0x20(%rsp) 401435: movdqu 0x18(%rsp),%xmm3 40143b: movaps %xmm2,0x2c7e(%rip) # 4040c0 <g_16> 401442: movaps %xmm3,0x2c87(%rip) # 4040d0 <g_16+0x10> /root/myCSmith/test/output2.c:55 401449: retq 40144a: nopw 0x0(%rax,%rax,1) ``` we can see that g_50.f0 and g_50.f4 have been repeatedly copy to e.