[llvm] [SimplifyCFG] Delete the unnecessary range check for small mask operation (PR #65835)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 18 01:57:11 PDT 2023
================
@@ -6552,10 +6552,25 @@ static bool SwitchToLookupTable(SwitchInst *SI, IRBuilder<> &Builder,
// Note: We call removeProdecessor later since we need to be able to get the
// PHI value for the default case in case we're using a bit mask.
} else {
- Value *Cmp = Builder.CreateICmpULT(
- TableIndex, ConstantInt::get(MinCaseVal->getType(), TableSize));
- RangeCheckBranch =
- Builder.CreateCondBr(Cmp, LookupBB, SI->getDefaultDest());
+ int KeepDefaultBranch = true;
+ if (UseSwitchConditionAsTableIndex) {
+ ConstantRange CR = computeConstantRange(TableIndex, /* ForSigned */ false,
+ /* UseInstrInfo*/ true);
+ if (DL.fitsInLegalInteger(CR.getUpper().getZExtValue())) {
----------------
nikic wrote:
fitsInLegalInteger() accepts a bit width, while you are passing the value itself. Should be `CR.getUpper().getActiveBits()`.
Also this should be `getUnsignedMax()` rather than `getUpper()`.
https://github.com/llvm/llvm-project/pull/65835
More information about the llvm-commits
mailing list