jameysharp commented on issue #5644:
A couple of thoughts for future work, maybe:
If
build_search_branches
did the subtraction offirst_index
instead of doing it inbuild_jump_table
, theicmp_imm_u128
checks there could always be tests against 0. For switch cases >= 2^64 I think that would reduce the number of CLIF instructions we generate, which isn't super important. More interestingly, I think we might be able to generate fewer machine instructions on some targets that way, although I'm not sure if we need better lowering rules or anything to fully take advantage.We might generate better code by merging contiguous case ranges that have small gaps between them. We can insert branches to the "default" block into a combined jump-table with a code-size cost proportional to the size of the gap, which may be smaller than the size of the instructions needed to check which range to evaluate. So there's a potential code-size advantage, and as long as at least one of the ranges was going to generate a jump-table anyway, I think there's always an advantage in terms of number of instructions/branches executed.
Last updated: Nov 22 2024 at 17:03 UTC