From 26ab7ead45b37e22dd6f4a7704ca11fb2a47ca43 Mon Sep 17 00:00:00 2001 From: Reid Kleckner Date: Thu, 15 May 2014 20:39:13 +0000 Subject: Don't insert lifetime.end markers between a musttail call and ret The allocas going out of scope are immediately killed by the return instruction. Reviewers: chandlerc Differential Revision: http://reviews.llvm.org/D3630 llvm-svn: 208912 --- llvm/lib/Transforms/Utils/InlineFunction.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'llvm/lib/Transforms') diff --git a/llvm/lib/Transforms/Utils/InlineFunction.cpp b/llvm/lib/Transforms/Utils/InlineFunction.cpp index a3b9da588e6..5b7a5dc88d7 100644 --- a/llvm/lib/Transforms/Utils/InlineFunction.cpp +++ b/llvm/lib/Transforms/Utils/InlineFunction.cpp @@ -758,8 +758,13 @@ bool llvm::InlineFunction(CallSite CS, InlineFunctionInfo &IFI, } builder.CreateLifetimeStart(AI, AllocaSize); - for (ReturnInst *RI : Returns) + for (ReturnInst *RI : Returns) { + // Don't insert llvm.lifetime.end calls between a musttail call and a + // return. The return kills all local allocas. + if (InlinedMustTailCalls && getPrecedingMustTailCall(RI)) + continue; IRBuilder<>(RI).CreateLifetimeEnd(AI, AllocaSize); + } } } @@ -777,8 +782,13 @@ bool llvm::InlineFunction(CallSite CS, InlineFunctionInfo &IFI, // Insert a call to llvm.stackrestore before any return instructions in the // inlined function. - for (ReturnInst *RI : Returns) + for (ReturnInst *RI : Returns) { + // Don't insert llvm.stackrestore calls between a musttail call and a + // return. The return will restore the stack pointer. + if (InlinedMustTailCalls && getPrecedingMustTailCall(RI)) + continue; IRBuilder<>(RI).CreateCall(StackRestore, SavedPtr); + } } // If we are inlining for an invoke instruction, we must make sure to rewrite -- cgit v1.2.3