[llvm] [SimplifyCFG] Delete the unnecessary range check for small mask operation (PR #65835)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 20 07:51:00 PDT 2023
================
@@ -6631,6 +6630,23 @@ static bool SwitchToLookupTable(SwitchInst *SI, IRBuilder<> &Builder,
BranchInst *RangeCheckBranch = nullptr;
+ // Grow the table to cover all possible index values to avoid the range check.
+ if (UseSwitchConditionAsTableIndex) {
+ ConstantRange CR = computeConstantRange(TableIndex, /* ForSigned */ false);
+ // Grow the table shouldn't have any size impact by checking
+ // WouldFitInRegister.
+ // TODO: Consider growing the table also when it doesn't fit in a register
+ // if no optsize is specified.
+ if (SwitchLookupTable::WouldFitInRegister(
+ DL, CR.getUpper().getLimitedValue(), PHIs[0]->getType())) {
----------------
nikic wrote:
This is checking the type of just one phi. Compare with the use here: https://github.com/llvm/llvm-project/blob/7d66f9b5aa8b15602b2b345b36af00a28b5a4f9d/llvm/lib/Transforms/Utils/SimplifyCFG.cpp#L6390-L6394
https://github.com/llvm/llvm-project/pull/65835
More information about the llvm-commits
mailing list