diff options
author | Sanjoy Das <sanjoy@playingwithpointers.com> | 2015-08-06 20:43:41 +0000 |
---|---|---|
committer | Sanjoy Das <sanjoy@playingwithpointers.com> | 2015-08-06 20:43:41 +0000 |
commit | 366acc175e49a6ebb7087a430a83ba17cc06211c (patch) | |
tree | 6046bc8a13bcc115119b94badf535fbabfd8169f /llvm/lib/Analysis/ScalarEvolution.cpp | |
parent | c18115db9c36fe70d1a9667d284138bd9a3f4998 (diff) | |
download | bcm5719-llvm-366acc175e49a6ebb7087a430a83ba17cc06211c.tar.gz bcm5719-llvm-366acc175e49a6ebb7087a430a83ba17cc06211c.zip |
[IndVars] Fix PR24356.
Unsigned predicates increase or decrease agnostic of the signs of their
increments.
llvm-svn: 244265
Diffstat (limited to 'llvm/lib/Analysis/ScalarEvolution.cpp')
-rw-r--r-- | llvm/lib/Analysis/ScalarEvolution.cpp | 66 |
1 files changed, 30 insertions, 36 deletions
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp index 73f0dc1e44c..3e3032b48fe 100644 --- a/llvm/lib/Analysis/ScalarEvolution.cpp +++ b/llvm/lib/Analysis/ScalarEvolution.cpp @@ -6721,8 +6721,16 @@ bool ScalarEvolution::isMonotonicPredicate(const SCEVAddRecExpr *LHS, bool ScalarEvolution::isMonotonicPredicateImpl(const SCEVAddRecExpr *LHS, ICmpInst::Predicate Pred, bool &Increasing) { - SCEV::NoWrapFlags FlagsRequired = SCEV::FlagAnyWrap; - bool IncreasingOnNonNegativeStep = false; + + // A zero step value for LHS means the induction variable is essentially a + // loop invariant value. We don't really depend on the predicate actually + // flipping from false to true (for increasing predicates, and the other way + // around for decreasing predicates), all we care about is that *if* the + // predicate changes then it only changes from false to true. + // + // A zero step value in itself is not very useful, but there may be places + // where SCEV can prove X >= 0 but not prove X > 0, so it is helpful to be + // as general as possible. switch (Pred) { default: @@ -6730,53 +6738,39 @@ bool ScalarEvolution::isMonotonicPredicateImpl(const SCEVAddRecExpr *LHS, case ICmpInst::ICMP_UGT: case ICmpInst::ICMP_UGE: - FlagsRequired = SCEV::FlagNUW; - IncreasingOnNonNegativeStep = true; - break; - case ICmpInst::ICMP_ULT: case ICmpInst::ICMP_ULE: - FlagsRequired = SCEV::FlagNUW; - IncreasingOnNonNegativeStep = false; - break; + if (!LHS->getNoWrapFlags(SCEV::FlagNUW)) + return false; + + Increasing = Pred == ICmpInst::ICMP_UGT || Pred == ICmpInst::ICMP_UGE; + return true; case ICmpInst::ICMP_SGT: case ICmpInst::ICMP_SGE: - FlagsRequired = SCEV::FlagNSW; - IncreasingOnNonNegativeStep = true; - break; - case ICmpInst::ICMP_SLT: - case ICmpInst::ICMP_SLE: - FlagsRequired = SCEV::FlagNSW; - IncreasingOnNonNegativeStep = false; - break; - } + case ICmpInst::ICMP_SLE: { + if (!LHS->getNoWrapFlags(SCEV::FlagNSW)) + return false; - if (!LHS->getNoWrapFlags(FlagsRequired)) - return false; + const SCEV *Step = LHS->getStepRecurrence(*this); - // A zero step value for LHS means the induction variable is essentially a - // loop invariant value. We don't really depend on the predicate actually - // flipping from false to true (for increasing predicates, and the other way - // around for decreasing predicates), all we care about is that *if* the - // predicate changes then it only changes from false to true. - // - // A zero step value in itself is not very useful, but there may be places - // where SCEV can prove X >= 0 but not prove X > 0, so it is helpful to be - // as general as possible. + if (isKnownNonNegative(Step)) { + Increasing = Pred == ICmpInst::ICMP_SGT || Pred == ICmpInst::ICMP_SGE; + return true; + } - if (isKnownNonNegative(LHS->getStepRecurrence(*this))) { - Increasing = IncreasingOnNonNegativeStep; - return true; + if (isKnownNonPositive(Step)) { + Increasing = Pred == ICmpInst::ICMP_SLT || Pred == ICmpInst::ICMP_SLE; + return true; + } + + return false; } - if (isKnownNonPositive(LHS->getStepRecurrence(*this))) { - Increasing = !IncreasingOnNonNegativeStep; - return true; } - return false; + llvm_unreachable("switch has default clause!"); } bool ScalarEvolution::isLoopInvariantPredicate( |