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