<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 --- - [X86] Consider not restoring the stack between calls"
   href="https://llvm.org/bugs/show_bug.cgi?id=27165">27165</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[X86] Consider not restoring the stack between calls
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

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

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>Backend: X86
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>hans@chromium.org
          </td>
        </tr>

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

        <tr>
          <th>Blocks</th>
          <td>26299
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Consider:

  void f(int);
  void g() {
    f(1);
    f(2);
  }

Compiled with -target i686-pc-win32 -Os, Clang generates:

00000000 <_g>:
   0:   6a 01                   push   $0x1
   2:   e8 00 00 00 00          call   7 <_g+0x7>
   7:   83 c4 04                add    $0x4,%esp
   a:   6a 02                   push   $0x2
   c:   e8 00 00 00 00          call   11 <_g+0x11>
  11:   83 c4 04                add    $0x4,%esp
  14:   c3                      ret


Since there is no need to align the stack, we could consider not restoring the
stack pointer between the two calls:

MSVC with /Ox:

  00000000: 6A 01              push        1
  00000002: E8 00 00 00 00     call        _f
  00000007: 6A 02              push        2
  00000009: E8 00 00 00 00     call        _f
  0000000E: 83 C4 08           add         esp,8
  00000011: C3                 ret
                 

This saves code size at the expense of stack size.

If we used pops to restore the stack here (see PR26333) that might be cheaper
than a consolidated "addl $8, %esp" though.</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>