summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Trick <atrick@apple.com>2012-03-20 21:24:44 +0000
committerAndrew Trick <atrick@apple.com>2012-03-20 21:24:44 +0000
commita3b10b83597dabd926a5153ac2eb867e7920f471 (patch)
tree779e51a75874c6668fea0cbc32e5ec783f57d7e5
parentf9492288bbc51e5d34f19ba53dc778bc83be807c (diff)
downloadllvm-a3b10b83597dabd926a5153ac2eb867e7920f471.tar.gz
llvm-a3b10b83597dabd926a5153ac2eb867e7920f471.tar.bz2
llvm-a3b10b83597dabd926a5153ac2eb867e7920f471.tar.xz
LSR: teach isSimplifiedLoopNest to handle PHI IVUsers.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@153132 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Analysis/IVUsers.cpp9
-rw-r--r--test/Transforms/LoopStrengthReduce/2012-03-15-nopreheader.ll32
2 files changed, 40 insertions, 1 deletions
diff --git a/lib/Analysis/IVUsers.cpp b/lib/Analysis/IVUsers.cpp
index 308729fcf1..463584db89 100644
--- a/lib/Analysis/IVUsers.cpp
+++ b/lib/Analysis/IVUsers.cpp
@@ -148,7 +148,14 @@ bool IVUsers::AddUsersIfInteresting(Instruction *I,
// Only consider IVUsers that are dominated by simplified loop
// headers. Otherwise, SCEVExpander will crash.
- if (!isSimplifiedLoopNest(User->getParent(), DT, LI, SimpleLoopNests))
+ BasicBlock *UseBB = User->getParent();
+ // A phi's use is live out of its predecessor block.
+ if (PHINode *PHI = dyn_cast<PHINode>(User)) {
+ unsigned OperandNo = UI.getOperandNo();
+ unsigned ValNo = PHINode::getIncomingValueNumForOperand(OperandNo);
+ UseBB = PHI->getIncomingBlock(ValNo);
+ }
+ if (!isSimplifiedLoopNest(UseBB, DT, LI, SimpleLoopNests))
return false;
// Descend recursively, but not into PHI nodes outside the current loop.
diff --git a/test/Transforms/LoopStrengthReduce/2012-03-15-nopreheader.ll b/test/Transforms/LoopStrengthReduce/2012-03-15-nopreheader.ll
index 01f9276dc2..0172492edc 100644
--- a/test/Transforms/LoopStrengthReduce/2012-03-15-nopreheader.ll
+++ b/test/Transforms/LoopStrengthReduce/2012-03-15-nopreheader.ll
@@ -49,6 +49,8 @@ return: ; preds = %if.end677, %doshell
ret void
}
+; Another case with a dominating loop that does not contain the IV
+; User. Just make sure it doesn't assert.
define void @nopreheader2() nounwind ssp {
entry:
indirectbr i8* undef, [label %while.cond, label %return]
@@ -121,3 +123,33 @@ while.body94: ; preds = %lor.rhs87, %while.c
return: ; preds = %if.end216, %land.lhs.true183, %land.lhs.true, %while.end52, %lor.lhs.false, %while.end, %entry
ret void
}
+
+; Test a phi operand IV User dominated by a no-preheader loop.
+define void @nopreheader3() nounwind uwtable ssp align 2 {
+entry:
+ indirectbr i8* blockaddress(@nopreheader3, %if.end10), [label %if.end22, label %if.end10]
+
+if.end10: ; preds = %entry
+ indirectbr i8* blockaddress(@nopreheader3, %if.end6.i), [label %if.end22, label %if.end6.i]
+
+if.end6.i: ; preds = %if.end10
+ indirectbr i8* blockaddress(@nopreheader3, %while.cond2.preheader.i.i), [label %if.then12, label %while.cond2.preheader.i.i]
+
+while.cond2.preheader.i.i: ; preds = %while.end.i18.i, %if.end6.i
+ indirectbr i8* blockaddress(@nopreheader3, %while.cond2.i.i), [label %while.cond2.i.i]
+
+while.cond2.i.i: ; preds = %while.cond2.i.i, %while.cond2.preheader.i.i
+ %i1.1.i14.i = phi i32 [ %add.i15.i, %while.cond2.i.i ], [ undef, %while.cond2.preheader.i.i ]
+ %add.i15.i = add nsw i32 %i1.1.i14.i, undef
+ indirectbr i8* blockaddress(@nopreheader3, %while.end.i18.i), [label %while.cond2.i.i, label %while.end.i18.i]
+
+while.end.i18.i: ; preds = %while.cond2.i.i
+ indirectbr i8* blockaddress(@nopreheader3, %while.cond2.preheader.i.i), [label %if.then12, label %while.cond2.preheader.i.i]
+
+if.then12: ; preds = %while.end.i18.i, %if.end6.i
+ %i1.0.lcssa.i.i = phi i32 [ undef, %if.end6.i ], [ %i1.1.i14.i, %while.end.i18.i ]
+ indirectbr i8* blockaddress(@nopreheader3, %if.end22), [label %if.end22]
+
+if.end22: ; preds = %if.then12, %if.end10, %entry
+ ret void
+}