https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68369

            Bug ID: 68369
           Summary: Unnecessary copying esp to ebp with regparm={1,2,3} on
                    x86 at -Os
           Product: gcc
           Version: 5.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: technosaurus at yahoo dot com
  Target Milestone: ---

This occurs on all versions tested for this simple test case:

> int nop(int x){return x;}

with gcc 5.2+ @ -O1,-O2 and -O3 this correctly compiles to:

> nop(int):
>       rep ret


however with -Os, it sub-optimally compiles to:

> nop(int):
>       pushl   %ebp
>       movl    %esp, %ebp
>       popl    %ebp
>       ret

At -O0, ebp is actually used which may hint why -Os doesn't pick it up

> nop(int):
>       pushl   %ebp
>       movl    %esp, %ebp
>       subl    $4, %esp
>       movl    %eax, -4(%ebp)
>       movl    -4(%ebp), %eax
>       leave
>       ret

Backtracking other optimization levels, the same behavior was fixed for -O1,
-O2 and -O3 somewhere between gcc-4.5.3 and 4.6.4 but remains suboptimal for
-Os up to 5.2.0

Reply via email to