public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/100377] New: needless stack adjustment when passing struct in register
@ 2021-05-01 19:20 luc.vanoostenryck at gmail dot com
2021-05-01 20:59 ` [Bug rtl-optimization/100377] " pinskia at gcc dot gnu.org
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: luc.vanoostenryck at gmail dot com @ 2021-05-01 19:20 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100377
Bug ID: 100377
Summary: needless stack adjustment when passing struct in
register
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: rtl-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: luc.vanoostenryck at gmail dot com
Target Milestone: ---
Created attachment 50726
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=50726&action=edit
testcases
When compiling with optimization for example -O2), the following code:
struct sb {
signed char a;
char b;
short y[3];
};
struct ub {
unsigned char a;
char b;
short y[3];
};
int fsb(struct sb s) { return s.a; }
int fub(struct ub s) { return s.a; }
produces the following assembly code on arm64:
fsb:
sub sp, sp, #16
sxtb w0, w0
add sp, sp, 16
ret
fub:
sub sp, sp, #16
and w0, w0, 255
add sp, sp, 16
ret
the following on mips64:
fsb:
daddiu $sp,$sp,-16
dsll $2,$4,56
dsra $2,$2,56
j $31
daddiu $sp,$sp,16
fub:
daddiu $sp,$sp,-16
andi $2,$4,0xff
j $31
daddiu $sp,$sp,16
the following on riscv64:
fsb:
addi sp,sp,-16
slli a0,a0,24
srai a0,a0,24
addi sp,sp,16
jr ra
fub:
addi sp,sp,-16
andi a0,a0,0xff
addi sp,sp,16
jr ra
OTOH, things seems OK on ppc64:
fsb:
extsb 3,3
blr
fub:
rlwinm 3,3,0,0xff
blr
and x86_64:
fsb:
movsx eax, dil
ret
fub:
movzx eax, dil
ret
Similar problems happen on 32-bit platforms too.
For example on arm32, the following code:
struct ub32 {
unsigned char a;
char b;
short y[1];
};
int fub32(struct ub32 s) { return s.a; }
produces:
fub32:
sub sp, sp, #8
uxtb r0, r0
add sp, sp, #8
bx lr
All these seem to happen on all versions.
See https://gcc.godbolt.org/z/x9zc1EnYn
Note: similar PRs exist but reported for x86_64 only
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug rtl-optimization/100377] needless stack adjustment when passing struct in register
2021-05-01 19:20 [Bug rtl-optimization/100377] New: needless stack adjustment when passing struct in register luc.vanoostenryck at gmail dot com
@ 2021-05-01 20:59 ` pinskia at gcc dot gnu.org
2021-05-01 21:00 ` pinskia at gcc dot gnu.org
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-05-01 20:59 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100377
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Depends on| |94173, 90216
Severity|normal |enhancement
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Luc Van Oostenryck from comment #0)
>
> Note: similar PRs exist but reported for x86_64 only
Not true. PR 94173, PR 90216.
I thought there was one which I filed which is much older than those but I
can't find it.
Referenced Bugs:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90216
[Bug 90216] Stack Pointer decrementing even when not loading extra data to
stack.
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94173
[Bug 94173] [RISCV] Superfluous stackpointer manipulation
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug rtl-optimization/100377] needless stack adjustment when passing struct in register
2021-05-01 19:20 [Bug rtl-optimization/100377] New: needless stack adjustment when passing struct in register luc.vanoostenryck at gmail dot com
2021-05-01 20:59 ` [Bug rtl-optimization/100377] " pinskia at gcc dot gnu.org
@ 2021-05-01 21:00 ` pinskia at gcc dot gnu.org
2021-05-02 14:05 ` luc.vanoostenryck at gmail dot com
2021-05-03 8:02 ` rguenth at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-05-01 21:00 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100377
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
OTOH, things seems OK on ppc64:
and x86_64:
Because both of those have redzones in their stack ABI.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug rtl-optimization/100377] needless stack adjustment when passing struct in register
2021-05-01 19:20 [Bug rtl-optimization/100377] New: needless stack adjustment when passing struct in register luc.vanoostenryck at gmail dot com
2021-05-01 20:59 ` [Bug rtl-optimization/100377] " pinskia at gcc dot gnu.org
2021-05-01 21:00 ` pinskia at gcc dot gnu.org
@ 2021-05-02 14:05 ` luc.vanoostenryck at gmail dot com
2021-05-03 8:02 ` rguenth at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: luc.vanoostenryck at gmail dot com @ 2021-05-02 14:05 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100377
--- Comment #3 from Luc Van Oostenryck <luc.vanoostenryck at gmail dot com> ---
> I thought there was one which I filed which is much older than those but I
> can't find it.
Probably also related to PR36409 and PR49157
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug rtl-optimization/100377] needless stack adjustment when passing struct in register
2021-05-01 19:20 [Bug rtl-optimization/100377] New: needless stack adjustment when passing struct in register luc.vanoostenryck at gmail dot com
` (2 preceding siblings ...)
2021-05-02 14:05 ` luc.vanoostenryck at gmail dot com
@ 2021-05-03 8:02 ` rguenth at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-05-03 8:02 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100377
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |missed-optimization
--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
I think there are indeed plenty of dups.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-05-03 8:02 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-01 19:20 [Bug rtl-optimization/100377] New: needless stack adjustment when passing struct in register luc.vanoostenryck at gmail dot com
2021-05-01 20:59 ` [Bug rtl-optimization/100377] " pinskia at gcc dot gnu.org
2021-05-01 21:00 ` pinskia at gcc dot gnu.org
2021-05-02 14:05 ` luc.vanoostenryck at gmail dot com
2021-05-03 8:02 ` rguenth at gcc dot gnu.org
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).