summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSanjoy Das <sanjoy@playingwithpointers.com>2016-12-11 19:02:21 +0000
committerSanjoy Das <sanjoy@playingwithpointers.com>2016-12-11 19:02:21 +0000
commitba1bf875869251328408e98567053528ff79cff7 (patch)
tree36b589cc096b95cd00f49d383d245a018acc5551
parent9683ecbff6c83ee2181e3bc463bfe1553c7388c6 (diff)
downloadbcm5719-llvm-ba1bf875869251328408e98567053528ff79cff7.tar.gz
bcm5719-llvm-ba1bf875869251328408e98567053528ff79cff7.zip
[SCEVExpander] Explicitly expand AddRec starts into loop preheader
This is NFC today, but won't be once D27216 (or an equivalent patch) is in. This change fixes a design problem in SCEVExpander -- it relied on a hoisting optimization to generate correct code for add recurrences. This meant changing the hoisting optimization to not kick in under certain circumstances (to avoid speculating faulting instructions, say) would break correctness. The fix is to make the correctness requirements explicit, and have it not rely on the hoisting optimization for correctness. llvm-svn: 289397
-rw-r--r--llvm/lib/Analysis/ScalarEvolutionExpander.cpp13
1 files changed, 8 insertions, 5 deletions
diff --git a/llvm/lib/Analysis/ScalarEvolutionExpander.cpp b/llvm/lib/Analysis/ScalarEvolutionExpander.cpp
index 5217c4dc22a..d15a7dbd20e 100644
--- a/llvm/lib/Analysis/ScalarEvolutionExpander.cpp
+++ b/llvm/lib/Analysis/ScalarEvolutionExpander.cpp
@@ -1182,11 +1182,14 @@ SCEVExpander::getAddRecExprPHILiterally(const SCEVAddRecExpr *Normalized,
PostIncLoopSet SavedPostIncLoops = PostIncLoops;
PostIncLoops.clear();
- // Expand code for the start value.
- Value *StartV =
- expandCodeFor(Normalized->getStart(), ExpandTy, &L->getHeader()->front());
-
- // StartV must be hoisted into L's preheader to dominate the new phi.
+ // Expand code for the start value into the loop preheader.
+ assert(L->getLoopPreheader() &&
+ "Can't expand add recurrences without a loop preheader!");
+ Value *StartV = expandCodeFor(Normalized->getStart(), ExpandTy,
+ L->getLoopPreheader()->getTerminator());
+
+ // StartV must have been be inserted into L's preheader to dominate the new
+ // phi.
assert(!isa<Instruction>(StartV) ||
SE.DT.properlyDominates(cast<Instruction>(StartV)->getParent(),
L->getHeader()));
OpenPOWER on IntegriCloud