[llvm-bugs] [Bug 34786] New: potential missing shrink wrapping on x86_64

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Sep 29 14:18:12 PDT 2017


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

            Bug ID: 34786
           Summary: potential missing shrink wrapping on x86_64
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Backend: X86
          Assignee: unassignedbugs at nondot.org
          Reporter: compnerd at compnerd.org
                CC: llvm-bugs at lists.llvm.org

```
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 at 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.

-- 
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/20170929/825a8b89/attachment.html>


More information about the llvm-bugs mailing list