<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/80107>80107</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Missed optimization: long conditional jump on hot path
</td>
</tr>
<tr>
<th>Labels</th>
<td>
llvm:optimizations,
missed-optimization
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
dvyukov
</td>
</tr>
</table>
<pre>
Consider the following code:
```
int fast(int x, bool f) {
if (__builtin_expect(f, false)) {
return very_slow_path(x);
}
return x + 1;
}
```
Currently clang emits a long 6-byte conditional jump instruction on the hot path of the function:
```
jne 1130 <_Z14very_slow_pathi>
```
I think for *very* hot functions it's better to emit a short 2-byte conditional jump on the hot path, and place long jump on a slow path. The nominal latency is the same for both, but more instruction bytes require more I cache space, and can move subsequent hot code to additional cache lines (?). This is hard to measure in micro-benchmarks.
https://godbolt.org/z/rqYf8cTE9
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx8VMty2zgQ_JrhZUoqEJRI6sCDLEdVOewtl92LCiSGImwQkPFQrHz9FsDIib3rqFR8TfeguzGk8F6dDVEH2wfYPhYihsm6Tl5v8dlei97KW3ewxitJDsNEOFqt7XdlzjhYSVDtgT0C20PNfv7zrTIBR-ED8DZdvgI_YG-txhH4DqF5WGCIiGpE4O3p1EelgzIner3QkIhjIo1CewK--w8t_RyF6Axeyd1OXtvvp4sIE_D2NRGqOxiax1-0n5RXBP6A5RvoDfPBx3I8ROfIBH3DQQtzRppV8ChQW3PGetXfAuFgjVRBWSM0PsX5gsr44OKQHqE1ObvJBkwS0Y5LltHk-mcp4pMhLMuKIVSH0z_l5r1TBdWXP6j-imFS5hlH6xD4PnGB77OI-8IeVQDeeOwphLTBNntDgX6yLiD_xNsHP2mjhJF40WKgJZU7TGCSm1Fr_DYRGjur1EeLQGa4ofK5lRczZaW9Xfr1MeBsHb3LManx6OglKkdL-SsOYkgNLmKgu5BBGJztldDH3tNLJBOy2DSyyaSQb34WtlaGfJpDqI7Ad0mq8knbJJxMjJmEj1kNzmpwdtWTGaZZuGe__j30KYSLT_vJj8CPZyt7q8PaujPw4w_gR_fy99gO377sFnghu0ruqp0oqCsbVtftZtPWxdSxcjds-cjk2HLJqrpiDd-2bCcZibGpt4XqOOMbVlYla1jJ67WUfS3kWNWi2YpG9LBhNAul11pf56SgUN5H6lpWsqbQoift81vPeUJAtbeXoGb1Q-TJAM6BH4DzWXlPcvV7MdW2j4XrEnHVx7OHDdPKB_9rsaCCpu6vTMZ35Gq_jMj_TdV9oorodPchSxWm2K8HOwM_ZsXLaXVx9il_MY7ZoAd-zB7_DQAA__-xa40D">