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

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 3 12:48:41 PDT 2016


Author: spatel
Date: Wed Aug  3 14:48:40 2016
New Revision: 277638

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

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

Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp?rev=277638&r1=277637&r2=277638&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp Wed Aug  3 14:48:40 2016
@@ -2218,10 +2218,9 @@ Instruction *InstCombiner::foldICmpEqual
   switch (BO->getOpcode()) {
   case Instruction::SRem:
     // If we have a signed (X % (2^c)) == 0, turn it into an unsigned one.
-    // FIXME: Vectors are excluded by ConstantInt.
-    if (*RHSV == 0 && isa<ConstantInt>(BOp1) && BO->hasOneUse()) {
-      const APInt &V = cast<ConstantInt>(BOp1)->getValue();
-      if (V.sgt(1) && V.isPowerOf2()) {
+    if (*RHSV == 0 && BO->hasOneUse()) {
+      const APInt *BOC;
+      if (match(BOp1, m_APInt(BOC)) && BOC->sgt(1) && BOC->isPowerOf2()) {
         Value *NewRem = Builder->CreateURem(BOp0, BOp1, BO->getName());
         return new ICmpInst(ICI.getPredicate(), NewRem,
                             Constant::getNullValue(BO->getType()));

Modified: llvm/trunk/test/Transforms/InstCombine/rem.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/rem.ll?rev=277638&r1=277637&r2=277638&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/rem.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/rem.ll Wed Aug  3 14:48:40 2016
@@ -53,12 +53,10 @@ define i1 @test3a(i32 %A) {
 	ret i1 %C
 }
 
-; FIXME: Vectors should fold the same way.
-
 define <2 x i1> @test3a_vec(<2 x i32> %A) {
 ; CHECK-LABEL: @test3a_vec(
-; CHECK-NEXT:    [[B:%.*]] = srem <2 x i32> %A, <i32 8, i32 8>
-; CHECK-NEXT:    [[C:%.*]] = icmp ne <2 x i32> [[B]], zeroinitializer
+; CHECK-NEXT:    [[B1:%.*]] = and <2 x i32> %A, <i32 7, i32 7>
+; CHECK-NEXT:    [[C:%.*]] = icmp ne <2 x i32> [[B1]], zeroinitializer
 ; CHECK-NEXT:    ret <2 x i1> [[C]]
 ;
   %B = srem <2 x i32> %A, <i32 -8, i32 -8>




More information about the llvm-commits mailing list