@@ -1292,8 +1292,7 @@ SCEVExpander::getAddRecExprPHILiterally(const SCEVAddRecExpr *Normalized,
1292
1292
if (useSubtract)
1293
1293
Step = SE.getNegativeSCEV (Step);
1294
1294
// Expand the step somewhere that dominates the loop header.
1295
- Value *StepV = expandCodeFor (Step, IntTy,
1296
- &*L->getHeader ()->getFirstInsertionPt ());
1295
+ Value *StepV = expandCodeFor (Step, IntTy, &L->getHeader ()->front ());
1297
1296
1298
1297
// The no-wrap behavior proved by IsIncrement(NUW|NSW) is only applicable if
1299
1298
// we actually do emit an addition. It does not apply if we emit a
@@ -1439,8 +1438,7 @@ Value *SCEVExpander::expandAddRecExprLiterally(const SCEVAddRecExpr *S) {
1439
1438
{
1440
1439
// Expand the step somewhere that dominates the loop header.
1441
1440
SCEVInsertPointGuard Guard (Builder, this );
1442
- StepV = expandCodeFor (Step, IntTy,
1443
- &*L->getHeader ()->getFirstInsertionPt ());
1441
+ StepV = expandCodeFor (Step, IntTy, &L->getHeader ()->front ());
1444
1442
}
1445
1443
Result = expandIVInc (PN, StepV, L, ExpandTy, IntTy, useSubtract);
1446
1444
}
@@ -1872,6 +1870,11 @@ Value *SCEVExpander::expand(const SCEV *S) {
1872
1870
}
1873
1871
}
1874
1872
1873
+ // IndVarSimplify sometimes sets the insertion point at the block start, even
1874
+ // when there are PHIs at that point. We must correct for this.
1875
+ if (isa<PHINode>(*InsertPt))
1876
+ InsertPt = &*InsertPt->getParent ()->getFirstInsertionPt ();
1877
+
1875
1878
// Check to see if we already expanded this here.
1876
1879
auto I = InsertedExpressions.find (std::make_pair (S, InsertPt));
1877
1880
if (I != InsertedExpressions.end ())
@@ -1942,8 +1945,7 @@ SCEVExpander::getOrInsertCanonicalInductionVariable(const Loop *L,
1942
1945
// Emit code for it.
1943
1946
SCEVInsertPointGuard Guard (Builder, this );
1944
1947
PHINode *V =
1945
- cast<PHINode>(expandCodeFor (H, nullptr ,
1946
- &*L->getHeader ()->getFirstInsertionPt ()));
1948
+ cast<PHINode>(expandCodeFor (H, nullptr , &L->getHeader ()->front ()));
1947
1949
1948
1950
return V;
1949
1951
}
0 commit comments