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

Zhu Siyuan via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed May 3 09:21:53 PDT 2023


floatshadow updated this revision to Diff 519114.
floatshadow added a comment.

rebase


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149510/new/

https://reviews.llvm.org/D149510

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


Index: llvm/test/Transforms/InstSimplify/implies.ll
===================================================================
--- llvm/test/Transforms/InstSimplify/implies.ll
+++ llvm/test/Transforms/InstSimplify/implies.ll
@@ -271,11 +271,7 @@
 ; 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 @@
 ; 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 @@
 ; 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 @@
 ; 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
Index: llvm/lib/Analysis/ValueTracking.cpp
===================================================================
--- llvm/lib/Analysis/ValueTracking.cpp
+++ llvm/lib/Analysis/ValueTracking.cpp
@@ -8144,12 +8144,26 @@
       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;
   }
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D149510.519114.patch
Type: text/x-patch
Size: 3385 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230503/219a60ef/attachment.bin>


More information about the llvm-commits mailing list