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

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 14 23:02:45 PDT 2023


================
@@ -6552,6 +6552,20 @@ 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 {
+    const APInt *MaskC;
+    if (UseSwitchConditionAsTableIndex &&
+        match(TableIndex, m_And(m_Value(), m_APInt(MaskC)))) {
+      APInt SCVPlus1 = *MaskC + 1;
+      const uint64_t *RawData = MaskC->getRawData();
+      // Expand the size of the table when the MaskC < 64.
+      if (SCVPlus1.isPowerOf2() && SCVPlus1.ule(64) && RawData) {
+        assert(TableSize <= RawData[0] && "unexpect mask value");
+        // The range check will be deleted later when we enlarge the lookup
+        // table because the check always return true.
----------------
nikic wrote:

Might be better to just directly omit the range change?

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


More information about the llvm-commits mailing list