Kyrill Tkachov wrote: > On 25/04/16 20:21, Wilco Dijkstra wrote: > > The GCC switch expansion is awful, so > > even with a good indirect predictor it is better to use conditional > > branches. > > In what way is it awful? If there's something we can do better at > can you file a bug report with a testcase so that we can work on > improving it rather than tweaking a heuristic in the backend.
In every way :-( Try this simple example and see whether you agree this is terrible, especially on targets that don't use PC-relative tables... int i; int func(int a) { switch(a) { case 0: i = 20; break; case 1: i = 50; break; case 2: i = 29; break; case 3: i = 20; break; case 4: i = 50; break; case 5: i = 29; break; case 6: i = 20; break; case 7: i = 50; break; case 8: i = 29; break; case 9: i = 79; break; case 110: i = 27; break; default: i = 77; break; } return i; } See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70861. It's also disappointing this doesn't get turned into: return i = (unsigned)a <= 110 ? table[a] : 77; Wilco