diff options
| author | Nick Lewycky <nicholas@mxc.ca> | 2011-10-24 21:02:38 +0000 |
|---|---|---|
| committer | Nick Lewycky <nicholas@mxc.ca> | 2011-10-24 21:02:38 +0000 |
| commit | a58fb48a5596d7cc6decebbbb845f3a47e5649b5 (patch) | |
| tree | 5084714cd6d99084a26442b9fe1032922d06bf14 /llvm/lib/Analysis | |
| parent | b72d55353a67fbf6df4584dc1472dbe9da6a68f2 (diff) | |
| download | bcm5719-llvm-a58fb48a5596d7cc6decebbbb845f3a47e5649b5.tar.gz bcm5719-llvm-a58fb48a5596d7cc6decebbbb845f3a47e5649b5.zip | |
Now that we look at all the header PHIs, we need to consider all the header PHIs
when deciding that the loop has stopped evolving. Fixes miscompile in the gcc
torture testsuite!
llvm-svn: 142843
Diffstat (limited to 'llvm/lib/Analysis')
| -rw-r--r-- | llvm/lib/Analysis/ScalarEvolution.cpp | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp index 1ab6a406fce..f65cf343355 100644 --- a/llvm/lib/Analysis/ScalarEvolution.cpp +++ b/llvm/lib/Analysis/ScalarEvolution.cpp @@ -4844,12 +4844,12 @@ ScalarEvolution::getConstantEvolutionLoopExitValue(PHINode *PN, // EvaluateExpression adds non-phi values to the CurrentIterVals map. DenseMap<Instruction *, Constant *> NextIterVals; Constant *NextPHI = EvaluateExpression(BEValue, L, CurrentIterVals, TD); - if (NextPHI == CurrentIterVals[PN]) - return RetVal = NextPHI; // Stopped evolving! if (NextPHI == 0) return 0; // Couldn't evaluate! NextIterVals[PN] = NextPHI; + bool StoppedEvolving = NextPHI == CurrentIterVals[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. @@ -4858,11 +4858,19 @@ ScalarEvolution::getConstantEvolutionLoopExitValue(PHINode *PN, PHINode *PHI = dyn_cast<PHINode>(I->first); if (!PHI || PHI == PN || PHI->getParent() != Header) continue; Constant *&NextPHI = NextIterVals[PHI]; - if (NextPHI) continue; // Already computed! - - Value *BEValue = PHI->getIncomingValue(SecondIsBackedge); - NextPHI = EvaluateExpression(BEValue, L, CurrentIterVals, TD); + if (!NextPHI) { // Not already computed. + Value *BEValue = PHI->getIncomingValue(SecondIsBackedge); + NextPHI = EvaluateExpression(BEValue, L, CurrentIterVals, TD); + } + if (NextPHI != I->second) + StoppedEvolving = false; } + + // If all entries in CurrentIterVals == NextIterVals then we can stop + // iterating, the loop can't continue to change. + if (StoppedEvolving) + return RetVal = CurrentIterVals[PN]; + CurrentIterVals.swap(NextIterVals); } } |

