aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Utils/CloneFunction.cpp
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2012-04-06 17:21:31 +0000
committerChandler Carruth <chandlerc@gmail.com>2012-04-06 17:21:31 +0000
commit49da93396eb2058fcf19ed7da2b73e854955fff8 (patch)
treee04a93309e035f067b8927887f3f7a1a0d2c0002 /llvm/lib/Transforms/Utils/CloneFunction.cpp
parente547fefcb780d8a19d62ec4646f2aca463861846 (diff)
downloadllvm-49da93396eb2058fcf19ed7da2b73e854955fff8.zip
llvm-49da93396eb2058fcf19ed7da2b73e854955fff8.tar.gz
llvm-49da93396eb2058fcf19ed7da2b73e854955fff8.tar.bz2
Sink the collection of return instructions until after *all*
simplification has been performed. This is a bit less efficient (requires another ilist walk of the basic blocks) but shouldn't matter in practice. More importantly, it's just too much work to keep track of all the various ways the return instructions can be mutated while simplifying them. This fixes yet another crasher, reported by Daniel Dunbar. llvm-svn: 154179
Diffstat (limited to 'llvm/lib/Transforms/Utils/CloneFunction.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/CloneFunction.cpp16
1 files changed, 9 insertions, 7 deletions
diff --git a/llvm/lib/Transforms/Utils/CloneFunction.cpp b/llvm/lib/Transforms/Utils/CloneFunction.cpp
index 423f47d..20052a4 100644
--- a/llvm/lib/Transforms/Utils/CloneFunction.cpp
+++ b/llvm/lib/Transforms/Utils/CloneFunction.cpp
@@ -532,13 +532,6 @@ void llvm::CloneAndPruneFunctionInto(Function *NewFunc, const Function *OldFunc,
// and we still want to prune the dead code as early as possible.
ConstantFoldTerminator(I);
- // Track all of the newly-inserted returns.
- if (ReturnInst *RI = dyn_cast<ReturnInst>(I->getTerminator())) {
- Returns.push_back(RI);
- ++I;
- continue;
- }
-
BranchInst *BI = dyn_cast<BranchInst>(I->getTerminator());
if (!BI || BI->isConditional()) { ++I; continue; }
@@ -566,4 +559,13 @@ void llvm::CloneAndPruneFunctionInto(Function *NewFunc, const Function *OldFunc,
// Do not increment I, iteratively merge all things this block branches to.
}
+
+ // Make a final pass over the basic blocks from theh old function to gather
+ // any return instructions which survived folding. We have to do this here
+ // because we can iteratively remove and merge returns above.
+ for (Function::iterator I = cast<BasicBlock>(VMap[&OldFunc->getEntryBlock()]),
+ E = NewFunc->end();
+ I != E; ++I)
+ if (ReturnInst *RI = dyn_cast<ReturnInst>(I->getTerminator()))
+ Returns.push_back(RI);
}