[llvm] r277779 - [InstCombine] use m_APInt to allow icmp eq (mul X, C1), C2 folds for splat constant vectors

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 4 15:19:27 PDT 2016


Author: spatel
Date: Thu Aug  4 17:19:27 2016
New Revision: 277779

URL: http://llvm.org/viewvc/llvm-project?rev=277779&view=rev
Log:
[InstCombine] use m_APInt to allow icmp eq (mul X, C1), C2 folds for splat constant vectors

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


Modified:
    llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp
    llvm/trunk/test/Transforms/InstCombine/icmp.ll

Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp?rev=277779&r1=277778&r2=277779&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp Thu Aug  4 17:19:27 2016
@@ -2314,14 +2314,13 @@ Instruction *InstCombiner::foldICmpEqual
   }
   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;

Modified: llvm/trunk/test/Transforms/InstCombine/icmp.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/icmp.ll?rev=277779&r1=277778&r2=277779&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/icmp.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/icmp.ll Thu Aug  4 17:19:27 2016
@@ -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>




More information about the llvm-commits mailing list