[llvm] r278945 - [InstCombine] use m_APInt to allow icmp (or X, Y), C folds for splat constant vectors

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 17 09:38:57 PDT 2016


Author: spatel
Date: Wed Aug 17 11:38:57 2016
New Revision: 278945

URL: http://llvm.org/viewvc/llvm-project?rev=278945&view=rev
Log:
[InstCombine] use m_APInt to allow icmp (or X, Y), C folds for splat constant vectors

This is a sibling of:
https://reviews.llvm.org/rL278859
https://reviews.llvm.org/rL278935

Modified:
    llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp
    llvm/trunk/test/Transforms/InstCombine/compare-signs.ll
    llvm/trunk/test/Transforms/InstCombine/or.ll

Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp?rev=278945&r1=278944&r2=278945&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp Wed Aug 17 11:38:57 2016
@@ -1882,11 +1882,6 @@ Instruction *InstCombiner::foldICmpAndCo
 /// Fold icmp (or X, Y), C.
 Instruction *InstCombiner::foldICmpOrConstant(ICmpInst &Cmp, Instruction *Or,
                                               const APInt *C) {
-  // FIXME: This check restricts all folds under here to scalar types.
-  ConstantInt *RHS = dyn_cast<ConstantInt>(Cmp.getOperand(1));
-  if (!RHS)
-    return nullptr;
-
   ICmpInst::Predicate Pred = Cmp.getPredicate();
   if (*C == 1) {
     // icmp slt signum(V) 1 --> icmp slt V, 1

Modified: llvm/trunk/test/Transforms/InstCombine/compare-signs.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/compare-signs.ll?rev=278945&r1=278944&r2=278945&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/compare-signs.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/compare-signs.ll Wed Aug 17 11:38:57 2016
@@ -67,14 +67,9 @@ define i1 @test4a(i32 %a) {
   ret i1 %c
 }
 
-; FIXME: Vectors should fold too.
 define <2 x i1> @test4a_vec(<2 x i32> %a) {
 ; CHECK-LABEL: @test4a_vec(
-; CHECK-NEXT:    [[L:%.*]] = ashr <2 x i32> %a, <i32 31, i32 31>
-; CHECK-NEXT:    [[NA:%.*]] = sub <2 x i32> zeroinitializer, %a
-; CHECK-NEXT:    [[R:%.*]] = lshr <2 x i32> [[NA]], <i32 31, i32 31>
-; CHECK-NEXT:    [[SIGNUM:%.*]] = or <2 x i32> [[L]], [[R]]
-; CHECK-NEXT:    [[C:%.*]] = icmp slt <2 x i32> [[SIGNUM]], <i32 1, i32 1>
+; CHECK-NEXT:    [[C:%.*]] = icmp slt <2 x i32> %a, <i32 1, i32 1>
 ; CHECK-NEXT:    ret <2 x i1> [[C]]
 ;
   %l = ashr <2 x i32> %a, <i32 31, i32 31>

Modified: llvm/trunk/test/Transforms/InstCombine/or.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/or.ll?rev=278945&r1=278944&r2=278945&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/or.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/or.ll Wed Aug 17 11:38:57 2016
@@ -309,10 +309,9 @@ define i1 @test27(i32* %A, i32* %B) {
 
 define <2 x i1> @test27vec(<2 x i32*> %A, <2 x i32*> %B) {
 ; CHECK-LABEL: @test27vec(
-; CHECK-NEXT:    [[C1:%.*]] = ptrtoint <2 x i32*> %A to <2 x i32>
-; CHECK-NEXT:    [[C2:%.*]] = ptrtoint <2 x i32*> %B to <2 x i32>
-; CHECK-NEXT:    [[D:%.*]] = or <2 x i32> [[C1]], [[C2]]
-; CHECK-NEXT:    [[E:%.*]] = icmp eq <2 x i32> [[D]], zeroinitializer
+; CHECK-NEXT:    [[TMP1:%.*]] = icmp eq <2 x i32*> %A, zeroinitializer
+; CHECK-NEXT:    [[TMP2:%.*]] = icmp eq <2 x i32*> %B, zeroinitializer
+; CHECK-NEXT:    [[E:%.*]] = and <2 x i1> [[TMP1]], [[TMP2]]
 ; CHECK-NEXT:    ret <2 x i1> [[E]]
 ;
   %C1 = ptrtoint <2 x i32*> %A to <2 x i32>
@@ -352,10 +351,9 @@ define i1 @test29(i32* %A, i32* %B) {
 
 define <2 x i1> @test29vec(<2 x i32*> %A, <2 x i32*> %B) {
 ; CHECK-LABEL: @test29vec(
-; CHECK-NEXT:    [[C1:%.*]] = ptrtoint <2 x i32*> %A to <2 x i32>
-; CHECK-NEXT:    [[C2:%.*]] = ptrtoint <2 x i32*> %B to <2 x i32>
-; CHECK-NEXT:    [[D:%.*]] = or <2 x i32> [[C1]], [[C2]]
-; CHECK-NEXT:    [[E:%.*]] = icmp ne <2 x i32> [[D]], zeroinitializer
+; CHECK-NEXT:    [[TMP1:%.*]] = icmp ne <2 x i32*> %A, zeroinitializer
+; CHECK-NEXT:    [[TMP2:%.*]] = icmp ne <2 x i32*> %B, zeroinitializer
+; CHECK-NEXT:    [[E:%.*]] = or <2 x i1> [[TMP1]], [[TMP2]]
 ; CHECK-NEXT:    ret <2 x i1> [[E]]
 ;
   %C1 = ptrtoint <2 x i32*> %A to <2 x i32>




More information about the llvm-commits mailing list