[llvm] [SimplifyCFG] Delete the unnecessary range check for small mask operation (PR #65835)

via llvm-commits llvm-commits at lists.llvm.org
Sat Oct 21 00:57:55 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())) {
----------------
vfdff wrote:

Apply your comment, thanks

https://github.com/llvm/llvm-project/pull/65835


More information about the llvm-commits mailing list