[llvm-dev] Ignored branch predictor hints
David Zarzycki via llvm-dev
llvm-dev at lists.llvm.org
Wed May 9 11:29:52 PDT 2018
I’d wager that the if-else chain is being converted to a "switch statement” during an optimization pass and the __builtin_expect() hint is lost. Can you file a bug? https://bugs.llvm.org
> On May 9, 2018, at 1:57 PM, Dávid Bolvanský via llvm-dev <llvm-dev at lists.llvm.org> wrote:
>
> Hello,
> #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";
> }
> GCC correctly prefers the first case:
> b(int):
> mov eax, OFFSET FLAT:.LC0
> test edi, edi
> jne .L7
> ret
>
> But Clang seems to ignore _builtin_expect hints in this case.
> b(int): # @b(int)
> 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
> https://godbolt.org/g/tuAVT7 <https://godbolt.org/g/tuAVT7>_______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180509/8eaed29c/attachment.html>
More information about the llvm-dev
mailing list