[llvm] r289397 - [SCEVExpander] Explicitly expand AddRec starts into loop preheader
Sanjoy Das via llvm-commits
llvm-commits at lists.llvm.org
Sun Dec 11 11:02:22 PST 2016
Author: sanjoy
Date: Sun Dec 11 13:02:21 2016
New Revision: 289397
URL: http://llvm.org/viewvc/llvm-project?rev=289397&view=rev
Log:
[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.
Modified:
llvm/trunk/lib/Analysis/ScalarEvolutionExpander.cpp
Modified: llvm/trunk/lib/Analysis/ScalarEvolutionExpander.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ScalarEvolutionExpander.cpp?rev=289397&r1=289396&r2=289397&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ScalarEvolutionExpander.cpp (original)
+++ llvm/trunk/lib/Analysis/ScalarEvolutionExpander.cpp Sun Dec 11 13:02:21 2016
@@ -1182,11 +1182,14 @@ SCEVExpander::getAddRecExprPHILiterally(
PostIncLoopSet SavedPostIncLoops = PostIncLoops;
PostIncLoops.clear();
- // Expand code for the start value.
- Value *StartV =
- expandCodeFor(Normalized->getStart(), ExpandTy, &L->getHeader()->front());
+ // 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 be hoisted into L's preheader to dominate the new phi.
+ // 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()));
More information about the llvm-commits
mailing list