[llvm] 7c51650 - [InstSimplify] allow vector splats for icmp-of-neg folds

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 20 06:24:54 PDT 2020


Author: Sanjay Patel
Date: 2020-10-20T09:24:36-04:00
New Revision: 7c516504a161ad2eff1837fb9b816322455ca330

URL: https://github.com/llvm/llvm-project/commit/7c516504a161ad2eff1837fb9b816322455ca330
DIFF: https://github.com/llvm/llvm-project/commit/7c516504a161ad2eff1837fb9b816322455ca330.diff

LOG: [InstSimplify] allow vector splats for icmp-of-neg folds

Added: 
    

Modified: 
    llvm/lib/Analysis/InstructionSimplify.cpp
    llvm/test/Transforms/InstSimplify/compare.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index e0b275aea9a1..b730eb33960a 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -2936,22 +2936,19 @@ static Value *simplifyICmpWithBinOp(CmpInst::Predicate Pred, Value *LHS,
 
   // 0 - (zext X) pred C
   if (!CmpInst::isUnsigned(Pred) && match(LHS, m_Neg(m_ZExt(m_Value())))) {
-    if (ConstantInt *RHSC = dyn_cast<ConstantInt>(RHS)) {
-      if (RHSC->getValue().isStrictlyPositive()) {
-        if (Pred == ICmpInst::ICMP_SLT)
-          return ConstantInt::getTrue(RHSC->getContext());
-        if (Pred == ICmpInst::ICMP_SGE)
-          return ConstantInt::getFalse(RHSC->getContext());
-        if (Pred == ICmpInst::ICMP_EQ)
-          return ConstantInt::getFalse(RHSC->getContext());
-        if (Pred == ICmpInst::ICMP_NE)
-          return ConstantInt::getTrue(RHSC->getContext());
+    const APInt *C;
+    if (match(RHS, m_APInt(C))) {
+      if (C->isStrictlyPositive()) {
+        if (Pred == ICmpInst::ICMP_SLT || Pred == ICmpInst::ICMP_NE)
+          return ConstantInt::getTrue(GetCompareTy(RHS));
+        if (Pred == ICmpInst::ICMP_SGE || Pred == ICmpInst::ICMP_EQ)
+          return ConstantInt::getFalse(GetCompareTy(RHS));
       }
-      if (RHSC->getValue().isNonNegative()) {
+      if (C->isNonNegative()) {
         if (Pred == ICmpInst::ICMP_SLE)
-          return ConstantInt::getTrue(RHSC->getContext());
+          return ConstantInt::getTrue(GetCompareTy(RHS));
         if (Pred == ICmpInst::ICMP_SGT)
-          return ConstantInt::getFalse(RHSC->getContext());
+          return ConstantInt::getFalse(GetCompareTy(RHS));
       }
     }
   }

diff  --git a/llvm/test/Transforms/InstSimplify/compare.ll b/llvm/test/Transforms/InstSimplify/compare.ll
index e2fcaee72609..a029d0b3c60d 100644
--- a/llvm/test/Transforms/InstSimplify/compare.ll
+++ b/llvm/test/Transforms/InstSimplify/compare.ll
@@ -1129,10 +1129,7 @@ define i1 @compare_always_true_slt(i16 %a) {
 
 define <2 x i1> @compare_always_true_slt_splat(<2 x i16> %a) {
 ; CHECK-LABEL: @compare_always_true_slt_splat(
-; CHECK-NEXT:    [[T1:%.*]] = zext <2 x i16> [[A:%.*]] to <2 x i32>
-; CHECK-NEXT:    [[T2:%.*]] = sub <2 x i32> zeroinitializer, [[T1]]
-; CHECK-NEXT:    [[T3:%.*]] = icmp slt <2 x i32> [[T2]], <i32 1, i32 1>
-; CHECK-NEXT:    ret <2 x i1> [[T3]]
+; CHECK-NEXT:    ret <2 x i1> <i1 true, i1 true>
 ;
   %t1 = zext <2 x i16> %a to <2 x i32>
   %t2 = sub <2 x i32> zeroinitializer, %t1
@@ -1152,10 +1149,7 @@ define i1 @compare_always_true_sle(i16 %a) {
 
 define <2 x i1> @compare_always_true_sle_splat(<2 x i16> %a) {
 ; CHECK-LABEL: @compare_always_true_sle_splat(
-; CHECK-NEXT:    [[T1:%.*]] = zext <2 x i16> [[A:%.*]] to <2 x i32>
-; CHECK-NEXT:    [[T2:%.*]] = sub <2 x i32> zeroinitializer, [[T1]]
-; CHECK-NEXT:    [[T3:%.*]] = icmp sle <2 x i32> [[T2]], zeroinitializer
-; CHECK-NEXT:    ret <2 x i1> [[T3]]
+; CHECK-NEXT:    ret <2 x i1> <i1 true, i1 true>
 ;
   %t1 = zext <2 x i16> %a to <2 x i32>
   %t2 = sub <2 x i32> zeroinitializer, %t1
@@ -1175,10 +1169,7 @@ define i1 @compare_always_false_sgt(i16 %a) {
 
 define <2 x i1> @compare_always_false_sgt_splat(<2 x i16> %a) {
 ; CHECK-LABEL: @compare_always_false_sgt_splat(
-; CHECK-NEXT:    [[T1:%.*]] = zext <2 x i16> [[A:%.*]] to <2 x i32>
-; CHECK-NEXT:    [[T2:%.*]] = sub <2 x i32> zeroinitializer, [[T1]]
-; CHECK-NEXT:    [[T3:%.*]] = icmp sgt <2 x i32> [[T2]], zeroinitializer
-; CHECK-NEXT:    ret <2 x i1> [[T3]]
+; CHECK-NEXT:    ret <2 x i1> zeroinitializer
 ;
   %t1 = zext <2 x i16> %a to <2 x i32>
   %t2 = sub <2 x i32> zeroinitializer, %t1
@@ -1198,10 +1189,7 @@ define i1 @compare_always_false_sge(i16 %a) {
 
 define <2 x i1> @compare_always_false_sge_splat(<2 x i16> %a) {
 ; CHECK-LABEL: @compare_always_false_sge_splat(
-; CHECK-NEXT:    [[T1:%.*]] = zext <2 x i16> [[A:%.*]] to <2 x i32>
-; CHECK-NEXT:    [[T2:%.*]] = sub <2 x i32> zeroinitializer, [[T1]]
-; CHECK-NEXT:    [[T3:%.*]] = icmp sge <2 x i32> [[T2]], <i32 1, i32 1>
-; CHECK-NEXT:    ret <2 x i1> [[T3]]
+; CHECK-NEXT:    ret <2 x i1> zeroinitializer
 ;
   %t1 = zext <2 x i16> %a to <2 x i32>
   %t2 = sub <2 x i32> zeroinitializer, %t1
@@ -1221,10 +1209,7 @@ define i1 @compare_always_false_eq(i16 %a) {
 
 define <2 x i1> @compare_always_false_eq_splat(<2 x i16> %a) {
 ; CHECK-LABEL: @compare_always_false_eq_splat(
-; CHECK-NEXT:    [[T1:%.*]] = zext <2 x i16> [[A:%.*]] to <2 x i32>
-; CHECK-NEXT:    [[T2:%.*]] = sub <2 x i32> zeroinitializer, [[T1]]
-; CHECK-NEXT:    [[T3:%.*]] = icmp eq <2 x i32> [[T2]], <i32 1, i32 1>
-; CHECK-NEXT:    ret <2 x i1> [[T3]]
+; CHECK-NEXT:    ret <2 x i1> zeroinitializer
 ;
   %t1 = zext <2 x i16> %a to <2 x i32>
   %t2 = sub <2 x i32> zeroinitializer, %t1
@@ -1244,10 +1229,7 @@ define i1 @compare_always_true_ne(i16 %a) {
 
 define <2 x i1> @compare_always_true_ne_splat(<2 x i16> %a) {
 ; CHECK-LABEL: @compare_always_true_ne_splat(
-; CHECK-NEXT:    [[T1:%.*]] = zext <2 x i16> [[A:%.*]] to <2 x i32>
-; CHECK-NEXT:    [[T2:%.*]] = sub <2 x i32> zeroinitializer, [[T1]]
-; CHECK-NEXT:    [[T3:%.*]] = icmp ne <2 x i32> [[T2]], <i32 1, i32 1>
-; CHECK-NEXT:    ret <2 x i1> [[T3]]
+; CHECK-NEXT:    ret <2 x i1> <i1 true, i1 true>
 ;
   %t1 = zext <2 x i16> %a to <2 x i32>
   %t2 = sub <2 x i32> zeroinitializer, %t1


        


More information about the llvm-commits mailing list