http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46932

           Summary: Inefficient code sequence to access local variable
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: car...@google.com


Compile the following code with options -march=armv7-a -mthumb -O2

extern void foo(char*);
void t01(char t)
{
  char c = t;
  foo(&c);
}

gcc4.6 generates:

t01:
    push    {lr}
    sub    sp, sp, #12
    add    r3, sp, #8       // A
    strb    r0, [r3, #-1]!   // B
    mov    r0, r3           // C
    bl    foo
    add    sp, sp, #12
    pop    {pc}

Code sequence ABC can be replaced by

        strb    r0, [sp, #7]
        add     r0, sp, #7      

Which may be faster. If we allocate the variable c at the boundary of a word(4
bytes aligned), the code sequence would be:

        strb    r0, [sp, #4]
        add     r0, sp, #4

which is shorter in code size because "add     r0, sp, #4" can be encode into
16 bits.

When compiled to ARM instructions and/or -Os, it has the same problem.

Reply via email to