public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/54585] New: stack space allocated but never used when calling functions that return structs in registers
@ 2012-09-14 21:11 chip at pobox dot com
2013-09-05 20:06 ` [Bug rtl-optimization/54585] " chip at pobox dot com
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: chip at pobox dot com @ 2012-09-14 21:11 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54585
Bug #: 54585
Summary: stack space allocated but never used when calling
functions that return structs in registers
Classification: Unclassified
Product: gcc
Version: 4.7.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: rtl-optimization
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: chip@pobox.com
Now that bug #44194 is fixed, and a returned structure used as a parameter is
no longer stored unnecessarily, a new bug is visible: a stack frame is being
allocated that is entirely unused. On x86_64 target with the fix for 44194
backported to the 4.7 branch, this code:
#include <stdint.h>
struct blargh { uint32_t a, b, c; } foo();
void bar(uint32_t a, uint32_t b, uint32_t c);
void func() {
struct blargh s = foo();
bar(s.a, s.b, s.c);
}
no longer uses any stack memory at all, but still the function call reserves 24
bytes with "subq $24,%rsp" and promptly returns it with "addq $24,%rsp". The
generated code looks like this:
func:
.cfi_startproc
xorl %eax, %eax
subq $24, %rsp
.cfi_def_cfa_offset 32
call foo
movq %rax, %rsi
movl %eax, %edi
addq $24, %rsp
.cfi_def_cfa_offset 8
shrq $32, %rsi
jmp bar
.cfi_endproc
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug rtl-optimization/54585] stack space allocated but never used when calling functions that return structs in registers
2012-09-14 21:11 [Bug rtl-optimization/54585] New: stack space allocated but never used when calling functions that return structs in registers chip at pobox dot com
@ 2013-09-05 20:06 ` chip at pobox dot com
2013-09-05 21:05 ` ebotcazou at gcc dot gnu.org
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: chip at pobox dot com @ 2013-09-05 20:06 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54585
--- Comment #1 from Chip Salzenberg <chip at pobox dot com> ---
I'd like to suggest this ticket be at least CONFIRMED what with the code
samples in the ticket.
What will it take to fix this?
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug rtl-optimization/54585] stack space allocated but never used when calling functions that return structs in registers
2012-09-14 21:11 [Bug rtl-optimization/54585] New: stack space allocated but never used when calling functions that return structs in registers chip at pobox dot com
2013-09-05 20:06 ` [Bug rtl-optimization/54585] " chip at pobox dot com
@ 2013-09-05 21:05 ` ebotcazou at gcc dot gnu.org
2013-09-23 20:05 ` chip at pobox dot com
2021-12-18 23:59 ` [Bug middle-end/54585] " pinskia at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: ebotcazou at gcc dot gnu.org @ 2013-09-05 21:05 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54585
Eric Botcazou <ebotcazou at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Last reconfirmed| |2013-09-05
CC| |ebotcazou at gcc dot gnu.org
Ever confirmed|0 |1
--- Comment #2 from Eric Botcazou <ebotcazou at gcc dot gnu.org> ---
It's quite hard because the frame is laid out way before all the memory
accesses to the stack slots are optimized away. My personal take is that it's
not worth the hassle, but I'm ready to be proved wrong.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug rtl-optimization/54585] stack space allocated but never used when calling functions that return structs in registers
2012-09-14 21:11 [Bug rtl-optimization/54585] New: stack space allocated but never used when calling functions that return structs in registers chip at pobox dot com
2013-09-05 20:06 ` [Bug rtl-optimization/54585] " chip at pobox dot com
2013-09-05 21:05 ` ebotcazou at gcc dot gnu.org
@ 2013-09-23 20:05 ` chip at pobox dot com
2021-12-18 23:59 ` [Bug middle-end/54585] " pinskia at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: chip at pobox dot com @ 2013-09-23 20:05 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54585
--- Comment #3 from Chip Salzenberg <chip at pobox dot com> ---
It's worth it for cache reasons I believe. The data cache works better you
don't spread out the stack data unnecessarily. More concretely, if the stack
frame can entirely disappear then you also reduce the instruction count.
That's fewer instructions to dispatch and less icache pressure.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug middle-end/54585] stack space allocated but never used when calling functions that return structs in registers
2012-09-14 21:11 [Bug rtl-optimization/54585] New: stack space allocated but never used when calling functions that return structs in registers chip at pobox dot com
` (2 preceding siblings ...)
2013-09-23 20:05 ` chip at pobox dot com
@ 2021-12-18 23:59 ` pinskia at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-18 23:59 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54585
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Component|rtl-optimization |middle-end
Severity|normal |enhancement
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-12-18 23:59 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-09-14 21:11 [Bug rtl-optimization/54585] New: stack space allocated but never used when calling functions that return structs in registers chip at pobox dot com
2013-09-05 20:06 ` [Bug rtl-optimization/54585] " chip at pobox dot com
2013-09-05 21:05 ` ebotcazou at gcc dot gnu.org
2013-09-23 20:05 ` chip at pobox dot com
2021-12-18 23:59 ` [Bug middle-end/54585] " pinskia 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).