diff options
| author | Nick Lewycky <nicholas@mxc.ca> | 2009-07-29 05:17:50 +0000 |
|---|---|---|
| committer | Nick Lewycky <nicholas@mxc.ca> | 2009-07-29 05:17:50 +0000 |
| commit | f82326b9848dc24d058e485386f993fcf0835a24 (patch) | |
| tree | 5db9e39770085d8fc3bd086404cb44173d1e8932 /llvm/lib | |
| parent | 5034329f8d67ca705b600b01c8bbec3d0b0f6aba (diff) | |
| download | bcm5719-llvm-f82326b9848dc24d058e485386f993fcf0835a24.tar.gz bcm5719-llvm-f82326b9848dc24d058e485386f993fcf0835a24.zip | |
Bulk erasing instructions without RAUWing them is unsafe. Instead, break them
into a new BB that has no predecessors.
llvm-svn: 77433
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/Transforms/Scalar/SimplifyLibCalls.cpp | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/llvm/lib/Transforms/Scalar/SimplifyLibCalls.cpp b/llvm/lib/Transforms/Scalar/SimplifyLibCalls.cpp index 506ba1fdb6d..14212bc5799 100644 --- a/llvm/lib/Transforms/Scalar/SimplifyLibCalls.cpp +++ b/llvm/lib/Transforms/Scalar/SimplifyLibCalls.cpp @@ -519,17 +519,19 @@ struct VISIBILITY_HIDDEN ExitOpt : public LibCallOptimization { TerminatorInst *OldTI = CI->getParent()->getTerminator(); - // Create the return after the call. - ReturnInst *RI = B.CreateRet(CI->getOperand(1)); - // Drop all successor phi node entries. for (unsigned i = 0, e = OldTI->getNumSuccessors(); i != e; ++i) OldTI->getSuccessor(i)->removePredecessor(CI->getParent()); - // Erase all instructions from after our return instruction until the end of - // the block. - BasicBlock::iterator FirstDead = RI; ++FirstDead; - CI->getParent()->getInstList().erase(FirstDead, CI->getParent()->end()); + // Split the basic block after the call to exit. + BasicBlock::iterator FirstDead = CI; ++FirstDead; + CI->getParent()->splitBasicBlock(FirstDead); + B.SetInsertPoint(B.GetInsertBlock()); + + // Remove the branch that splitBB created and insert a return instead. + CI->getParent()->getTerminator()->eraseFromParent(); + B.CreateRet(CI->getOperand(1)); + return CI; } }; |

