From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 5050D3959C85; Tue, 10 May 2022 11:34:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5050D3959C85 From: "absoler at smail dot nju.edu.cn" To: gcc-bugs@gcc.gnu.org Subject: [Bug rtl-optimization/105546] New: load introduction when copying a struct Date: Tue, 10 May 2022 11:34:49 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: rtl-optimization X-Bugzilla-Version: 11.3.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: absoler at smail dot nju.edu.cn X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 10 May 2022 11:34:49 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D105546 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=3D52948&action=3Dedit 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 =3D 0xC307L; struct S0 func_1(void) {=20 struct S0 l_346 =3D {65526UL,1UL,-8L,0xA1L,0x2F513C84A35AAE1BLL,-6L}; if (g_344) {=20 struct S0 l_345 =3D {0x0AB2L,0x6D27L,-1L,0xABL,3L,0x3E72F31FF82C1E3= 5LL}; return l_345; } else {=20 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 0x0000000000401131 <+11>: sbb %edi,%edi 0x0000000000401133 <+13>: and $0xf544,%di 0x0000000000401138 <+18>: add $0xab2,%di 0x000000000040113d <+23>: cmpw $0x1,0x2eeb(%rip) # 0x404030 0x0000000000401145 <+31>: sbb %esi,%esi 0x0000000000401147 <+33>: and $0x92da,%si 0x000000000040114c <+38>: add $0x6d27,%si 0x0000000000401151 <+43>: cmpw $0x1,0x2ed7(%rip) # 0x404030 0x0000000000401159 <+51>: sbb %ecx,%ecx 0x000000000040115b <+53>: and $0xfffffff9,%ecx 0x000000000040115e <+56>: sub $0x1,%ecx 0x0000000000401161 <+59>: cmpw $0x1,0x2ec7(%rip) # 0x404030 0x0000000000401169 <+67>: sbb %edx,%edx 0x000000000040116b <+69>: and $0xfffffff6,%edx 0x000000000040116e <+72>: sub $0x55,%edx 0x0000000000401171 <+75>: cmpw $0x0,0x2eb7(%rip) # 0x404030 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=