This is an archive of the discontinued LLVM Phabricator instance.

PATCH] [SimplifyCFG] Run ReduceSwitchRange unconditionally, generalize
AbandonedPublic

Authored by shawnl on Apr 25 2019, 2:07 PM.

Details

Reviewers
jmolloy
Summary

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

Diff Detail

Repository
rL LLVM

Event Timeline

shawnl created this revision.Apr 25 2019, 2:07 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 25 2019, 2:07 PM
shawnl planned changes to this revision.Apr 25 2019, 2:08 PM

needs another test

shawnl abandoned this revision.Apr 25 2019, 4:22 PM