From ba1bf875869251328408e98567053528ff79cff7 Mon Sep 17 00:00:00 2001 From: Sanjoy Das Date: Sun, 11 Dec 2016 19:02:21 +0000 Subject: [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 --- llvm/lib/Analysis/ScalarEvolutionExpander.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'llvm/lib/Analysis') 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(StartV) || SE.DT.properlyDominates(cast(StartV)->getParent(), L->getHeader())); -- cgit v1.2.3