public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/109766] New: Passing doubles through the stack generates a stack adjustment pear each such argument at -Os/-Oz.
@ 2023-05-08 9:06 pskocik at gmail dot com
2023-05-08 13:51 ` [Bug middle-end/109766] Passing doubles through the stack generates a stack adjustment per " sjames at gcc dot gnu.org
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: pskocik at gmail dot com @ 2023-05-08 9:06 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109766
Bug ID: 109766
Summary: Passing doubles through the stack generates a stack
adjustment pear each such argument at -Os/-Oz.
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: middle-end
Assignee: unassigned at gcc dot gnu.org
Reporter: pskocik at gmail dot com
Target Milestone: ---
/*
Passing doubles through the stack generates a stack adjustment pear each such
argument at -Os/-Oz.
These stack adjustments are only coalesced at -O1/-O2/-O3, leaving -Os/-Oz
with larger code.
*/
#define $expr(...) (__extension__({__VA_ARGS__;}))
#define $regF0 $expr(register double x __asm("xmm0"); x)
#define $regF1 $expr(register double x __asm("xmm1"); x)
#define $regF2 $expr(register double x __asm("xmm2"); x)
#define $regF3 $expr(register double x __asm("xmm3"); x)
#define $regF4 $expr(register double x __asm("xmm4"); x)
#define $regF5 $expr(register double x __asm("xmm5"); x)
#define $regF6 $expr(register double x __asm("xmm6"); x)
#define $regF7 $expr(register double x __asm("xmm7"); x)
void func(char const*Fmt, ...);
void callfunc(char const*Fmt, double D0, double D1, double D2, double D3,
double D4, double D5, double D6, double D7){
func(Fmt,$regF0,$regF1,$regF2,$regF3,$regF4,$regF5,$regF6,$regF7,
D0,D1,D2,D3,D4,D5,D6,D7);
/*
//gcc @ -Os/-Oz
0000000000000000 <callfunc>:
0: 50 push %rax
1: b0 08 mov $0x8,%al
3: 48 8d 64 24 f8 lea -0x8(%rsp),%rsp
8: 66 0f d6 3c 24 movq %xmm7,(%rsp)
d: 48 8d 64 24 f8 lea -0x8(%rsp),%rsp
12: 66 0f d6 34 24 movq %xmm6,(%rsp)
17: 48 8d 64 24 f8 lea -0x8(%rsp),%rsp
1c: 66 0f d6 2c 24 movq %xmm5,(%rsp)
21: 48 8d 64 24 f8 lea -0x8(%rsp),%rsp
26: 66 0f d6 24 24 movq %xmm4,(%rsp)
2b: 48 8d 64 24 f8 lea -0x8(%rsp),%rsp
30: 66 0f d6 1c 24 movq %xmm3,(%rsp)
35: 48 8d 64 24 f8 lea -0x8(%rsp),%rsp
3a: 66 0f d6 14 24 movq %xmm2,(%rsp)
3f: 48 8d 64 24 f8 lea -0x8(%rsp),%rsp
44: 66 0f d6 0c 24 movq %xmm1,(%rsp)
49: 48 8d 64 24 f8 lea -0x8(%rsp),%rsp
4e: 66 0f d6 04 24 movq %xmm0,(%rsp)
53: e8 00 00 00 00 callq 58 <callfunc+0x58>
54: R_X86_64_PLT32 func-0x4
58: 48 83 c4 48 add $0x48,%rsp
5c: c3 retq
$sz(callfunc)=93
//clang @ -Os/-Oz
0000000000000000 <callfunc>:
0: 48 83 ec 48 sub $0x48,%rsp
4: f2 0f 11 7c 24 38 movsd %xmm7,0x38(%rsp)
a: f2 0f 11 74 24 30 movsd %xmm6,0x30(%rsp)
10: f2 0f 11 6c 24 28 movsd %xmm5,0x28(%rsp)
16: f2 0f 11 64 24 20 movsd %xmm4,0x20(%rsp)
1c: f2 0f 11 5c 24 18 movsd %xmm3,0x18(%rsp)
22: f2 0f 11 54 24 10 movsd %xmm2,0x10(%rsp)
28: f2 0f 11 4c 24 08 movsd %xmm1,0x8(%rsp)
2e: f2 0f 11 04 24 movsd %xmm0,(%rsp)
33: b0 08 mov $0x8,%al
35: e8 00 00 00 00 callq 3a <callfunc+0x3a>
36: R_X86_64_PLT32 func-0x4
3a: 48 83 c4 48 add $0x48,%rsp
3e: c3 retq
$sz(callfunc)=63
//gcc @ -O1
0000000000000000 <callfunc>:
0: 48 83 ec 48 sub $0x48,%rsp
4: f2 0f 11 7c 24 38 movsd %xmm7,0x38(%rsp)
a: f2 0f 11 74 24 30 movsd %xmm6,0x30(%rsp)
10: f2 0f 11 6c 24 28 movsd %xmm5,0x28(%rsp)
16: f2 0f 11 64 24 20 movsd %xmm4,0x20(%rsp)
1c: f2 0f 11 5c 24 18 movsd %xmm3,0x18(%rsp)
22: f2 0f 11 54 24 10 movsd %xmm2,0x10(%rsp)
28: f2 0f 11 4c 24 08 movsd %xmm1,0x8(%rsp)
2e: f2 0f 11 04 24 movsd %xmm0,(%rsp)
33: b8 08 00 00 00 mov $0x8,%eax
38: e8 00 00 00 00 callq 3d <callfunc+0x3d>
39: R_X86_64_PLT32 func-0x4
3d: 48 83 c4 48 add $0x48,%rsp
41: c3 retq
$sz(callfunc)=66
*/
}
https://godbolt.org/z/d8T3hxqWK
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug middle-end/109766] Passing doubles through the stack generates a stack adjustment per each such argument at -Os/-Oz.
2023-05-08 9:06 [Bug middle-end/109766] New: Passing doubles through the stack generates a stack adjustment pear each such argument at -Os/-Oz pskocik at gmail dot com
@ 2023-05-08 13:51 ` sjames at gcc dot gnu.org
2023-05-08 16:28 ` roger at nextmovesoftware dot com
2023-06-16 8:47 ` roger at nextmovesoftware dot com
2 siblings, 0 replies; 4+ messages in thread
From: sjames at gcc dot gnu.org @ 2023-05-08 13:51 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109766
Sam James <sjames at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |roger at nextmovesoftware dot com
--- Comment #1 from Sam James <sjames at gcc dot gnu.org> ---
I'll cc Roger on the off chance he's interested, given he added -Oz.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug middle-end/109766] Passing doubles through the stack generates a stack adjustment per each such argument at -Os/-Oz.
2023-05-08 9:06 [Bug middle-end/109766] New: Passing doubles through the stack generates a stack adjustment pear each such argument at -Os/-Oz pskocik at gmail dot com
2023-05-08 13:51 ` [Bug middle-end/109766] Passing doubles through the stack generates a stack adjustment per " sjames at gcc dot gnu.org
@ 2023-05-08 16:28 ` roger at nextmovesoftware dot com
2023-06-16 8:47 ` roger at nextmovesoftware dot com
2 siblings, 0 replies; 4+ messages in thread
From: roger at nextmovesoftware dot com @ 2023-05-08 16:28 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109766
Roger Sayle <roger at nextmovesoftware dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed| |2023-05-08
Ever confirmed|0 |1
Status|UNCONFIRMED |NEW
--- Comment #2 from Roger Sayle <roger at nextmovesoftware dot com> ---
I believe the problem is in the cprop_hardreg pass, which undoes reload's
register assignments (to use DImode GPR registers with -Os), by propagating DF
mode values into *pushdi2_rex64, which then get split during the split3 pass
into lea/movq pairs, that are each larger than a DImode push. The work around,
for this test case, is to use -Os -fno-cprop-registers which produces code
that's shorter than -O2.
0000000000000000 <callfunc>:
0: 66 48 0f 7e ca movq %xmm1,%rdx
5: 66 48 0f 7e d1 movq %xmm2,%rcx
a: 66 48 0f 7e de movq %xmm3,%rsi
f: 50 push %rax
10: 66 49 0f 7e e0 movq %xmm4,%r8
15: 66 48 0f 7e c0 movq %xmm0,%rax
1a: 66 49 0f 7e e9 movq %xmm5,%r9
1f: 66 49 0f 7e f2 movq %xmm6,%r10
24: 66 49 0f 7e fb movq %xmm7,%r11
29: 41 53 push %r11
2b: 41 52 push %r10
2d: 41 51 push %r9
2f: 41 50 push %r8
31: 56 push %rsi
32: 51 push %rcx
33: 52 push %rdx
34: 50 push %rax
35: b0 08 mov $0x8,%al
37: e8 00 00 00 00 callq 3c <callfunc+0x3c>
3c: 48 83 c4 48 add $0x48,%rsp
40: c3 retq
Now to figure out if there's a way, using target rtx_costs or pushdi2_rex64's
constraints/predicates, to prevent hardreg cprop performing this substitution.
Plan B might be to investigate reload's choice of DFmode SSE vs DImode GPR, but
this is within one or two bytes of optimal (for four arguments I believe GCC
would produce shorter code than clang).
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug middle-end/109766] Passing doubles through the stack generates a stack adjustment per each such argument at -Os/-Oz.
2023-05-08 9:06 [Bug middle-end/109766] New: Passing doubles through the stack generates a stack adjustment pear each such argument at -Os/-Oz pskocik at gmail dot com
2023-05-08 13:51 ` [Bug middle-end/109766] Passing doubles through the stack generates a stack adjustment per " sjames at gcc dot gnu.org
2023-05-08 16:28 ` roger at nextmovesoftware dot com
@ 2023-06-16 8:47 ` roger at nextmovesoftware dot com
2 siblings, 0 replies; 4+ messages in thread
From: roger at nextmovesoftware dot com @ 2023-06-16 8:47 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109766
--- Comment #3 from Roger Sayle <roger at nextmovesoftware dot com> ---
For the record a solution was proposed at
https://gcc.gnu.org/pipermail/gcc-patches/2023-May/618197.html
but this approach failed review at
https://gcc.gnu.org/pipermail/gcc-patches/2023-May/618278.html
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-06-16 8:47 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-08 9:06 [Bug middle-end/109766] New: Passing doubles through the stack generates a stack adjustment pear each such argument at -Os/-Oz pskocik at gmail dot com
2023-05-08 13:51 ` [Bug middle-end/109766] Passing doubles through the stack generates a stack adjustment per " sjames at gcc dot gnu.org
2023-05-08 16:28 ` roger at nextmovesoftware dot com
2023-06-16 8:47 ` 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).