[SCEV][NFC] Use general predicate checkers in monotonicity check
authorMax Kazantsev <mkazantsev@azul.com>
Thu, 29 Oct 2020 09:29:45 +0000 (16:29 +0700)
committerMax Kazantsev <mkazantsev@azul.com>
Thu, 29 Oct 2020 09:45:52 +0000 (16:45 +0700)
This makes the code more compact and readable.

llvm/lib/Analysis/ScalarEvolution.cpp

index 8bc2595..ec39180 100644 (file)
@@ -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(