ReduceSwitchRange only ran if the switch statement wasn't "dense". This is a very cheap transform, if it can make improvements should be runI am trying to move towards much more space-efficient wwitch statements, so run it all the time.using popcnt, (that is all IsSwitchDense did,as described in PR39013. it did not determine if a jump table or lookup table should be generated) Also:This is the first patch towards that goal.
*ReduceSwitchRange only ran if the switch statement wasn't "dense", resulting in unnecessary sparse switch statements. This is a very cheap transform, if it can make improvements should be run, so run it all the time. (that is all IsSwitchDense did, it did not determine if a jump table or lookup table should be generated) Also:
* Do not do an expensive general GCD calculation when only countTrailingZeros() information is used from it.
* Re-order values to ideal with a subtraction, instead of only covering some cases by treating the values as signed.
* Implement the ctlz/cttz transform that was suggested in the comments. This transform is still not ideal, as SwitchToLookupTable doesn't know the potential range of values has been reduced, and there is no good plumbing in LLVM (that I know of) to get that information, and KnownBits is not sufficient.