[llvm-bugs] [Bug 37368] Missed small switch optimizations

via llvm-bugs llvm-bugs at lists.llvm.org
Tue May 8 08:34:43 PDT 2018


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

David Bolvansky <david.bolvansky at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|INVALID                     |---

--- Comment #3 from David Bolvansky <david.bolvansky at gmail.com> ---
Clang ignores likely hints?

#define likely(x)       __builtin_expect((x),1)


// switch like
char * b(int e) {
    if (likely(e == 0))
        return "0";
    else if (e == 1)
        return "1";
    else return "f";
}

Clang:
b: # @b
  cmp edi, 1
  mov eax, offset .L.str.1
  mov ecx, offset .L.str.2
  cmove rcx, rax
  test edi, edi
  mov eax, offset .L.str
  cmovne rax, rcx
  ret


GCC:
b:
  mov eax, OFFSET FLAT:.LC0
  test edi, edi
  jne .L7
  ret
.L7:
  cmp edi, 1
  mov edx, OFFSET FLAT:.LC2
  mov eax, OFFSET FLAT:.LC1
  cmovne rax, rdx
  ret

-- 
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/20180508/726cfb2e/attachment-0001.html>


More information about the llvm-bugs mailing list