[PATCH] D61153: PATCH] [SimplifyCFG] Run ReduceSwitchRange unconditionally, generalize

Shawn Landden via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 25 14:08:59 PDT 2019


shawnl created this revision.
shawnl added a reviewer: jmolloy.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
shawnl planned changes to this revision.
shawnl added a comment.

needs another test


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".


Repository:
  rL LLVM

https://reviews.llvm.org/D61153

Files:
  lib/Transforms/Utils/SimplifyCFG.cpp
  test/Transforms/SimplifyCFG/rangereduce.ll
  test/Transforms/SimplifyCFG/switch-simplify-range.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D61153.196727.patch
Type: text/x-patch
Size: 15262 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190425/0dc8c8fa/attachment.bin>


More information about the llvm-commits mailing list