[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 04:55:16 PDT 2023


floatshadow updated this revision to Diff 519032.
floatshadow retitled this revision from "[ValueTracking] add UGT/UGE and lshr case in imply icmp" to "[ValueTracking] add UGT/UGE and SGT/SGE in `isImpliedCondOperands`".
floatshadow edited the summary of this revision.
floatshadow added a comment.

split the patch


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
@@ -270,11 +270,7 @@
 
 define i1 @test_sgt(i32 %length.i, i32 %i) {
 ; CHECK-LABEL: @test_sgt(
-; 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
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.519032.patch
Type: text/x-patch
Size: 1709 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230503/d333a185/attachment.bin>


More information about the llvm-commits mailing list