mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-09-28 07:17:32 +00:00
LSR: fix IVUsers isSimplifiedLoopNest to perform a full domtree walk
instead of skipping the current loop. My prior fix was incomplete because of an overzealous compile-time optimization: Better fix for: <rdar://problem/11049788> Segmentation fault: 11 in LoopStrengthReduce git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@153131 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -79,22 +79,31 @@ static bool isInteresting(const SCEV *S, const Instruction *I, const Loop *L,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return true if this loop and all loop headers that dominate it are in
|
/// Return true if all loop headers that dominate this block are in simplified
|
||||||
/// simplified form.
|
/// form.
|
||||||
static bool isSimplifiedLoopNest(Loop *L, const DominatorTree *DT,
|
static bool isSimplifiedLoopNest(BasicBlock *BB, const DominatorTree *DT,
|
||||||
const LoopInfo *LI) {
|
const LoopInfo *LI,
|
||||||
if (!L->isLoopSimplifyForm())
|
SmallPtrSet<Loop*,16> &SimpleLoopNests) {
|
||||||
return false;
|
Loop *NearestLoop = 0;
|
||||||
|
for (DomTreeNode *Rung = DT->getNode(BB);
|
||||||
for (DomTreeNode *Rung = DT->getNode(L->getLoopPreheader());
|
|
||||||
Rung; Rung = Rung->getIDom()) {
|
Rung; Rung = Rung->getIDom()) {
|
||||||
BasicBlock *BB = Rung->getBlock();
|
BasicBlock *DomBB = Rung->getBlock();
|
||||||
const Loop *DomLoop = LI->getLoopFor(BB);
|
Loop *DomLoop = LI->getLoopFor(DomBB);
|
||||||
if (DomLoop && DomLoop->getHeader() == BB) {
|
if (DomLoop && DomLoop->getHeader() == DomBB) {
|
||||||
|
// If the domtree walk reaches a loop with no preheader, return false.
|
||||||
if (!DomLoop->isLoopSimplifyForm())
|
if (!DomLoop->isLoopSimplifyForm())
|
||||||
return false;
|
return false;
|
||||||
|
// If we have already checked this loop nest, stop checking.
|
||||||
|
if (SimpleLoopNests.count(DomLoop))
|
||||||
|
break;
|
||||||
|
// If we have not already checked this loop nest, remember the loop
|
||||||
|
// header nearest to BB. The nearest loop may not contain BB.
|
||||||
|
if (!NearestLoop)
|
||||||
|
NearestLoop = DomLoop;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (NearestLoop)
|
||||||
|
SimpleLoopNests.insert(NearestLoop);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,15 +146,10 @@ bool IVUsers::AddUsersIfInteresting(Instruction *I,
|
|||||||
if (isa<PHINode>(User) && Processed.count(User))
|
if (isa<PHINode>(User) && Processed.count(User))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Loop *UserLoop = LI->getLoopFor(User->getParent());
|
|
||||||
|
|
||||||
// Only consider IVUsers that are dominated by simplified loop
|
// Only consider IVUsers that are dominated by simplified loop
|
||||||
// headers. Otherwise, SCEVExpander will crash.
|
// headers. Otherwise, SCEVExpander will crash.
|
||||||
if (UserLoop && !SimpleLoopNests.count(UserLoop)) {
|
if (!isSimplifiedLoopNest(User->getParent(), DT, LI, SimpleLoopNests))
|
||||||
if (!isSimplifiedLoopNest(UserLoop, DT, LI))
|
|
||||||
return false;
|
return false;
|
||||||
SimpleLoopNests.insert(UserLoop);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Descend recursively, but not into PHI nodes outside the current loop.
|
// Descend recursively, but not into PHI nodes outside the current loop.
|
||||||
// It's important to see the entire expression outside the loop to get
|
// It's important to see the entire expression outside the loop to get
|
||||||
@@ -154,7 +158,7 @@ bool IVUsers::AddUsersIfInteresting(Instruction *I,
|
|||||||
// If User is already in Processed, we don't want to recurse into it again,
|
// If User is already in Processed, we don't want to recurse into it again,
|
||||||
// but do want to record a second reference in the same instruction.
|
// but do want to record a second reference in the same instruction.
|
||||||
bool AddUserToIVUsers = false;
|
bool AddUserToIVUsers = false;
|
||||||
if (UserLoop != L) {
|
if (LI->getLoopFor(User->getParent()) != L) {
|
||||||
if (isa<PHINode>(User) || Processed.count(User) ||
|
if (isa<PHINode>(User) || Processed.count(User) ||
|
||||||
!AddUsersIfInteresting(User, SimpleLoopNests)) {
|
!AddUsersIfInteresting(User, SimpleLoopNests)) {
|
||||||
DEBUG(dbgs() << "FOUND USER in other loop: " << *User << '\n'
|
DEBUG(dbgs() << "FOUND USER in other loop: " << *User << '\n'
|
||||||
|
@@ -48,3 +48,76 @@ for.inc: ; preds = %lor.rhs234, %land.l
|
|||||||
return: ; preds = %if.end677, %doshell, %if.then96
|
return: ; preds = %if.end677, %doshell, %if.then96
|
||||||
ret void
|
ret void
|
||||||
}
|
}
|
||||||
|
|
||||||
|
define void @nopreheader2() nounwind ssp {
|
||||||
|
entry:
|
||||||
|
indirectbr i8* undef, [label %while.cond, label %return]
|
||||||
|
|
||||||
|
while.cond: ; preds = %while.cond.backedge, %entry
|
||||||
|
indirectbr i8* undef, [label %while.cond.backedge, label %lor.rhs]
|
||||||
|
|
||||||
|
lor.rhs: ; preds = %while.cond
|
||||||
|
indirectbr i8* undef, [label %while.cond.backedge, label %while.end]
|
||||||
|
|
||||||
|
while.cond.backedge: ; preds = %lor.rhs, %while.cond
|
||||||
|
indirectbr i8* undef, [label %while.cond]
|
||||||
|
|
||||||
|
while.end: ; preds = %lor.rhs
|
||||||
|
indirectbr i8* undef, [label %if.then18, label %return]
|
||||||
|
|
||||||
|
if.then18: ; preds = %while.end
|
||||||
|
indirectbr i8* undef, [label %if.end35, label %lor.lhs.false]
|
||||||
|
|
||||||
|
lor.lhs.false: ; preds = %if.then18
|
||||||
|
indirectbr i8* undef, [label %if.end35, label %return]
|
||||||
|
|
||||||
|
if.end35: ; preds = %lor.lhs.false, %if.then18
|
||||||
|
indirectbr i8* undef, [label %while.cond36]
|
||||||
|
|
||||||
|
while.cond36: ; preds = %while.body49, %if.end35
|
||||||
|
%0 = phi i64 [ %indvar.next13, %while.body49 ], [ 0, %if.end35 ]
|
||||||
|
indirectbr i8* undef, [label %while.body49, label %lor.rhs42]
|
||||||
|
|
||||||
|
lor.rhs42: ; preds = %while.cond36
|
||||||
|
indirectbr i8* undef, [label %while.body49, label %while.end52]
|
||||||
|
|
||||||
|
while.body49: ; preds = %lor.rhs42, %while.cond36
|
||||||
|
%indvar.next13 = add i64 %0, 1
|
||||||
|
indirectbr i8* undef, [label %while.cond36]
|
||||||
|
|
||||||
|
while.end52: ; preds = %lor.rhs42
|
||||||
|
indirectbr i8* undef, [label %land.lhs.true, label %return]
|
||||||
|
|
||||||
|
land.lhs.true: ; preds = %while.end52
|
||||||
|
indirectbr i8* undef, [label %while.cond66.preheader, label %return]
|
||||||
|
|
||||||
|
while.cond66.preheader: ; preds = %land.lhs.true
|
||||||
|
indirectbr i8* undef, [label %while.cond66]
|
||||||
|
|
||||||
|
while.cond66: ; preds = %while.body77, %while.cond66.preheader
|
||||||
|
indirectbr i8* undef, [label %land.rhs, label %while.cond81.preheader]
|
||||||
|
|
||||||
|
land.rhs: ; preds = %while.cond66
|
||||||
|
indirectbr i8* undef, [label %while.body77, label %while.cond81.preheader]
|
||||||
|
|
||||||
|
while.cond81.preheader: ; preds = %land.rhs, %while.cond66
|
||||||
|
%tmp45 = add i64 undef, %0
|
||||||
|
%tmp46 = add i64 %tmp45, undef
|
||||||
|
indirectbr i8* undef, [label %while.cond81]
|
||||||
|
|
||||||
|
while.body77: ; preds = %land.rhs
|
||||||
|
indirectbr i8* undef, [label %while.cond66]
|
||||||
|
|
||||||
|
while.cond81: ; preds = %while.body94, %while.cond81.preheader
|
||||||
|
%tmp25 = add i64 %tmp46, undef
|
||||||
|
indirectbr i8* undef, [label %while.body94, label %lor.rhs87]
|
||||||
|
|
||||||
|
lor.rhs87: ; preds = %while.cond81
|
||||||
|
indirectbr i8* undef, [label %while.body94, label %return]
|
||||||
|
|
||||||
|
while.body94: ; preds = %lor.rhs87, %while.cond81
|
||||||
|
indirectbr i8* undef, [label %while.cond81]
|
||||||
|
|
||||||
|
return: ; preds = %if.end216, %land.lhs.true183, %land.lhs.true, %while.end52, %lor.lhs.false, %while.end, %entry
|
||||||
|
ret void
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user