]> granicus.if.org Git - llvm/commit
[SimplifyCFG] Run ReduceSwitchRange unconditionally, generalize
authorShawn Landden <shawn@git.icu>
Sun, 26 May 2019 13:55:14 +0000 (13:55 +0000)
committerShawn Landden <shawn@git.icu>
Sun, 26 May 2019 13:55:14 +0000 (13:55 +0000)
commitae37018572794531b1d1df9a10bd159ec2fece3f
treeb25b1870ad419238efd0d207df48efc887bdc796
parentd3a265fe31e583bb8a123ce96d076e9cd3677848
[SimplifyCFG] Run ReduceSwitchRange unconditionally, generalize

Rather than gating on "isSwitchDense" (resulting in necessesarily
sparse lookup tables even when they were generated), always run
this quite cheap transform.

This transform is useful not just for generating tables.
LowerSwitch also wants this: read LowerSwitch.cpp:257.

Be careful to not generate worse code, by introducing a
SubThreshold heuristic.

Instead of just sorting by signed, generalize the finding of the
best base.

And now that it is run unconditionally, do not replicate its
functionality in SwitchToLookupTable (which could use a Sub
when having a hole is smaller, hence the SubThreshold
heuristic located in a single place).
This simplifies SwitchToLookupTable, and fixes
some ugly corner cases due to the use of signed numbers,
such as a table containing i16 32768 and 32769, of which
32769 would be interpreted as -32768, and now the code thinks
the table is size 65536.

(We still use unconditional subtraction when building a single-register mask,
but I think this whole block should go when the more general sparse
map is added, which doesn't leave empty holes in the table.)

And the reason test4 and test5 did not trigger was documented wrong:
it was because they were not considered sufficiently "dense".

Also, fix generation of invalid LLVM-IR: shl by bit-width.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@361727 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Transforms/Utils/SimplifyCFG.cpp
test/Transforms/SimplifyCFG/X86/disable-lookup-table.ll
test/Transforms/SimplifyCFG/X86/switch-covered-bug.ll
test/Transforms/SimplifyCFG/X86/switch-table-bug.ll
test/Transforms/SimplifyCFG/X86/switch_to_lookup_table.ll
test/Transforms/SimplifyCFG/rangereduce.ll
test/Transforms/SimplifyCFG/switch-dead-default.ll