This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug rtl-optimization/49157] New: Unnecessary stack save/restore code generated for a leaf function (arm-elf-gcc)


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]