<div dir="ltr">Interestingly, clang 3.6 seemed to do the right thing, but 3.7 onwards ignores __builtin_expect for this particular case.<div><br></div><div>All versions of gcc and Intel both generate jump tables, which I assume is even less optimal in this case.</div></div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature" data-smartmail="gmail_signature"><br> - ½<br></div></div>
<br><div class="gmail_quote">On 18 April 2017 at 17:56, Adam Nowacki via cfe-dev <span dir="ltr"><<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><a href="https://godbolt.org/g/VvrbFZ" rel="noreferrer" target="_blank">https://godbolt.org/g/VvrbFZ</a><br>
<br>
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?<br>
<br>
long case_2();<br>
long case_3();<br>
long case_1();<br>
long case_else();<br>
long test(long a) {<br>
switch (__builtin_expect(a, 2)) {<br>
case 2: return case_2();<br>
case 3: return case_3();<br>
case 1: return case_1();<br>
case 0:<br>
case 4:<br>
case 5: return case_else();<br>
default: __builtin_unreachable();<br>
}<br>
}<br>
______________________________<wbr>_________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-dev</a><br>
</blockquote></div><br></div>