diff options
author | Sanjoy Das <sanjoy@playingwithpointers.com> | 2016-06-09 01:13:54 +0000 |
---|---|---|
committer | Sanjoy Das <sanjoy@playingwithpointers.com> | 2016-06-09 01:13:54 +0000 |
commit | 97cd7d5d44b60df7fc4a8dffb0a7d7d8d128aee2 (patch) | |
tree | 02577b5612955199cc5426c943459a0819ee541e | |
parent | 22252f98477ce1c30170815c12cf0fb53347d065 (diff) | |
download | llvm-97cd7d5d44b60df7fc4a8dffb0a7d7d8d128aee2.zip llvm-97cd7d5d44b60df7fc4a8dffb0a7d7d8d128aee2.tar.gz llvm-97cd7d5d44b60df7fc4a8dffb0a7d7d8d128aee2.tar.bz2 |
Factor out a loopHasNoAbnormalExits; NFC
llvm-svn: 272236
-rw-r--r-- | llvm/include/llvm/Analysis/ScalarEvolution.h | 16 | ||||
-rw-r--r-- | llvm/lib/Analysis/ScalarEvolution.cpp | 17 |
2 files changed, 17 insertions, 16 deletions
diff --git a/llvm/include/llvm/Analysis/ScalarEvolution.h b/llvm/include/llvm/Analysis/ScalarEvolution.h index 408d123..535b623 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 7a6bc3a7..9278aa0 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) { |