From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 32C453857C50; Wed, 24 Mar 2021 12:57:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 32C453857C50 From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/65847] SSE2 code for adding two structs is much worse at -O3 than at -O2 Date: Wed, 24 Mar 2021 12:57:37 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Version: 6.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: rguenth at gcc dot gnu.org X-Bugzilla-Status: NEW 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: Message-ID: In-Reply-To: References: 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: Wed, 24 Mar 2021 12:57:38 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D65847 --- Comment #3 from Richard Biener --- Similarly struct X { int a; int b; int c; int d; }; struct X foo (struct X x, struct X y) { struct X res; res.a =3D x.a + y.a; res.b =3D x.b + y.b; res.c =3D x.c + y.c; res.d =3D x.d + y.d; return res; } is vectorized as foo: .LFB0: .cfi_startproc movq %rdi, -40(%rsp) movq %rsi, -32(%rsp) movdqa -40(%rsp), %xmm0 movq %rdx, -24(%rsp) movq %rcx, -16(%rsp) paddd -24(%rsp), %xmm0 movaps %xmm0, -40(%rsp) movq -40(%rsp), %rax movq -32(%rsp), %rdx ret which is bad because the on-stack construction of %xmm0 causes a STLF fail. Unvectorized code isn't necessarily worse, but the vectorized sequence can be improved=20 foo: .LFB0: .cfi_startproc movq %rdi, %rax movq %rdi, %r10 movq %rdx, %rdi movq %rsi, %r9 sarq $32, %r10 sarq $32, %rdi addl %edx, %eax movq %rcx, %r8 addl %r10d, %edi sarq $32, %r9 movl %eax, %eax leal (%rsi,%rcx), %edx movl %edi, %edi sarq $32, %r8 salq $32, %rdi orq %rdi, %rax leal (%r9,%r8), %edi salq $32, %rdi orq %rdi, %rdx ret in this case the spill is caused by LRA not knowing how to re-load the TImode reg build by pieces by the RTL expansion code.=