<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </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 - Shrink wrapping not firing on seemingly basic cases? (maybe i misunderstand how it works)"
   href="https://bugs.llvm.org/show_bug.cgi?id=33868">33868</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Shrink wrapping not firing on seemingly basic cases? (maybe i misunderstand how it works)
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

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

        <tr>
          <th>OS</th>
          <td>All
          </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>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>chandlerc@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>I was digging into sadly unrelated performance issues and noticed a surprising
lack of shrink wrapping for functions with obvious, trivial early-exits.

Here is one example I was able to quickly reproduce:

% cat shrink_wrap.cpp
struct S { long a, b; };

struct C {
  S doit() { return {1, 2}; }
};

S compute() {
  static C* c = new C();
  return c->doit();
}

% ./dev/bin/clang++ -std=c++11 -fno-rtti -fno-exceptions -c -S -o -
shrink_wrap.cpp -O3
        .text
        .file   "shrink_wrap.cpp"
        .globl  _Z7computev             # -- Begin function _Z7computev
        .p2align        4, 0x90
        .type   _Z7computev,@function
_Z7computev:                            # @_Z7computev
        .cfi_startproc
# BB#0:                                 # %entry
        pushq   %rax
.Lcfi0:
        .cfi_def_cfa_offset 16
        movb    _ZGVZ7computevE1c(%rip), %al
        testb   %al, %al
        jne     .LBB0_3
# BB#1:                                 # %init.check
        movl    $_ZGVZ7computevE1c, %edi
        callq   __cxa_guard_acquire
        testl   %eax, %eax
        je      .LBB0_3
# BB#2:                                 # %init
        movl    $1, %edi
        callq   _Znwm
        movq    %rax, _ZZ7computevE1c(%rip)
        movl    $_ZGVZ7computevE1c, %edi
        callq   __cxa_guard_release
.LBB0_3:                                # %init.end
        movl    $1, %eax
        movl    $2, %edx
        popq    %rcx
        retq
.Lfunc_end0:


Why do we need to pushq %rax and popq %rcx in the fast path?</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>