<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 - potential missing shrink wrapping on x86_64"
   href="https://bugs.llvm.org/show_bug.cgi?id=34786">34786</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>potential missing shrink wrapping on x86_64
          </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>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>Backend: X86
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>compnerd@compnerd.org
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>```
void (*e)(void *);

extern void g(void *);

void f(void *p) {
  if (__builtin_expect(e != (void *)0, 0))
    e(p);
  g(p);
}

```

%clang_cc1 -mrelocation-model static -triple i386-apple-macosx10.4.0 -S -Os -o
- %s

Generates:

```
_f:
        movl    _e, %eax
        testl   %eax, %eax
        jne     LBB0_1
        jmp     _g
LBB0_1:
        subl    $12, %esp
        movl    16(%esp), %ecx
        movl    %ecx, (%esp)
        calll   *%eax
        addl    $12, %esp
        jmp     _g
```

However, note the following on x86_64:

%clang_cc1 -mrelocation-model static -triple x86_64-apple-macosx10.4.0 -S -Os
-o - %s

```
_f:
        pushq   %rbx
        movq    %rdi, %rbx
        movq    _e@GOTPCREL(%rip), %rax
        movq    (%rax), %rax
        testq   %rax, %rax
        jne     LBB0_1
LBB0_2:
        movq    %rbx, %rdi
        popq    %rbx
        jmp     _g
LBB0_1:
        movq    %rbx, %rdi
        callq   *%rax
        jmp     LBB0_2
```

On the case of x86_64, we do not generate a tail call to `g`, opting to
coalesce the BBs across the tail call.  However, the call to `g` is explicitly
being marked as cold via the `__builtin_expect` with the false parameter.

Is there something that I'm overlooking or is this a limitation on our shrink
wrapping?  Seems that this may be related to PR33868.</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>