<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 --- - inefficient codegen for inalloca calls"
   href="https://llvm.org/bugs/show_bug.cgi?id=27076">27076</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>inefficient codegen for inalloca 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, rnk@google.com
          </td>
        </tr>

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

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

  struct S {
    ~S();
    int x;
  };

  void f(S);

  void g(S* s) {
    f(*s);
    f(*s);
  }

MSVC /Ox:

?g@@YAXPAUS@@@Z (void __cdecl g(struct S *)):
  00000000: 56                 push        esi
  00000001: 8B 74 24 08        mov         esi,dword ptr [esp+8]
  00000005: FF 36              push        dword ptr [esi]
  00000007: E8 00 00 00 00     call        ?f@@YAXUS@@@Z
  0000000C: FF 36              push        dword ptr [esi]
  0000000E: E8 00 00 00 00     call        ?f@@YAXUS@@@Z
  00000013: 83 C4 08           add         esp,8
  00000016: 5E                 pop         esi
  00000017: C3                 ret
                               

Clang -O3:

00000000 <?g@@YAXPAUS@@@Z>:
   0:   55                      push   %ebp
   1:   89 e5                   mov    %esp,%ebp
   3:   57                      push   %edi
   4:   56                      push   %esi
   5:   89 e6                   mov    %esp,%esi
   7:   8b 7d 08                mov    0x8(%ebp),%edi
   a:   b8 04 00 00 00          mov    $0x4,%eax
   f:   e8 00 00 00 00          call   14 <?g@@YAXPAUS@@@Z+0x14> (chkstk)
  14:   89 e0                   mov    %esp,%eax
  16:   8b 0f                   mov    (%edi),%ecx
  18:   89 08                   mov    %ecx,(%eax)
  1a:   e8 00 00 00 00          call   1f <?g@@YAXPAUS@@@Z+0x1f>
  1f:   83 c4 04                add    $0x4,%esp  <-- This is just redundant??
  22:   89 f4                   mov    %esi,%esp
  24:   b8 04 00 00 00          mov    $0x4,%eax
  29:   e8 00 00 00 00          call   2e <?g@@YAXPAUS@@@Z+0x2e> (chkstk)
  2e:   89 e0                   mov    %esp,%eax
  30:   8b 0f                   mov    (%edi),%ecx
  32:   89 08                   mov    %ecx,(%eax)
  34:   e8 00 00 00 00          call   39 <?g@@YAXPAUS@@@Z+0x39>
  39:   8d 65 f8                lea    -0x8(%ebp),%esp
  3c:   5e                      pop    %esi
  3d:   5f                      pop    %edi
  3e:   5d                      pop    %ebp
  3f:   c3                      ret    


The Clang version is 40 bytes larger, more than twice the size of the MSVC one.

It would be good if we could at least get rid off the chkstk calls and the
stacksave/stackrestores.



David took a stab at this in r262370, which was then reverted in r262505 with
the following message:

  The goal of this change was to improve the code size of inalloca call
  sequences, but we got tangled up in the mess of dynamic allocas.
  Instead, we should come back later with a separate MI pass that uses
  dominance to optimize the full sequence. This should also be able to
  remove the often unneeded stacksave/stackrestore pairs around the call.</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>