diff options
author | Chris Lattner <sabre@nondot.org> | 2008-02-18 06:12:38 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2008-02-18 06:12:38 +0000 |
commit | 024f8c8f095a9d05a863ab3188369c111c8fdac1 (patch) | |
tree | 3cd7d973e84aa285c6e5b9ecc1aac6d805e27224 /llvm/lib/Transforms | |
parent | c8ec470b5226a1fdd46190c93554fd3588dfae61 (diff) | |
download | bcm5719-llvm-024f8c8f095a9d05a863ab3188369c111c8fdac1.tar.gz bcm5719-llvm-024f8c8f095a9d05a863ab3188369c111c8fdac1.zip |
optimize away stackrestore calls that have no intervening alloca or call.
llvm-svn: 47258
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r-- | llvm/lib/Transforms/Scalar/InstructionCombining.cpp | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp index 1ecefeb82bc..9d0990f51b8 100644 --- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp @@ -8199,22 +8199,30 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) { } } - // If the stack restore is in a return/unwind block and if there are no - // allocas or calls between the restore and the return, nuke the restore. + // Scan down this block to see if there is another stack restore in the + // same block without an intervening call/alloca. + BasicBlock::iterator BI = II; TerminatorInst *TI = II->getParent()->getTerminator(); - if (isa<ReturnInst>(TI) || isa<UnwindInst>(TI)) { - BasicBlock::iterator BI = II; - bool CannotRemove = false; - for (++BI; &*BI != TI; ++BI) { - if (isa<AllocaInst>(BI) || - (isa<CallInst>(BI) && !isa<IntrinsicInst>(BI))) { + bool CannotRemove = false; + for (++BI; &*BI != TI; ++BI) { + if (isa<AllocaInst>(BI)) { + CannotRemove = true; + break; + } + if (isa<CallInst>(BI)) { + if (!isa<IntrinsicInst>(BI)) { CannotRemove = true; break; } - } - if (!CannotRemove) + // If there is a stackrestore below this one, remove this one. return EraseInstFromFunction(CI); + } } + + // If the stack restore is in a return/unwind block and if there are no + // allocas or calls between the restore and the return, nuke the restore. + if (!CannotRemove && (isa<ReturnInst>(TI) || isa<UnwindInst>(TI))) + return EraseInstFromFunction(CI); break; } } |