Fix CodeExtractor/2004-03-17-UpdatePHIsOutsideRegion.ll
authorChris Lattner <sabre@nondot.org>
Thu, 18 Mar 2004 05:38:31 +0000 (05:38 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 18 Mar 2004 05:38:31 +0000 (05:38 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12489 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Utils/CodeExtractor.cpp

index 4e131b4a11ada922a74a2985c449010b36756588..9a47130c7b3a8302e2fad423423c2cd698947681 100644 (file)
@@ -371,6 +371,19 @@ Function *CodeExtractor::ExtractCodeRegion(const std::vector<BasicBlock*> &code)
       if (!BlocksToExtract.count(PN->getIncomingBlock(i)))
         PN->setIncomingBlock(i, newFuncRoot);
 
+  // Look at all successors of the codeReplacer block.  If any of these blocks
+  // had PHI nodes in them, we need to update the "from" block to be the code
+  // replacer, not the original block in the extracted region.
+  std::vector<BasicBlock*> Succs(succ_begin(codeReplacer),
+                                 succ_end(codeReplacer));
+  for (unsigned i = 0, e = Succs.size(); i != e; ++i)
+    for (BasicBlock::iterator I = Succs[i]->begin();
+         PHINode *PN = dyn_cast<PHINode>(I); ++I)
+      for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i)
+        if (BlocksToExtract.count(PN->getIncomingBlock(i)))
+          PN->setIncomingBlock(i, codeReplacer);
+  
+
   DEBUG(if (verifyFunction(*newFunction)) abort());
   return newFunction;
 }