summaryrefslogtreecommitdiff
path: root/lib/Transforms/Utils/CodeExtractor.cpp
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
commita670c684a637e9922be87d8b459d2e052675f0e4 (patch)
tree84d4aa8c464e992d613be90000dfb349f1c812ac /lib/Transforms/Utils/CodeExtractor.cpp
parent337772832bb93ed98ee1e93c584ac3f82d9ea959 (diff)
downloadllvm-a670c684a637e9922be87d8b459d2e052675f0e4.tar.gz
llvm-a670c684a637e9922be87d8b459d2e052675f0e4.tar.bz2
llvm-a670c684a637e9922be87d8b459d2e052675f0e4.tar.xz
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). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15717 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Utils/CodeExtractor.cpp')
-rw-r--r--lib/Transforms/Utils/CodeExtractor.cpp13
1 files changed, 11 insertions, 2 deletions
diff --git a/lib/Transforms/Utils/CodeExtractor.cpp b/lib/Transforms/Utils/CodeExtractor.cpp
index 4521038dd6..aabc587b56 100644
--- a/lib/Transforms/Utils/CodeExtractor.cpp
+++ b/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);