diff options
author | Serguei Katkov <serguei.katkov@azul.com> | 2018-02-05 05:49:47 +0000 |
---|---|---|
committer | Serguei Katkov <serguei.katkov@azul.com> | 2018-02-05 05:49:47 +0000 |
commit | ec7029c286c6a8e49db52c752d87c9ff0a465996 (patch) | |
tree | 5d110a63275ed8cbba83a56249ee9facec9f2f1d /llvm/lib/Analysis | |
parent | 0923542c61cdbaa255c4336575c4b21d0c6779e8 (diff) | |
download | bcm5719-llvm-ec7029c286c6a8e49db52c752d87c9ff0a465996.tar.gz bcm5719-llvm-ec7029c286c6a8e49db52c752d87c9ff0a465996.zip |
Re-apply [SCEV] Fix isLoopEntryGuardedByCond usage
ScalarEvolution::isKnownPredicate invokes isLoopEntryGuardedByCond without check
that SCEV is available at entry point of the loop. It is incorrect and fixed by patch.
To bugs additionally fixed:
assert is moved after the check whether loop is not a nullptr.
Usage of isLoopEntryGuardedByCond in ScalarEvolution::isImpliedCondOperandsViaNoOverflow
is guarded by isAvailableAtLoopEntry.
Reviewers: sanjoy, mkazantsev, anna, dorit, reames
Reviewed By: mkazantsev
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D42417
llvm-svn: 324204
Diffstat (limited to 'llvm/lib/Analysis')
-rw-r--r-- | llvm/lib/Analysis/ScalarEvolution.cpp | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp index 7a9fddfd10b..f44bb8d447e 100644 --- a/llvm/lib/Analysis/ScalarEvolution.cpp +++ b/llvm/lib/Analysis/ScalarEvolution.cpp @@ -8669,7 +8669,8 @@ bool ScalarEvolution::isKnownPredicate(ICmpInst::Predicate Pred, bool RightGuarded = false; if (LAR) { const Loop *L = LAR->getLoop(); - if (isLoopEntryGuardedByCond(L, Pred, LAR->getStart(), RHS) && + if (isAvailableAtLoopEntry(RHS, L) && + isLoopEntryGuardedByCond(L, Pred, LAR->getStart(), RHS) && isLoopBackedgeGuardedByCond(L, Pred, LAR->getPostIncExpr(*this), RHS)) { if (!RAR) return true; LeftGuarded = true; @@ -8677,7 +8678,8 @@ bool ScalarEvolution::isKnownPredicate(ICmpInst::Predicate Pred, } if (RAR) { const Loop *L = RAR->getLoop(); - if (isLoopEntryGuardedByCond(L, Pred, LHS, RAR->getStart()) && + if (isAvailableAtLoopEntry(LHS, L) && + isLoopEntryGuardedByCond(L, Pred, LHS, RAR->getStart()) && isLoopBackedgeGuardedByCond(L, Pred, LHS, RAR->getPostIncExpr(*this))) { if (!LAR) return true; RightGuarded = true; @@ -9062,6 +9064,12 @@ ScalarEvolution::isLoopEntryGuardedByCond(const Loop *L, // (interprocedural conditions notwithstanding). if (!L) return false; + // Both LHS and RHS must be available at loop entry. + assert(isAvailableAtLoopEntry(LHS, L) && + "LHS is not available at Loop Entry"); + assert(isAvailableAtLoopEntry(RHS, L) && + "RHS is not available at Loop Entry"); + if (isKnownPredicateViaConstantRanges(Pred, LHS, RHS)) return true; @@ -9418,7 +9426,8 @@ bool ScalarEvolution::isImpliedCondOperandsViaNoOverflow( } // Try to prove (1) or (2), as needed. - return isLoopEntryGuardedByCond(L, Pred, FoundRHS, + return isAvailableAtLoopEntry(FoundRHS, L) && + isLoopEntryGuardedByCond(L, Pred, FoundRHS, getConstant(FoundRHSLimit)); } |