logoalt Hacker News

Switch Lowering in GCC

51 points • by signa11 • today at 8:02 AM • 3 comments • view on HN

Comments

LarsKrimi • today at 10:03 AM

> The switch in sparse_8 could be simplified by dividing x by eight before the jump. Interestingly, gcc doesn't find this simplification.

It could not because that would ensure that 7 values for each case would be handled by function calls instead of the default case - 0/8 is 0, but 3/8 is also 0

sylware • today at 10:07 AM

In order to peak into hardware speculation/BTB, having a look atswitch lowering seems a good way. Big switches will go into serious convolution to please that hardware since by definition this is a source of a lot of branch mispredicitions.

arsalan17 • today at 9:19 AM

This one was interesting, especially its name :)