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;
}