Re-apply r245635, "[InstCombine] Transform A & (L - 1) u< L --> L != 0"
[oota-llvm.git] / lib / Transforms / InstCombine / InstCombineCompares.cpp
index 9ce1c3fc41b302126f33943cd0d1610a0c3b8749..905f66a380f9457afb1627679eee6aacb893aadd 100644 (file)
@@ -3490,6 +3490,18 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
       }
       }
     }
+
+    if (BO0) {
+      // Transform  A & (L - 1) `ult` L --> L != 0
+      auto LSubOne = m_Add(m_Specific(Op1), m_AllOnes());
+      auto BitwiseAnd =
+          m_CombineOr(m_And(m_Value(), LSubOne), m_And(LSubOne, m_Value()));
+
+      if (match(BO0, BitwiseAnd) && I.getPredicate() == ICmpInst::ICMP_ULT) {
+        auto *Zero = Constant::getNullValue(BO0->getType());
+        return new ICmpInst(ICmpInst::ICMP_NE, Op1, Zero);
+      }
+    }
   }
 
   { Value *A, *B;