[Bug target/43988] New: unnecessary memory store

carrot at google dot com gcc-bugzilla@gcc.gnu.org
Wed May 5 01:47:00 GMT 2010


Compile following code with options -march=armv7-a -mthumb -Os,

extern void foo(int*);

void bar3(int v)
{
  foo(&v);
}

GCC generates:

bar3:
        push    {r0, r1, r2, lr}
        add     r3, sp, #8
        str     r0, [r3, #-4]!
        mov     r0, r3
        bl      foo
        pop     {r1, r2, r3, pc}

After the first push instruction, register r0 is already stored at memory [sp],
but later instructions store r0 to memory [sp+4] again and use it as the
address for variable v. The better result is:

bar3:
        push    {r0, r1, r2, lr}
        mov     r0, sp
        bl      foo
        pop     {r1, r2, r3, pc}


-- 
           Summary: unnecessary memory store
           Product: gcc
           Version: 4.6.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=43988



More information about the Gcc-bugs mailing list