public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/115351] New: [14 regression] pointless movs when passing by value on x86-64
@ 2024-06-05  3:14 michael.kenzel at gmail dot com
  2024-06-05  7:10 ` [Bug rtl-optimization/115351] [14/15 " rguenth at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: michael.kenzel at gmail dot com @ 2024-06-05  3:14 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115351

            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 specific
to this target), gcc 14 emits (fails to optimize away?) a number of redundant
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

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-06-08 14:51 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-05  3:14 [Bug c++/115351] New: [14 regression] pointless movs when passing by value on x86-64 michael.kenzel at gmail dot com
2024-06-05  7:10 ` [Bug rtl-optimization/115351] [14/15 " rguenth at gcc dot gnu.org
2024-06-05  7:21 ` liuhongt at gcc dot gnu.org
2024-06-05 23:33 ` [Bug target/115351] " roger at nextmovesoftware dot com
2024-06-07 13:04 ` cvs-commit at gcc dot gnu.org
2024-06-08 14:51 ` [Bug target/115351] [14 " roger at nextmovesoftware dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).