LSR: teach isSimplifiedLoopNest to handle PHI IVUsers.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@153132 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Analysis/IVUsers.cpp b/lib/Analysis/IVUsers.cpp
index 308729f..463584d 100644
--- a/lib/Analysis/IVUsers.cpp
+++ b/lib/Analysis/IVUsers.cpp
@@ -148,7 +148,14 @@
 
     // 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.