https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105546
Bug ID: 105546 Summary: load introduction when copying a struct Product: gcc Version: 11.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: rtl-optimization Assignee: unassigned at gcc dot gnu.org Reporter: absoler at smail dot nju.edu.cn Target Milestone: --- Created attachment 52948 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=52948&action=edit case file Hi, here's the code: ... struct S0 { unsigned short f0; unsigned short f1; short f2; unsigned char f3; long long f4; long long f5; }; short g_344 = 0xC307L; struct S0 func_1(void) { struct S0 l_346 = {65526UL,1UL,-8L,0xA1L,0x2F513C84A35AAE1BLL,-6L}; if (g_344) { struct S0 l_345 = {0x0AB2L,0x6D27L,-1L,0xABL,3L,0x3E72F31FF82C1E35LL}; return l_345; } else { return l_346; } } ... with option -O1, gcc-11.3.0 generate the following code: Dump of assembler code for function func_1: 0x0000000000401126 <+0>: mov %rdi,%rax 0x0000000000401129 <+3>: cmpw $0x1,0x2eff(%rip) # 0x404030 <g_344> 0x0000000000401131 <+11>: sbb %edi,%edi 0x0000000000401133 <+13>: and $0xf544,%di 0x0000000000401138 <+18>: add $0xab2,%di 0x000000000040113d <+23>: cmpw $0x1,0x2eeb(%rip) # 0x404030 <g_344> 0x0000000000401145 <+31>: sbb %esi,%esi 0x0000000000401147 <+33>: and $0x92da,%si 0x000000000040114c <+38>: add $0x6d27,%si 0x0000000000401151 <+43>: cmpw $0x1,0x2ed7(%rip) # 0x404030 <g_344> 0x0000000000401159 <+51>: sbb %ecx,%ecx 0x000000000040115b <+53>: and $0xfffffff9,%ecx 0x000000000040115e <+56>: sub $0x1,%ecx 0x0000000000401161 <+59>: cmpw $0x1,0x2ec7(%rip) # 0x404030 <g_344> 0x0000000000401169 <+67>: sbb %edx,%edx 0x000000000040116b <+69>: and $0xfffffff6,%edx 0x000000000040116e <+72>: sub $0x55,%edx 0x0000000000401171 <+75>: cmpw $0x0,0x2eb7(%rip) # 0x404030 <g_344> 0x0000000000401179 <+83>: movabs $0x2f513c84a35aae1b,%r9 0x0000000000401183 <+93>: mov $0x3,%r8d 0x0000000000401189 <+99>: cmovne %r8,%r9 0x000000000040118d <+103>: movabs $0x3e72f31ff82c1e35,%r10 0x0000000000401197 <+113>: mov $0xfffffffffffffffa,%r8 0x000000000040119e <+120>: cmovne %r10,%r8 0x00000000004011a2 <+124>: mov %di,(%rax) 0x00000000004011a5 <+127>: mov %si,0x2(%rax) 0x00000000004011a9 <+131>: mov %cx,0x4(%rax) 0x00000000004011ad <+135>: mov %dl,0x6(%rax) 0x00000000004011b0 <+138>: mov %r9,0x8(%rax) 0x00000000004011b4 <+142>: mov %r8,0x10(%rax) 0x00000000004011b8 <+146>: retq it seems the last 4 loads are unneed and can be optimized away, which bring vulnerabilities when facing concurrency and may decrease performance