From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 7A5FD390DEC4; Wed, 5 Jun 2024 03:14:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7A5FD390DEC4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1717557295; bh=zcu9hwUxocK+WTno8JqjdcCX57F1mKZlHj8t76SOc6I=; h=From:To:Subject:Date:From; b=KQ5JzNH85SBGeS+QrH4d68w1UB7dz7h7bEccpApY7CwqIUdWxEUyESMnqxnkD7aKM TRgvPnLw1glOD/19OGX1A+E5W8UqXVJI3aPdSPdGJyg04PIPw+Q7ehVKrwX2u5z1ll PLHwi3FZKpzP1xk3yf68S/U5vG3ZuVnsE6qoL1JA= From: "michael.kenzel at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/115351] New: [14 regression] pointless movs when passing by value on x86-64 Date: Wed, 05 Jun 2024 03:14:54 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 14.1.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: michael.kenzel at gmail dot com 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 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D115351 Bug ID: 115351 Summary: [14 regression] pointless movs when passing by value on x86-64 Product: gcc Version: 14.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: michael.kenzel at gmail dot com Target Milestone: --- When passing structs of certain shape by value on x86-64 (seems to be speci= fic to this target), gcc 14 emits (fails to optimize away?) a number of redunda= nt moves: struct complex { double real; double imag; }; complex blub(complex z) { return { z.real * z.real - z.imag * z.imag, 2 * z.real * z.imag }; } on gcc 13 with -O3 results in blub(complex): movapd xmm3, xmm1 movapd xmm2, xmm0 mulsd xmm3, xmm1 addsd xmm2, xmm2 mulsd xmm0, xmm0 mulsd xmm1, xmm2 subsd xmm0, xmm3 ret gcc 14 and later with -O3 emit blub(complex): movq rax, xmm1 movq rdx, xmm0 xchg rdx, rax movq xmm2, rax movq xmm1, rdx movapd xmm0, xmm2 movapd xmm3, xmm1 mulsd xmm3, xmm1 mulsd xmm0, xmm2 addsd xmm2, xmm2 mulsd xmm1, xmm2 subsd xmm0, xmm3 ret godbolt: https://godbolt.org/z/hzEfs3ob4=