summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/include/llvm/Analysis/ScalarEvolution.h16
-rw-r--r--llvm/lib/Analysis/ScalarEvolution.cpp17
2 files changed, 17 insertions, 16 deletions
diff --git a/llvm/include/llvm/Analysis/ScalarEvolution.h b/llvm/include/llvm/Analysis/ScalarEvolution.h
index 408d1233412..535b623d31a 100644
--- a/llvm/include/llvm/Analysis/ScalarEvolution.h
+++ b/llvm/include/llvm/Analysis/ScalarEvolution.h
@@ -781,13 +781,15 @@ namespace llvm {
SmallVector<PointerIntPair<const Loop *, 2, LoopDisposition>, 2>>
LoopDispositions;
- /// A cache of the predicate "does the given loop contain an instruction
- /// that can abnormally exit the loop (i.e. via throwing an exception, by
- /// terminating the thread cleanly or by infinite looping in a called
- /// function)?" The last one is strictly not leaving the loop, but is
- /// identical to leaving the loop from the viewpoint of reasoning about
- /// undefined behavior.
- DenseMap<const Loop *, bool> LoopHasAbnormalExit;
+ /// Cache for \c loopHasNoAbnormalExits.
+ DenseMap<const Loop *, bool> LoopHasNoAbnormalExits;
+
+ /// Returns true if \p L contains no instruction that can abnormally exit
+ /// the loop (i.e. via throwing an exception, by terminating the thread
+ /// cleanly or by infinite looping in a called function). Strictly
+ /// speaking, the last one is not leaving the loop, but is identical to
+ /// leaving the loop for reasoning about undefined behavior.
+ bool loopHasNoAbnormalExits(const Loop *L);
/// Compute a LoopDisposition value.
LoopDisposition computeLoopDisposition(const SCEV *S, const Loop *L);
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index 7a6bc3a7637..9278aa05dcb 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -4906,13 +4906,12 @@ bool ScalarEvolution::isAddRecNeverPoison(const Instruction *I, const Loop *L) {
}
}
- if (!LatchControlDependentOnPoison)
- return false;
-
- // Now check if loop has abonormal exits (or not), and cache the information.
+ return LatchControlDependentOnPoison && loopHasNoAbnormalExits(L);
+}
- auto Itr = LoopHasAbnormalExit.find(L);
- if (Itr == LoopHasAbnormalExit.end()) {
+bool ScalarEvolution::loopHasNoAbnormalExits(const Loop *L) {
+ auto Itr = LoopHasNoAbnormalExits.find(L);
+ if (Itr == LoopHasNoAbnormalExits.end()) {
bool HasAbnormalExit = false;
for (auto *BB : L->getBlocks()) {
HasAbnormalExit = any_of(*BB, [](Instruction &I) {
@@ -4921,12 +4920,12 @@ bool ScalarEvolution::isAddRecNeverPoison(const Instruction *I, const Loop *L) {
if (HasAbnormalExit)
break;
}
- auto InsertPair = LoopHasAbnormalExit.insert({L, HasAbnormalExit});
+ auto InsertPair = LoopHasNoAbnormalExits.insert({L, !HasAbnormalExit});
assert(InsertPair.second && "We just checked!");
Itr = InsertPair.first;
}
- return !Itr->second;
+ return Itr->second;
}
const SCEV *ScalarEvolution::createSCEV(Value *V) {
@@ -5490,7 +5489,7 @@ void ScalarEvolution::forgetLoop(const Loop *L) {
for (Loop::iterator I = L->begin(), E = L->end(); I != E; ++I)
forgetLoop(*I);
- LoopHasAbnormalExit.erase(L);
+ LoopHasNoAbnormalExits.erase(L);
}
void ScalarEvolution::forgetValue(Value *V) {
OpenPOWER on IntegriCloud