Compile the attached code with options -march=armv7-a -mthumb -Os -fpic, gcc
generates:

foo3:
        push    {r4, r5, r6, r7, lr}
        sub     sp, sp, #12      // A
        ldr     r3, .L4
        add     r7, sp, #0       // B
        sub     sp, sp, #48      // C
        mov     r0, sp
         ...

Instruction A is used to allocate space for spilled variables. Instruction B
setups a frame pointer. Instruction C allocate space for local variables.
Instruction A and C can be merged into one, so ABC can be rewritten as:

        sub     sp, sp, 60
        add     r7, sp, r8

Instruction C is emitted at the expand phase. But instructions AB is emitted
from function arm_expand_prologue in pro_and_epilogue pass. So one possible
solution is stop emitting code to allocate space for local variables. Instead
record the local variables' space size and allocate the space with spill space
together in pro_and_epilogue pass.


-- 
           Summary: The stack pointer is adjusted twice
           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=43513

Reply via email to