[llvm-commits] [llvm] r153131 - in /llvm/trunk: lib/Analysis/IVUsers.cpp test/Transforms/LoopStrengthReduce/2012-03-15-nopreheader.ll
Andrew Trick
atrick at apple.com
Tue Mar 20 14:24:40 PDT 2012
Author: atrick
Date: Tue Mar 20 16:24:40 2012
New Revision: 153131
URL: http://llvm.org/viewvc/llvm-project?rev=153131&view=rev
Log:
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
Modified:
llvm/trunk/lib/Analysis/IVUsers.cpp
llvm/trunk/test/Transforms/LoopStrengthReduce/2012-03-15-nopreheader.ll
Modified: llvm/trunk/lib/Analysis/IVUsers.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/IVUsers.cpp?rev=153131&r1=153130&r2=153131&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/IVUsers.cpp (original)
+++ llvm/trunk/lib/Analysis/IVUsers.cpp Tue Mar 20 16:24:40 2012
@@ -79,22 +79,31 @@
return false;
}
-/// Return true if this loop and all loop headers that dominate it are in
-/// simplified form.
-static bool isSimplifiedLoopNest(Loop *L, const DominatorTree *DT,
- const LoopInfo *LI) {
- if (!L->isLoopSimplifyForm())
- return false;
-
- for (DomTreeNode *Rung = DT->getNode(L->getLoopPreheader());
+/// Return true if all loop headers that dominate this block are in simplified
+/// form.
+static bool isSimplifiedLoopNest(BasicBlock *BB, const DominatorTree *DT,
+ const LoopInfo *LI,
+ SmallPtrSet<Loop*,16> &SimpleLoopNests) {
+ Loop *NearestLoop = 0;
+ for (DomTreeNode *Rung = DT->getNode(BB);
Rung; Rung = Rung->getIDom()) {
- BasicBlock *BB = Rung->getBlock();
- const Loop *DomLoop = LI->getLoopFor(BB);
- if (DomLoop && DomLoop->getHeader() == BB) {
+ BasicBlock *DomBB = Rung->getBlock();
+ Loop *DomLoop = LI->getLoopFor(DomBB);
+ if (DomLoop && DomLoop->getHeader() == DomBB) {
+ // If the domtree walk reaches a loop with no preheader, return false.
if (!DomLoop->isLoopSimplifyForm())
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;
}
@@ -137,15 +146,10 @@
if (isa<PHINode>(User) && Processed.count(User))
continue;
- Loop *UserLoop = LI->getLoopFor(User->getParent());
-
// Only consider IVUsers that are dominated by simplified loop
// headers. Otherwise, SCEVExpander will crash.
- if (UserLoop && !SimpleLoopNests.count(UserLoop)) {
- if (!isSimplifiedLoopNest(UserLoop, DT, LI))
- return false;
- SimpleLoopNests.insert(UserLoop);
- }
+ if (!isSimplifiedLoopNest(User->getParent(), DT, LI, SimpleLoopNests))
+ return false;
// Descend recursively, but not into PHI nodes outside the current loop.
// It's important to see the entire expression outside the loop to get
@@ -154,7 +158,7 @@
// 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.
bool AddUserToIVUsers = false;
- if (UserLoop != L) {
+ if (LI->getLoopFor(User->getParent()) != L) {
if (isa<PHINode>(User) || Processed.count(User) ||
!AddUsersIfInteresting(User, SimpleLoopNests)) {
DEBUG(dbgs() << "FOUND USER in other loop: " << *User << '\n'
Modified: llvm/trunk/test/Transforms/LoopStrengthReduce/2012-03-15-nopreheader.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/LoopStrengthReduce/2012-03-15-nopreheader.ll?rev=153131&r1=153130&r2=153131&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/LoopStrengthReduce/2012-03-15-nopreheader.ll (original)
+++ llvm/trunk/test/Transforms/LoopStrengthReduce/2012-03-15-nopreheader.ll Tue Mar 20 16:24:40 2012
@@ -48,3 +48,76 @@
return: ; preds = %if.end677, %doshell, %if.then96
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
+}
More information about the llvm-commits
mailing list