diff options
author | Daniel Dunbar <daniel@zuster.org> | 2009-07-29 22:00:43 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2009-07-29 22:00:43 +0000 |
commit | 98ddd164d8fc754a37454f1cbb8ea04051149690 (patch) | |
tree | 5cbfd649cd28575d80507b38dcd2a432d733813b /llvm/lib/Transforms/Scalar/SimplifyLibCalls.cpp | |
parent | 4a942d0863b103c807171a1ffc6112865768e19e (diff) | |
download | bcm5719-llvm-98ddd164d8fc754a37454f1cbb8ea04051149690.tar.gz bcm5719-llvm-98ddd164d8fc754a37454f1cbb8ea04051149690.zip |
Fix PR4645 which was fallout from the fix for PR4641.
- Call RAUW to delete all instructions (this is a patch from Nick Lewycky).
llvm-svn: 77512
Diffstat (limited to 'llvm/lib/Transforms/Scalar/SimplifyLibCalls.cpp')
-rw-r--r-- | llvm/lib/Transforms/Scalar/SimplifyLibCalls.cpp | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/llvm/lib/Transforms/Scalar/SimplifyLibCalls.cpp b/llvm/lib/Transforms/Scalar/SimplifyLibCalls.cpp index fef19f0ba0e..c421ee24068 100644 --- a/llvm/lib/Transforms/Scalar/SimplifyLibCalls.cpp +++ b/llvm/lib/Transforms/Scalar/SimplifyLibCalls.cpp @@ -29,6 +29,7 @@ #include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/StringMap.h" #include "llvm/ADT/Statistic.h" +#include "llvm/ADT/STLExtras.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/Debug.h" #include "llvm/Support/raw_ostream.h" @@ -518,18 +519,24 @@ struct VISIBILITY_HIDDEN ExitOpt : public LibCallOptimization { return 0; TerminatorInst *OldTI = CI->getParent()->getTerminator(); - + // Drop all successor phi node entries. for (unsigned i = 0, e = OldTI->getNumSuccessors(); i != e; ++i) OldTI->getSuccessor(i)->removePredecessor(CI->getParent()); - - // 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(); + // Remove all instructions after the exit. + BasicBlock::iterator Dead = CI, E = OldTI; ++Dead; + while (Dead != E) { + BasicBlock::iterator Next = next(Dead); + if (Dead->getType() != Type::VoidTy) + Dead->replaceAllUsesWith(UndefValue::get(Dead->getType())); + Dead->eraseFromParent(); + Dead = Next; + } + + // Insert a return instruction. + OldTI->eraseFromParent(); + B.SetInsertPoint(B.GetInsertBlock()); B.CreateRet(CI->getOperand(1)); return CI; |