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

via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 19 04:33:58 PDT 2023


================
@@ -6545,6 +6544,19 @@ 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);
+    if (SwitchLookupTable::WouldFitInRegister(
----------------
zmodem wrote:

Maybe add a comment explaining why we check `WouldFitInRegister`: that by doing so, growing the table shouldn't have any size impact.

And maybe put a TODO that we could consider growing the table also when it doesn't fit in a register. A small size increase might be worth removing the range check.

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


More information about the llvm-commits mailing list