alternate fix for PR5258 which avoids worklist problems, with reduced testcase.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@84667 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Transforms/Utils/SSAUpdater.cpp b/lib/Transforms/Utils/SSAUpdater.cpp
index ed9c0ee..8a07c35 100644
--- a/lib/Transforms/Utils/SSAUpdater.cpp
+++ b/lib/Transforms/Utils/SSAUpdater.cpp
@@ -177,19 +177,14 @@
 /// which use their value in the corresponding predecessor.
 void SSAUpdater::RewriteUse(Use &U) {
   Instruction *User = cast<Instruction>(U.getUser());
-  BasicBlock *UseBB = User->getParent();
-  PHINode *UserPN = dyn_cast<PHINode>(User);
-  if (UserPN)
-    UseBB = UserPN->getIncomingBlock(U);
+  
+  Value *V;
+  if (PHINode *UserPN = dyn_cast<PHINode>(User))
+    V = GetValueAtEndOfBlock(UserPN->getIncomingBlock(U));
+  else
+    V = GetValueInMiddleOfBlock(User->getParent());
 
-  Value *V = GetValueInMiddleOfBlock(UseBB);
   U.set(V);
-  if (UserPN) {
-    // Incoming value from the same BB must be consistent
-    for (unsigned i=0;i<UserPN->getNumIncomingValues();i++)
-      if (UserPN->getIncomingBlock(i) == UseBB)
-        UserPN->setIncomingValue(i, V);
-  }
 }