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: [email protected]
          Reporter: [email protected]
                CC: [email protected]
    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.
_______________________________________________
llvm-bugs mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to