[llvm] e2703c0 - [SCEV] Handle `less` predicates for FoundPred = NE

Max Kazantsev via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 22 04:56:59 PDT 2020


Author: Max Kazantsev
Date: 2020-09-22T18:56:35+07:00
New Revision: e2703c021d844ea0e5c1b203a4bd534e7a231997

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

LOG: [SCEV] Handle `less` predicates for FoundPred = NE

Currently these predicates are ignored, yet their handling is
pretty simple. I could not find a single test where it would
actually change something, but it's only because isImpliedCondOperands
is not smart enough to prove it further on. Yet the situation when
we come there with `less` predicate is pretty common.

Differential Revision: https://reviews.llvm.org/D87890
Reviewed By: fhahn

Added: 
    

Modified: 
    llvm/lib/Analysis/ScalarEvolution.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index 39bccecd678c..a26eab121009 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -9758,8 +9758,23 @@ bool ScalarEvolution::isImpliedCond(ICmpInst::Predicate Pred, const SCEV *LHS,
 
           if (isImpliedCondOperands(Pred, LHS, RHS, V, getConstant(Min)))
             return true;
+          break;
+
+        // `LHS < RHS` and `LHS <= RHS` are handled in the same way as `RHS > LHS` and `RHS >= LHS` respectively.
+        case ICmpInst::ICMP_SLE:
+        case ICmpInst::ICMP_ULE:
+          if (isImpliedCondOperands(CmpInst::getSwappedPredicate(Pred), RHS,
+                                    LHS, V, getConstant(SharperMin)))
+            return true;
           LLVM_FALLTHROUGH;
 
+        case ICmpInst::ICMP_SLT:
+        case ICmpInst::ICMP_ULT:
+          if (isImpliedCondOperands(CmpInst::getSwappedPredicate(Pred), RHS,
+                                    LHS, V, getConstant(Min)))
+            return true;
+          break;
+
         default:
           // No change
           break;


        


More information about the llvm-commits mailing list