[llvm-bugs] [Bug 27076] New: inefficient codegen for inalloca calls

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Mar 25 14:24:21 PDT 2016


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

            Bug ID: 27076
           Summary: inefficient codegen for inalloca calls
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Backend: X86
          Assignee: unassignedbugs at nondot.org
          Reporter: hans at chromium.org
                CC: llvm-bugs at lists.llvm.org, rnk at google.com
            Blocks: 26299
    Classification: Unclassified

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.

-- 
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/20160325/de0ce254/attachment-0001.html>


More information about the llvm-bugs mailing list