[PATCH] D149510: [ValueTracking] add UGT/UGE and lshr case in imply icmp

Zhu Siyuan via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Apr 29 10:40:02 PDT 2023


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

address comments


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
@@ -273,9 +273,8 @@
 ; CHECK-LABEL: @test_shift(
 ; CHECK-NEXT:    [[LSHR:%.*]] = lshr i64 [[X:%.*]], [[SHIFT:%.*]]
 ; CHECK-NEXT:    [[ICMP1:%.*]] = icmp ugt i64 [[LSHR]], [[Y:%.*]]
-; CHECK-NEXT:    [[ICMP2:%.*]] = icmp ugt i64 [[X]], [[Y]]
 ; CHECK-NEXT:    call void @llvm.assume(i1 [[ICMP1]])
-; CHECK-NEXT:    ret i1 [[ICMP2]]
+; CHECK-NEXT:    ret i1 true
 ;
   %lshr = lshr i64 %x, %shift
   %icmp1 = icmp ugt i64 %lshr, %y
Index: llvm/lib/Analysis/ValueTracking.cpp
===================================================================
--- llvm/lib/Analysis/ValueTracking.cpp
+++ llvm/lib/Analysis/ValueTracking.cpp
@@ -7939,6 +7939,10 @@
     if (match(RHS, m_NUWAdd(m_Specific(LHS), m_APInt(C))))
       return true;
 
+    // (RHS >> X) u<= RHS      for any X
+    if (match(LHS, m_LShr(m_Specific(RHS), m_Value())))
+      return true;
+
     // Match A to (X +_{nuw} CA) and B to (X +_{nuw} CB)
     auto MatchNUWAddsToSameValue = [&](const Value *A, const Value *B,
                                        const Value *&X,
@@ -7993,6 +7997,13 @@
         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.518193.patch
Type: text/x-patch
Size: 1641 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230429/4efc3e5e/attachment.bin>


More information about the llvm-commits mailing list