Transform (sub 0, (zext bool to A)) to (sext bool to A) and
[oota-llvm.git] / lib / Transforms / InstCombine / InstCombineAddSub.cpp
index 03be8ef6fb707c2c26a3b0c5c7d427616b3ac53d..c6d60d6f008b87d0d8b2838b47f66c5856f20353 100644 (file)
@@ -1250,6 +1250,16 @@ Instruction *InstCombiner::visitSub(BinaryOperator &I) {
 
     if (SimplifyDemandedInstructionBits(I))
       return &I;
+
+    // Fold (sub 0, (zext bool to B)) --> (sext bool to B)
+    if (C->isZero() && match(Op1, m_ZExt(m_Value(X))))
+      if (X->getType()->isIntegerTy(1))
+        return CastInst::CreateSExtOrBitCast(X, Op1->getType());
+
+    // Fold (sub 0, (sext bool to B)) --> (zext bool to B)
+    if (C->isZero() && match(Op1, m_SExt(m_Value(X))))
+      if (X->getType()->isIntegerTy(1))
+        return CastInst::CreateZExtOrBitCast(X, Op1->getType());
   }