diff options
author | Chris Lattner <sabre@nondot.org> | 2006-01-13 21:28:09 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2006-01-13 21:28:09 +0000 |
commit | a728ddc81586c7fb881a1b429d169d1004f8c74b (patch) | |
tree | 98f53958a3c4591657f84026003f791530fe1e01 /lib | |
parent | 052d2ff5dda20a7a3ff07f2829acbbb4827d7a9c (diff) | |
download | external_llvm-a728ddc81586c7fb881a1b429d169d1004f8c74b.zip external_llvm-a728ddc81586c7fb881a1b429d169d1004f8c74b.tar.gz external_llvm-a728ddc81586c7fb881a1b429d169d1004f8c74b.tar.bz2 |
Do a simple instcombine xforms to delete llvm.stackrestore cases.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25294 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Transforms/Scalar/InstructionCombining.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index b326220..cbfb81b 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/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); |