Skip to content

Commit 32e813e

Browse files
author
John Criswell
committed
Merged from mainline.
llvm-svn: 15723
1 parent b6a9b36 commit 32e813e

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

llvm/lib/Transforms/Utils/CodeExtractor.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ ExtractCodeRegion(const std::vector<BasicBlock*> &code) {
622622
Function *oldFunction = header->getParent();
623623

624624
// This takes place of the original loop
625-
BasicBlock *codeReplacer = new BasicBlock("codeRepl", oldFunction);
625+
BasicBlock *codeReplacer = new BasicBlock("codeRepl", oldFunction, header);
626626

627627
// The new function needs a root node because other nodes can branch to the
628628
// head of the region, but the entry node of a function cannot have preds.
@@ -657,10 +657,19 @@ ExtractCodeRegion(const std::vector<BasicBlock*> &code) {
657657
succ_end(codeReplacer));
658658
for (unsigned i = 0, e = Succs.size(); i != e; ++i)
659659
for (BasicBlock::iterator I = Succs[i]->begin();
660-
PHINode *PN = dyn_cast<PHINode>(I); ++I)
660+
PHINode *PN = dyn_cast<PHINode>(I); ++I) {
661+
std::set<BasicBlock*> ProcessedPreds;
661662
for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i)
662663
if (BlocksToExtract.count(PN->getIncomingBlock(i)))
663-
PN->setIncomingBlock(i, codeReplacer);
664+
if (ProcessedPreds.insert(PN->getIncomingBlock(i)).second)
665+
PN->setIncomingBlock(i, codeReplacer);
666+
else {
667+
// There were multiple entries in the PHI for this block, now there
668+
// is only one, so remove the duplicated entries.
669+
PN->removeIncomingValue(i, false);
670+
--i; --e;
671+
}
672+
}
664673

665674
//std::cerr << "NEW FUNCTION: " << *newFunction;
666675
// verifyFunction(*newFunction);

llvm/lib/Transforms/Utils/ValueMapper.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ Value *llvm::MapValue(const Value *V, std::map<const Value*, Value*> &VM) {
8181
for (unsigned i = 1, e = CE->getNumOperands(); i != e; ++i)
8282
Idx.push_back(cast<Constant>(MapValue(CE->getOperand(i), VM)));
8383
return VMSlot = ConstantExpr::getGetElementPtr(MV, Idx);
84+
} else if (CE->getOpcode() == Instruction::Select) {
85+
Constant *MV1 = cast<Constant>(MapValue(CE->getOperand(0), VM));
86+
Constant *MV2 = cast<Constant>(MapValue(CE->getOperand(1), VM));
87+
Constant *MV3 = cast<Constant>(MapValue(CE->getOperand(2), VM));
88+
return VMSlot = ConstantExpr::getSelect(MV1, MV2, MV3);
8489
} else {
8590
assert(CE->getNumOperands() == 2 && "Must be binary operator?");
8691
Constant *MV1 = cast<Constant>(MapValue(CE->getOperand(0), VM));

0 commit comments

Comments
 (0)