A loop latch phi node may have uses inside loop, not just in loop header.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@47093 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Transforms/Scalar/LoopIndexSplit.cpp b/lib/Transforms/Scalar/LoopIndexSplit.cpp
index 383415b..a0bfe4f 100644
--- a/lib/Transforms/Scalar/LoopIndexSplit.cpp
+++ b/lib/Transforms/Scalar/LoopIndexSplit.cpp
@@ -151,7 +151,7 @@
     /// Update ExitBB PHINodes' to reflect this change.
     void updatePHINodes(BasicBlock *ExitBB, BasicBlock *Latch, 
                         BasicBlock *Header,
-                        PHINode *IV, Instruction *IVIncrement);
+                        PHINode *IV, Instruction *IVIncrement, Loop *LP);
 
     /// moveExitCondition - Move exit condition EC into split condition block CondBB.
     void moveExitCondition(BasicBlock *CondBB, BasicBlock *ActiveBB,
@@ -1597,7 +1597,7 @@
   new BranchInst(OrigDestBB, ExitingBB);
 
   // Update PHINodes
-  updatePHINodes(ExitBB, ExitingBB, CondBB, IV, IVAdd);
+  updatePHINodes(ExitBB, ExitingBB, CondBB, IV, IVAdd, LP);
 
   // Fix dominator info.
   // ExitBB is now dominated by CondBB
@@ -1637,7 +1637,8 @@
 /// Update ExitBB PHINodes' to reflect this change.
 void LoopIndexSplit::updatePHINodes(BasicBlock *ExitBB, BasicBlock *Latch, 
                                     BasicBlock *Header,
-                                    PHINode *IV, Instruction *IVIncrement) {
+                                    PHINode *IV, Instruction *IVIncrement,
+                                    Loop *LP) {
 
   for (BasicBlock::iterator BI = ExitBB->begin(), BE = ExitBB->end(); 
        BI != BE; ++BI) {
@@ -1653,7 +1654,7 @@
       for (Value::use_iterator UI = PHV->use_begin(), E = PHV->use_end(); 
            UI != E; ++UI) 
         if (PHINode *U = dyn_cast<PHINode>(*UI)) 
-          if (U->getParent() == Header) {
+          if (LP->contains(U->getParent())) {
             NewV = U;
             break;
           }