diff options
author | Nick Lewycky <nicholas@mxc.ca> | 2011-11-12 03:09:12 +0000 |
---|---|---|
committer | Nick Lewycky <nicholas@mxc.ca> | 2011-11-12 03:09:12 +0000 |
commit | d7ecff49d9190262da48a9f5815c01138fd54ebc (patch) | |
tree | d9d2d5c69a14a2744ae55a3dff0e79d70d61b39e /lib/Analysis | |
parent | 7386612a1635090acf010aaa4c7f68b181fcfe65 (diff) | |
download | external_llvm-d7ecff49d9190262da48a9f5815c01138fd54ebc.zip external_llvm-d7ecff49d9190262da48a9f5815c01138fd54ebc.tar.gz external_llvm-d7ecff49d9190262da48a9f5815c01138fd54ebc.tar.bz2 |
Don't try to loop on iterators that are potentially invalidated inside the loop. Fixes PR11361!
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@144454 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis')
-rw-r--r-- | lib/Analysis/ScalarEvolution.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/Analysis/ScalarEvolution.cpp b/lib/Analysis/ScalarEvolution.cpp index b940d93..ac00259 100644 --- a/lib/Analysis/ScalarEvolution.cpp +++ b/lib/Analysis/ScalarEvolution.cpp @@ -4853,10 +4853,18 @@ ScalarEvolution::getConstantEvolutionLoopExitValue(PHINode *PN, // Also evaluate the other PHI nodes. However, we don't get to stop if we // cease to be able to evaluate one of them or if they stop evolving, // because that doesn't necessarily prevent us from computing PN. + SmallVector<std::pair<PHINode *, Constant *>, 8> PHIsToCompute; for (DenseMap<Instruction *, Constant *>::const_iterator I = CurrentIterVals.begin(), E = CurrentIterVals.end(); I != E; ++I){ PHINode *PHI = dyn_cast<PHINode>(I->first); if (!PHI || PHI == PN || PHI->getParent() != Header) continue; + PHIsToCompute.push_back(std::make_pair(PHI, I->second)); + } + // We use two distinct loops because EvaluateExpression may invalidate any + // iterators into CurrentIterVals. + for (SmallVectorImpl<std::pair<PHINode *, Constant*> >::const_iterator + I = PHIsToCompute.begin(), E = PHIsToCompute.end(); I != E; ++I) { + PHINode *PHI = I->first; Constant *&NextPHI = NextIterVals[PHI]; if (!NextPHI) { // Not already computed. Value *BEValue = PHI->getIncomingValue(SecondIsBackedge); @@ -4928,10 +4936,20 @@ const SCEV *ScalarEvolution::ComputeExitCountExhaustively(const Loop *L, // Update all the PHI nodes for the next iteration. DenseMap<Instruction *, Constant *> NextIterVals; + + // Create a list of which PHIs we need to compute. We want to do this before + // calling EvaluateExpression on them because that may invalidate iterators + // into CurrentIterVals. + SmallVector<PHINode *, 8> PHIsToCompute; for (DenseMap<Instruction *, Constant *>::const_iterator I = CurrentIterVals.begin(), E = CurrentIterVals.end(); I != E; ++I){ PHINode *PHI = dyn_cast<PHINode>(I->first); if (!PHI || PHI->getParent() != Header) continue; + PHIsToCompute.push_back(PHI); + } + for (SmallVectorImpl<PHINode *>::const_iterator I = PHIsToCompute.begin(), + E = PHIsToCompute.end(); I != E; ++I) { + PHINode *PHI = *I; Constant *&NextPHI = NextIterVals[PHI]; if (NextPHI) continue; // Already computed! |