Compile following code with options -Os -mthumb -march=armv5te extern void bar(int*); int foo() { int x; bar(&x); return x; }
Gcc generates: push {lr} sub sp, sp, #12 add r0, sp, #4 bl bar ldr r0, [sp, #4] add sp, sp, #12 @ sp needed for prologue pop {pc} A better code sequence could be: push {r1-r3,lr} add r0, sp, #4 bl bar ldr r0, [sp, #4] @ sp needed for prologue pop {r1-r3, pc} The local variable allocation and deallocation can be merged into the push/pop instruction, so we can avoid the extra sub/add instructions and reduce two instructions. -- Summary: allocate local variables with fewer instructions Product: gcc Version: 4.5.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: carrot at google dot com GCC build triplet: i686-linux GCC host triplet: i686-linux GCC target triplet: arm-eabi http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40657