summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Analysis/ScalarEvolutionExpander.cpp
diff options
context:
space:
mode:
authorWojciech Matyjewicz <wmatyjewicz@fastmail.fm>2008-06-14 16:48:22 +0000
committerWojciech Matyjewicz <wmatyjewicz@fastmail.fm>2008-06-14 16:48:22 +0000
commit8bf66ee13b1fd728f24cc6bbd9eb25700be99806 (patch)
treee7878b526433cc56d52e18962239251c5e54e26e /llvm/lib/Analysis/ScalarEvolutionExpander.cpp
parentf88d50bfccf06b9032e4e5b4d4a2af5b91540348 (diff)
downloadbcm5719-llvm-8bf66ee13b1fd728f24cc6bbd9eb25700be99806.tar.gz
bcm5719-llvm-8bf66ee13b1fd728f24cc6bbd9eb25700be99806.zip
Change 'while' loop to 'do' loop.
Add a safety measure. It isn't safe to assume in ScalarEvolutionExpander that all loops are in canonical form (but it should be safe for loops that have AddRecs). xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx llvm-svn: 52275
Diffstat (limited to 'llvm/lib/Analysis/ScalarEvolutionExpander.cpp')
-rw-r--r--llvm/lib/Analysis/ScalarEvolutionExpander.cpp15
1 files changed, 11 insertions, 4 deletions
diff --git a/llvm/lib/Analysis/ScalarEvolutionExpander.cpp b/llvm/lib/Analysis/ScalarEvolutionExpander.cpp
index e249421a1f3..a241960b374 100644
--- a/llvm/lib/Analysis/ScalarEvolutionExpander.cpp
+++ b/llvm/lib/Analysis/ScalarEvolutionExpander.cpp
@@ -185,14 +185,21 @@ Value *SCEVExpander::visitAddRecExpr(SCEVAddRecExpr *S) {
Loop *InsertPtLoop = LI.getLoopFor(MulInsertPt->getParent());
if (InsertPtLoop != L && InsertPtLoop &&
L->contains(InsertPtLoop->getHeader())) {
- while (InsertPtLoop != L) {
+ do {
// If we cannot hoist the multiply out of this loop, don't.
if (!InsertPtLoop->isLoopInvariant(F)) break;
- // Otherwise, move the insert point to the preheader of the loop.
- MulInsertPt = InsertPtLoop->getLoopPreheader()->getTerminator();
+ BasicBlock *InsertPtLoopPH = InsertPtLoop->getLoopPreheader();
+
+ // If this loop hasn't got a preheader, we aren't able to hoist the
+ // multiply.
+ if (!InsertPtLoopPH)
+ break;
+
+ // Otherwise, move the insert point to the preheader.
+ MulInsertPt = InsertPtLoopPH->getTerminator();
InsertPtLoop = InsertPtLoop->getParentLoop();
- }
+ } while (InsertPtLoop != L);
}
return InsertBinop(Instruction::Mul, I, F, MulInsertPt);
OpenPOWER on IntegriCloud