Skip to content

Commit 1cd1c1d

Browse files
author
serge-sans-paille
committed
Revert "[SCEV][IndVarSimplify] insert point should not be block front."
This reverts commit f1efb8b. Reverted because it doesn't correctly update the pass return status, see http://lab.llvm.org:8011/builders/llvm-clang-x86_64-expensive-checks-debian/builds/9441/steps/test-check-all/logs/FAIL%3A%20LLVM%3A%3Awiden-i32-i8ptr.ll
1 parent 6f51cee commit 1cd1c1d

File tree

3 files changed

+10
-36
lines changed

3 files changed

+10
-36
lines changed

llvm/lib/Transforms/Scalar/IndVarSimplify.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1435,12 +1435,8 @@ PHINode *WidenIV::createWideIV(SCEVExpander &Rewriter) {
14351435
// either find an existing phi or materialize a new one. Either way, we
14361436
// expect a well-formed cyclic phi-with-increments. i.e. any operand not part
14371437
// of the phi-SCC dominates the loop entry.
1438-
Instruction *InsertPt = &*L->getHeader()->getFirstInsertionPt();
1439-
WidePhi = dyn_cast<PHINode>(Rewriter.expandCodeFor(AddRec, WideType, InsertPt));
1440-
// If the wide phi is not a phi node, for example a cast node, like bitcast,
1441-
// inttoptr, ptrtoint, just skip for now.
1442-
if (!WidePhi)
1443-
return nullptr;
1438+
Instruction *InsertPt = &L->getHeader()->front();
1439+
WidePhi = cast<PHINode>(Rewriter.expandCodeFor(AddRec, WideType, InsertPt));
14441440

14451441
// Remembering the WideIV increment generated by SCEVExpander allows
14461442
// widenIVUse to reuse it when widening the narrow IV's increment. We don't

llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1292,8 +1292,7 @@ SCEVExpander::getAddRecExprPHILiterally(const SCEVAddRecExpr *Normalized,
12921292
if (useSubtract)
12931293
Step = SE.getNegativeSCEV(Step);
12941294
// 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());
12971296

12981297
// The no-wrap behavior proved by IsIncrement(NUW|NSW) is only applicable if
12991298
// we actually do emit an addition. It does not apply if we emit a
@@ -1439,8 +1438,7 @@ Value *SCEVExpander::expandAddRecExprLiterally(const SCEVAddRecExpr *S) {
14391438
{
14401439
// Expand the step somewhere that dominates the loop header.
14411440
SCEVInsertPointGuard Guard(Builder, this);
1442-
StepV = expandCodeFor(Step, IntTy,
1443-
&*L->getHeader()->getFirstInsertionPt());
1441+
StepV = expandCodeFor(Step, IntTy, &L->getHeader()->front());
14441442
}
14451443
Result = expandIVInc(PN, StepV, L, ExpandTy, IntTy, useSubtract);
14461444
}
@@ -1872,6 +1870,11 @@ Value *SCEVExpander::expand(const SCEV *S) {
18721870
}
18731871
}
18741872

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+
18751878
// Check to see if we already expanded this here.
18761879
auto I = InsertedExpressions.find(std::make_pair(S, InsertPt));
18771880
if (I != InsertedExpressions.end())
@@ -1942,8 +1945,7 @@ SCEVExpander::getOrInsertCanonicalInductionVariable(const Loop *L,
19421945
// Emit code for it.
19431946
SCEVInsertPointGuard Guard(Builder, this);
19441947
PHINode *V =
1945-
cast<PHINode>(expandCodeFor(H, nullptr,
1946-
&*L->getHeader()->getFirstInsertionPt()));
1948+
cast<PHINode>(expandCodeFor(H, nullptr, &L->getHeader()->front()));
19471949

19481950
return V;
19491951
}

llvm/test/Transforms/IndVarSimplify/widen-i32-i8ptr.ll

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)