summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2004-08-13 03:27:07 +0000
committerChris Lattner <sabre@nondot.org>2004-08-13 03:27:07 +0000
commit56273827b15e158eed8deeb24273538c94264b44 (patch)
tree2938beb4b297f97b2e922ea59cad7c60dcadbdf2 /llvm/lib/Transforms
parentf06b0432045ddf4bf59f1994b2c7ac17fb56789e (diff)
downloadbcm5719-llvm-56273827b15e158eed8deeb24273538c94264b44.tar.gz
bcm5719-llvm-56273827b15e158eed8deeb24273538c94264b44.zip
If we are extracting a block that has multiple successors that are the same
block (common in a switch), make sure to remove extra edges in successor blocks. This fixes CodeExtractor/2004-08-12-BlockExtractPHI.ll and should be pulled into LLVM 1.3 (though the regression test need not be, as that would require pulling in the LoopExtract.cpp changes). llvm-svn: 15717
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/Utils/CodeExtractor.cpp13
1 files changed, 11 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/Utils/CodeExtractor.cpp b/llvm/lib/Transforms/Utils/CodeExtractor.cpp
index 4521038dd66..aabc587b56d 100644
--- a/llvm/lib/Transforms/Utils/CodeExtractor.cpp
+++ b/llvm/lib/Transforms/Utils/CodeExtractor.cpp
@@ -657,10 +657,19 @@ ExtractCodeRegion(const std::vector<BasicBlock*> &code) {
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)
+ PHINode *PN = dyn_cast<PHINode>(I); ++I) {
+ std::set<BasicBlock*> ProcessedPreds;
for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i)
if (BlocksToExtract.count(PN->getIncomingBlock(i)))
- PN->setIncomingBlock(i, codeReplacer);
+ if (ProcessedPreds.insert(PN->getIncomingBlock(i)).second)
+ PN->setIncomingBlock(i, codeReplacer);
+ else {
+ // There were multiple entries in the PHI for this block, now there
+ // is only one, so remove the duplicated entries.
+ PN->removeIncomingValue(i, false);
+ --i; --e;
+ }
+ }
//std::cerr << "NEW FUNCTION: " << *newFunction;
// verifyFunction(*newFunction);
OpenPOWER on IntegriCloud