[Bug rtl-optimization/49157] New: Unnecessary stack save/restore code generated for a leaf function (arm-elf-gcc)
bmei at broadcom dot com
gcc-bugzilla@gcc.gnu.org
Wed May 25 10:34:00 GMT 2011
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49157
Summary: Unnecessary stack save/restore code generated for a
leaf function (arm-elf-gcc)
Product: gcc
Version: 4.6.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: rtl-optimization
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: bmei@broadcom.com
For the following example:
struct Complex16{
short a;
short b;
};
short foo (struct Complex16 s)
{
return s.a + s.b;
}
Compile with:
arm-elf-gcc tst.c -O2 -S -mstructure-size-boundary=8
It produces:
foo:
@ args = 0, pretend = 0, frame = 4
@ frame_needed = 0, uses_anonymous_args = 0
@ link register save eliminated.
mov r3, r0, asl #16
mov r3, r3, lsr #16
add r0, r3, r0, lsr #16
mov r0, r0, asl #16
sub sp, sp, #4
mov r0, r0, asr #16
add sp, sp, #4
bx lr
The problem is with struct-size-boundary=8, the structure has BLKmode and
mapped to memory after RTL expand. However, memory accesses are optimized away
later. But GCC records a stack item anyway and generates stack frame
save/restore code for this leaf function.
If we compile without -mstructure-size-boundary=8 (default is 32), it generates
much better code.
foo:
@ args = 0, pretend = 0, frame = 0
@ frame_needed = 0, uses_anonymous_args = 0
@ link register save eliminated.
add r0, r0, r0, asr #16
mov r0, r0, asl #16
mov r0, r0, asr #16
bx lr
This is not limited to ARM gcc. Our target has the same issue because
STRUCTURE_SIZE_BOUNDARY = 8 to save data memory size.
Though I only tested gcc 4.6, I believe trunk gcc probably has the same
problem.
More information about the Gcc-bugs
mailing list