[Bug middle-end/59521] __builtin_expect not effective in switch
marxin at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Tue Jul 11 09:24:00 GMT 2017
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59521
--- Comment #5 from Martin Liška <marxin at gcc dot gnu.org> ---
Ok, your patch is definitely needed to properly propagate the builtin
probability to a proper edge. Apart from that I added code that preserves that
probability incombine_predictions_for_bb. Having that we're quite close:
$ ./xgcc -B. ~/Programming/testcases/pr59521.c -O2 -c -S
-fdump-tree-optimized=/dev/stdout
;; Function f (f, funcdef_no=11, decl_uid=2306, cgraph_uid=11, symbol_order=11)
Removing basic block 7
f (int ch)
{
<bb 2> [100.00%] [count: INV]:
switch (ch_4(D)) <default: <L3> [3.33%] [count: INV], case 3: <L0> [3.33%]
[count: INV], case 42: <L1> [3.33%] [count: INV], case 333: <L2> [90.00%]
[count: INV]>
But still there's a missing piece that will rearrange switch statement so that
case 333 will be first:
f:
.LFB11:
.cfi_startproc
cmpl $42, %edi
je .L3
cmpl $333, %edi
jne .L8
movl $.LC2, %edi
jmp puts
Can you please Yuri take a look?
More information about the Gcc-bugs
mailing list