[llvm-bugs] [Bug 26160] New: Missed optimization: stack frame pushing/popping is not optimized away for trivial functions

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Jan 15 08:18:43 PST 2016


https://llvm.org/bugs/show_bug.cgi?id=26160

            Bug ID: 26160
           Summary: Missed optimization: stack frame pushing/popping is
                    not optimized away for trivial functions
           Product: clang
           Version: 3.6
          Hardware: Macintosh
                OS: MacOS X
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: mjbshaw at hotmail.com
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

clang unnecessarily pushes and pops the stack frame for trivial functions at
all -O levels:

$ cat t.c
void foo(void) {}
$ clang -O2 -c t.c
$ otool -tV t.o
t.o:
(__TEXT,__text) section
_foo:
0000000000000000    pushq    %rbp
0000000000000001    movq    %rsp, %rbp
0000000000000004    popq    %rbp
0000000000000005    retq


gcc is able to optimize this function to a single retq instruction at
optimization levels of -O1 and above.

----

This is not just seen with empty functions. Other simple functions that have no
need for a full stack frame end up pushing and popping it anyway:

$ cat t.c
int bar(int x) { return x; }
$ clang -O2 -c t.c
$ otool -tV t.o
t.o:
(__TEXT,__text) section
_bar:
0000000000000000    pushq    %rbp
0000000000000001    movq    %rsp, %rbp
0000000000000004    movl    %edi, %eax
0000000000000006    popq    %rbp
0000000000000007    retq


gcc is able to optimize this function to just movl %edi, %eax and retq.


It would be ideal if clang could optimize away unnecessary fiddling with %rbp
and $rsp.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20160115/3be89b9b/attachment.html>


More information about the llvm-bugs mailing list