[cfe-dev] __builtin_expect hint ignored

Halfdan Ingvarsson via cfe-dev cfe-dev at lists.llvm.org
Tue Apr 18 16:38:40 PDT 2017


Interestingly, clang 3.6 seemed to do the right thing, but 3.7 onwards
ignores __builtin_expect for this particular case.

All versions of gcc and Intel both generate jump tables, which I assume is
even less optimal in this case.


- ½

On 18 April 2017 at 17:56, Adam Nowacki via cfe-dev <cfe-dev at lists.llvm.org>
wrote:

> https://godbolt.org/g/VvrbFZ
>
> For the code below generated assembly is the worst possible - test 1, else
> test 3, else test 2 with expected value of 2 last ... Whats going on?
>
> long case_2();
> long case_3();
> long case_1();
> long case_else();
> long test(long a) {
>     switch (__builtin_expect(a, 2)) {
>         case 2: return case_2();
>         case 3: return case_3();
>         case 1: return case_1();
>         case 0:
>         case 4:
>         case 5: return case_else();
>         default: __builtin_unreachable();
>     }
> }
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170418/e5b59a06/attachment.html>


More information about the cfe-dev mailing list