aboutsummaryrefslogtreecommitdiff
path: root/lib/Transforms
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2008-02-18 06:12:38 +0000
committerChris Lattner <sabre@nondot.org>2008-02-18 06:12:38 +0000
commitbf1d8a7099bb23e9dc92b56fe2564cbc2a71b063 (patch)
tree2088a996d29f56b54ce1f2ce592e3b2d61952304 /lib/Transforms
parent28cb2051c85f72a425c1fa595d10b175413416bb (diff)
optimize away stackrestore calls that have no intervening alloca or call.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@47258 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms')
-rw-r--r--lib/Transforms/Scalar/InstructionCombining.cpp28
1 files changed, 18 insertions, 10 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp
index 1ecefeb82b..9d0990f51b 100644
--- a/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/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;
}
}