OSDN Git Service

[InstCombine] use m_APInt to allow icmp eq (mul X, C1), C2 folds for splat constant...
authorSanjay Patel <spatel@rotateright.com>
Thu, 4 Aug 2016 22:19:27 +0000 (22:19 +0000)
committerSanjay Patel <spatel@rotateright.com>
Thu, 4 Aug 2016 22:19:27 +0000 (22:19 +0000)
This concludes the splat vector enhancements for foldICmpEqualityWithConstant().
Other commits in this series:
https://reviews.llvm.org/rL277762
https://reviews.llvm.org/rL277752
https://reviews.llvm.org/rL277738
https://reviews.llvm.org/rL277731
https://reviews.llvm.org/rL277659
https://reviews.llvm.org/rL277638
https://reviews.llvm.org/rL277629

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@277779 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/InstCombine/InstCombineCompares.cpp
test/Transforms/InstCombine/icmp.ll

index 6c795db..778a75f 100644 (file)
@@ -2314,14 +2314,13 @@ Instruction *InstCombiner::foldICmpEqualityWithConstant(ICmpInst &ICI) {
   }
   case Instruction::Mul:
     if (*RHSV == 0 && BO->hasNoSignedWrap()) {
-      // FIXME: Vectors are excluded by ConstantInt.
-      if (ConstantInt *BOC = dyn_cast<ConstantInt>(BOp1)) {
-        // The trivial case (mul X, 0) is handled by InstSimplify
+      const APInt *BOC;
+      if (match(BOp1, m_APInt(BOC)) && *BOC != 0) {
+        // The trivial case (mul X, 0) is handled by InstSimplify.
         // General case : (mul X, C) != 0 iff X != 0
         //                (mul X, C) == 0 iff X == 0
-        if (!BOC->isZero())
-          return new ICmpInst(ICI.getPredicate(), BOp0,
-                              Constant::getNullValue(RHS->getType()));
+        return new ICmpInst(ICI.getPredicate(), BOp0,
+                            Constant::getNullValue(RHS->getType()));
       }
     }
     break;
index 88cf0cd..27ae64e 100644 (file)
@@ -1207,8 +1207,7 @@ define i1 @icmp_mul_neq0(i32 %x) {
 ; FIXME: Vectors should fold the same way.
 define <2 x i1> @icmp_mul_neq0_vec(<2 x i32> %x) {
 ; CHECK-LABEL: @icmp_mul_neq0_vec(
-; CHECK-NEXT:    [[MUL:%.*]] = mul nsw <2 x i32> %x, <i32 -12, i32 -12>
-; CHECK-NEXT:    [[CMP:%.*]] = icmp ne <2 x i32> [[MUL]], zeroinitializer
+; CHECK-NEXT:    [[CMP:%.*]] = icmp ne <2 x i32> %x, zeroinitializer
 ; CHECK-NEXT:    ret <2 x i1> [[CMP]]
 ;
   %mul = mul nsw <2 x i32> %x, <i32 -12, i32 -12>