<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - Missed optimization: stack frame pushing/popping is not optimized away for trivial functions"
   href="https://llvm.org/bugs/show_bug.cgi?id=26160">26160</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Missed optimization: stack frame pushing/popping is not optimized away for trivial functions
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>3.6
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>Macintosh
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>MacOS X
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>-New Bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>mjbshaw@hotmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>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.</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>