summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2006-01-13 21:28:09 +0000
committerChris Lattner <sabre@nondot.org>2006-01-13 21:28:09 +0000
commit503221f5c58b0b84894f9bf7a970dc32cca69bbf (patch)
tree0276895707ae0ec35ae5820d188a027f4e09c474 /llvm/lib/Transforms
parent5f9c134bac04b16bb9c4a6fa735b017ed30b8c5f (diff)
downloadbcm5719-llvm-503221f5c58b0b84894f9bf7a970dc32cca69bbf.tar.gz
bcm5719-llvm-503221f5c58b0b84894f9bf7a970dc32cca69bbf.zip
Do a simple instcombine xforms to delete llvm.stackrestore cases.
llvm-svn: 25294
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/Scalar/InstructionCombining.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
index b326220499d..cbfb81bf05a 100644
--- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -4671,6 +4671,39 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
SPI->replaceAllUsesWith(PrevSPI);
return EraseInstFromFunction(CI);
}
+ } else {
+ switch (II->getIntrinsicID()) {
+ default: break;
+ case Intrinsic::stackrestore: {
+ // If the save is right next to the restore, remove the restore. This can
+ // happen when variable allocas are DCE'd.
+ if (IntrinsicInst *SS = dyn_cast<IntrinsicInst>(II->getOperand(1))) {
+ if (SS->getIntrinsicID() == Intrinsic::stacksave) {
+ BasicBlock::iterator BI = SS;
+ if (&*++BI == II)
+ 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.
+ 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))) {
+ CannotRemove = true;
+ break;
+ }
+ }
+ if (!CannotRemove)
+ return EraseInstFromFunction(CI);
+ }
+ break;
+ }
+ }
}
return visitCallSite(II);
OpenPOWER on IntegriCloud