[llvm] edcdc81 - [ValueTracking] add UGT/UGE and SGT/SGE in `isImpliedCondOperands`

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Thu May 4 08:01:49 PDT 2023


Author: Siyuan Zhu
Date: 2023-05-04T16:59:07+02:00
New Revision: edcdc81e2bb39ff8bf6c326c24f4b70e9eebea3d

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

LOG: [ValueTracking] add UGT/UGE and SGT/SGE in `isImpliedCondOperands`

Partially `fix` https://github.com/llvm/llvm-project/issues/62441.

Extend isImpliedCondOperands() to handle ugt/uge and sgt/sge predicates.

alive2 proof: https://alive2.llvm.org/ce/z/jLFDAv and
https://alive2.llvm.org/ce/z/Z8idUd

Differential Revision: https://reviews.llvm.org/D149510

Added: 
    

Modified: 
    llvm/lib/Analysis/ValueTracking.cpp
    llvm/test/Transforms/InstSimplify/implies.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index ec05fa99b1b3f..1a15ad4bb6aa6 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -8144,12 +8144,26 @@ isImpliedCondOperands(CmpInst::Predicate Pred, const Value *ALHS,
       return true;
     return std::nullopt;
 
+  case CmpInst::ICMP_SGT:
+  case CmpInst::ICMP_SGE:
+    if (isTruePredicate(CmpInst::ICMP_SLE, ALHS, BLHS, DL, Depth) &&
+        isTruePredicate(CmpInst::ICMP_SLE, BRHS, ARHS, DL, Depth))
+      return true;
+    return std::nullopt;
+
   case CmpInst::ICMP_ULT:
   case CmpInst::ICMP_ULE:
     if (isTruePredicate(CmpInst::ICMP_ULE, BLHS, ALHS, DL, Depth) &&
         isTruePredicate(CmpInst::ICMP_ULE, ARHS, BRHS, DL, Depth))
       return true;
     return std::nullopt;
+
+  case CmpInst::ICMP_UGT:
+  case CmpInst::ICMP_UGE:
+    if (isTruePredicate(CmpInst::ICMP_ULE, ALHS, BLHS, DL, Depth) &&
+        isTruePredicate(CmpInst::ICMP_ULE, BRHS, ARHS, DL, Depth))
+      return true;
+    return std::nullopt;
   }
 }
 

diff  --git a/llvm/test/Transforms/InstSimplify/implies.ll b/llvm/test/Transforms/InstSimplify/implies.ll
index a7949cc77495e..e94ad62e5e32c 100644
--- a/llvm/test/Transforms/InstSimplify/implies.ll
+++ b/llvm/test/Transforms/InstSimplify/implies.ll
@@ -271,11 +271,7 @@ define i1 @test_sle(i32 %length.i, i32 %i) {
 ; X +_{nsw} 1 <(s) Y ==> X <(s) Y
 define i1 @test_sgt_icmp(i32 %length.i, i32 %i) {
 ; CHECK-LABEL: @test_sgt_icmp(
-; CHECK-NEXT:    [[IPLUS1:%.*]] = add nsw i32 [[I:%.*]], 1
-; CHECK-NEXT:    [[VAR29:%.*]] = icmp sgt i32 [[LENGTH_I:%.*]], [[I]]
-; CHECK-NEXT:    [[VAR30:%.*]] = icmp sgt i32 [[LENGTH_I]], [[IPLUS1]]
-; CHECK-NEXT:    [[RES:%.*]] = icmp ule i1 [[VAR30]], [[VAR29]]
-; CHECK-NEXT:    ret i1 [[RES]]
+; CHECK-NEXT:    ret i1 true
 ;
   %iplus1 = add nsw i32 %i, 1
   %var29 = icmp sgt i32 %length.i, %i
@@ -287,11 +283,7 @@ define i1 @test_sgt_icmp(i32 %length.i, i32 %i) {
 ; X +_{nsw} 1 <=(s) Y ==> X <=(s) Y
 define i1 @test_sge_icmp(i32 %length.i, i32 %i) {
 ; CHECK-LABEL: @test_sge_icmp(
-; CHECK-NEXT:    [[IPLUS1:%.*]] = add nsw i32 [[I:%.*]], 1
-; CHECK-NEXT:    [[VAR29:%.*]] = icmp sge i32 [[LENGTH_I:%.*]], [[I]]
-; CHECK-NEXT:    [[VAR30:%.*]] = icmp sge i32 [[LENGTH_I]], [[IPLUS1]]
-; CHECK-NEXT:    [[RES:%.*]] = icmp ule i1 [[VAR30]], [[VAR29]]
-; CHECK-NEXT:    ret i1 [[RES]]
+; CHECK-NEXT:    ret i1 true
 ;
   %iplus1 = add nsw i32 %i, 1
   %var29 = icmp sge i32 %length.i, %i
@@ -303,11 +295,7 @@ define i1 @test_sge_icmp(i32 %length.i, i32 %i) {
 ; X +_{nuw} 1 <(u) Y ==> X <(u) Y
 define i1 @test_ugt_icmp(i32 %length.i, i32 %i) {
 ; CHECK-LABEL: @test_ugt_icmp(
-; CHECK-NEXT:    [[IPLUS1:%.*]] = add nuw i32 [[I:%.*]], 1
-; CHECK-NEXT:    [[VAR29:%.*]] = icmp ugt i32 [[LENGTH_I:%.*]], [[I]]
-; CHECK-NEXT:    [[VAR30:%.*]] = icmp ugt i32 [[LENGTH_I]], [[IPLUS1]]
-; CHECK-NEXT:    [[RES:%.*]] = icmp ule i1 [[VAR30]], [[VAR29]]
-; CHECK-NEXT:    ret i1 [[RES]]
+; CHECK-NEXT:    ret i1 true
 ;
   %iplus1 = add nuw i32 %i, 1
   %var29 = icmp ugt i32 %length.i, %i
@@ -319,11 +307,7 @@ define i1 @test_ugt_icmp(i32 %length.i, i32 %i) {
 ; X +_{nuw} 1 <=(u) Y ==> X <=(u) Y
 define i1 @test_uge_icmp(i32 %length.i, i32 %i) {
 ; CHECK-LABEL: @test_uge_icmp(
-; CHECK-NEXT:    [[IPLUS1:%.*]] = add nuw i32 [[I:%.*]], 1
-; CHECK-NEXT:    [[VAR29:%.*]] = icmp uge i32 [[LENGTH_I:%.*]], [[I]]
-; CHECK-NEXT:    [[VAR30:%.*]] = icmp uge i32 [[LENGTH_I]], [[IPLUS1]]
-; CHECK-NEXT:    [[RES:%.*]] = icmp ule i1 [[VAR30]], [[VAR29]]
-; CHECK-NEXT:    ret i1 [[RES]]
+; CHECK-NEXT:    ret i1 true
 ;
   %iplus1 = add nuw i32 %i, 1
   %var29 = icmp uge i32 %length.i, %i


        


More information about the llvm-commits mailing list