[llvm] ef129f0 - [SCEV][NFC] Use general predicate checkers in monotonicity check

Max Kazantsev via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 29 02:46:16 PDT 2020


Author: Max Kazantsev
Date: 2020-10-29T16:45:52+07:00
New Revision: ef129f01e9053871fdf97ad48dd26857d3af925d

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

LOG: [SCEV][NFC] Use general predicate checkers in monotonicity check

This makes the code more compact and readable.

Added: 
    

Modified: 
    llvm/lib/Analysis/ScalarEvolution.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index 8bc2595d5261..ec39180cec39 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -9270,25 +9270,20 @@ ScalarEvolution::getMonotonicPredicateTypeImpl(const SCEVAddRecExpr *LHS,
   // where SCEV can prove X >= 0 but not prove X > 0, so it is helpful to be
   // as general as possible.
 
-  switch (Pred) {
-  default:
-    return None; // Conservative answer
+  // Only handle LE/LT/GE/GT predicates.
+  if (!ICmpInst::isRelational(Pred))
+    return None;
 
-  case ICmpInst::ICMP_UGT:
-  case ICmpInst::ICMP_UGE:
-  case ICmpInst::ICMP_ULT:
-  case ICmpInst::ICMP_ULE:
+  // Check that AR does not wrap.
+  if (ICmpInst::isUnsigned(Pred)) {
     if (!LHS->hasNoUnsignedWrap())
       return None;
-
     return Pred == ICmpInst::ICMP_UGT || Pred == ICmpInst::ICMP_UGE
                ? MonotonicallyIncreasing
                : MonotonicallyDecreasing;
-
-  case ICmpInst::ICMP_SGT:
-  case ICmpInst::ICMP_SGE:
-  case ICmpInst::ICMP_SLT:
-  case ICmpInst::ICMP_SLE: {
+  } else {
+    assert(ICmpInst::isSigned(Pred) &&
+           "Relational predicate is either signed or unsigned!");
     if (!LHS->hasNoSignedWrap())
       return None;
 
@@ -9308,10 +9303,6 @@ ScalarEvolution::getMonotonicPredicateTypeImpl(const SCEVAddRecExpr *LHS,
 
     return None;
   }
-
-  }
-
-  llvm_unreachable("switch has default clause!");
 }
 
 bool ScalarEvolution::isLoopInvariantPredicate(


        


More information about the llvm-commits mailing list