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
* [Bug rtl-optimization/115351] [14/15 regression] pointless movs when passing by value on x86-64
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 ` rguenth at gcc dot gnu.org
2024-06-05 7:21 ` liuhongt at gcc dot gnu.org
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-06-05 7:10 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115351
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target| |x86_64-*-*
Summary|[14 regression] pointless |[14/15 regression]
|movs when passing by value |pointless movs when passing
|on x86-64 |by value on x86-64
Target Milestone|--- |14.2
Ever confirmed|0 |1
Status|UNCONFIRMED |NEW
Last reconfirmed| |2024-06-05
Component|c++ |rtl-optimization
Keywords| |missed-optimization,
| |needs-bisection
--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Confirmed. The IL we expand from is the same.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug rtl-optimization/115351] [14/15 regression] pointless movs when passing by value on x86-64
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
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: liuhongt at gcc dot gnu.org @ 2024-06-05 7:21 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115351
Hongtao Liu <liuhongt at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |liuhongt at gcc dot gnu.org
--- Comment #2 from Hongtao Liu <liuhongt at gcc dot gnu.org> ---
There're
(insn 5 4 6 2 (set (reg:TI 110)
(ior:TI (and:TI (reg:TI 110)
(const_wide_int 0xffffffffffffffff0000000000000000))
(zero_extend:TI (subreg:DI (reg:DF 111) 0))))
"/app/example.cpp":8:1 136 {*insvti_lowpart_1}
(nil))
(insn 6 5 7 2 (set (reg:TI 110)
(ior:TI (and:TI (reg:TI 110)
(const_wide_int 0x0ffffffffffffffff))
(ashift:TI (zero_extend:TI (subreg:DI (reg:DF 112) 0))
(const_int 64 [0x40])))) "/app/example.cpp":8:1 133
{*insvti_highpart_1}
(nil))
(insn 7 6 8 2 (set (reg/v:TI 109 [ z ])
in GCC14's rtl dump, guess related to r14-589-g1e3054d27c83ee?
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug target/115351] [14/15 regression] pointless movs when passing by value on x86-64
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 ` 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
4 siblings, 0 replies; 6+ messages in thread
From: roger at nextmovesoftware dot com @ 2024-06-05 23:33 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115351
Roger Sayle <roger at nextmovesoftware dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Assignee|unassigned at gcc dot gnu.org |roger at nextmovesoftware dot com
--- Comment #3 from Roger Sayle <roger at nextmovesoftware dot com> ---
I have a fix (to ix86_rtx_costs) that I'm bootstrapping and regression testing.
By making concatditi3 slightly cheaper than *insvti_highpart (COSTS_N_INSN(2)
vs. COSTS_N_INSNS(2)+1), fwprop is able to do the right.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug target/115351] [14/15 regression] pointless movs when passing by value on x86-64
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
` (2 preceding siblings ...)
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
4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-06-07 13:04 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115351
--- Comment #4 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Roger Sayle <sayle@gcc.gnu.org>:
https://gcc.gnu.org/g:fb3e4c549d16d5050e10114439ad77149f33c597
commit r15-1101-gfb3e4c549d16d5050e10114439ad77149f33c597
Author: Roger Sayle <roger@nextmovesoftware.com>
Date: Fri Jun 7 14:03:20 2024 +0100
i386: PR target/115351: RTX costs for *concatditi3 and *insvti_highpart.
This patch addresses PR target/115351, which is a code quality regression
on x86 when passing floating point complex numbers. The ABI considers
these arguments to have TImode, requiring interunit moves to place the
FP values (which are actually passed in SSE registers) into the upper
and lower parts of a TImode pseudo, and then similar moves back again
before they can be used.
The cause of the regression is that changes in how TImode initialization
is represented in RTL now prevents the RTL optimizers from eliminating
these redundant moves. The specific cause is that the *concatditi3
pattern, (zext(hi)<<64)|zext(lo), has an inappropriately high (default)
rtx_cost, preventing fwprop1 from propagating it. This pattern just
sets the hipart and lopart of a double-word register, typically two
instructions (less if reload can allocate things appropriately) but
the current ix86_rtx_costs actually returns INSN_COSTS(13), i.e. 52.
propagating insn 5 into insn 6, replacing:
(set (reg:TI 110)
(ior:TI (and:TI (reg:TI 110)
(const_wide_int 0x0ffffffffffffffff))
(ashift:TI (zero_extend:TI (subreg:DI (reg:DF 112 [ zD.2796+8 ])
0))
(const_int 64 [0x40]))))
successfully matched this instruction to *concatditi3_3:
(set (reg:TI 110)
(ior:TI (ashift:TI (zero_extend:TI (subreg:DI (reg:DF 112 [ zD.2796+8
]) 0))
(const_int 64 [0x40]))
(zero_extend:TI (subreg:DI (reg:DF 111 [ zD.2796 ]) 0))))
change not profitable (cost 50 -> cost 52)
This issue is resolved by having ix86_rtx_costs return more reasonable
values for these (place-holder) patterns.
2024-06-07 Roger Sayle <roger@nextmovesoftware.com>
gcc/ChangeLog
PR target/115351
* config/i386/i386.cc (ix86_rtx_costs): Provide estimates for
the *concatditi3 and *insvti_highpart patterns, about two insns.
gcc/testsuite/ChangeLog
PR target/115351
* g++.target/i386/pr115351.C: New test case.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug target/115351] [14 regression] pointless movs when passing by value on x86-64
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
` (3 preceding siblings ...)
2024-06-07 13:04 ` cvs-commit at gcc dot gnu.org
@ 2024-06-08 14:51 ` roger at nextmovesoftware dot com
4 siblings, 0 replies; 6+ messages in thread
From: roger at nextmovesoftware dot com @ 2024-06-08 14:51 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115351
Roger Sayle <roger at nextmovesoftware dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Assignee|roger at nextmovesoftware dot com |unassigned at gcc dot gnu.org
Summary|[14/15 regression] |[14 regression] pointless
|pointless movs when passing |movs when passing by value
|by value on x86-64 |on x86-64
Known to work| |15.0
--- Comment #5 from Roger Sayle <roger at nextmovesoftware dot com> ---
This has been fixed on mainline (for GCC 15).
^ 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).