<div dir="ltr">This is fine, and explains it better IMO. Seeing them together also helps me think about it in the right (and more obvious) direction. Thanks!</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, May 15, 2014 at 2:58 PM, Reid Kleckner <span dir="ltr"><<a href="mailto:rnk@google.com" target="_blank">rnk@google.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="">Hi chandlerc,<br>
<br>
The allocas going out of scope are immediately killed by the return<br>
instruction.<br>
<br>
</div>This is a resend of r208912, which was committed accidentally.<br>
<br>
<a href="http://reviews.llvm.org/D3792" target="_blank">http://reviews.llvm.org/D3792</a><br>
<div class=""><br>
Files:<br>
  lib/Transforms/Utils/InlineFunction.cpp<br>
  test/Transforms/Inline/inline-tail.ll<br>
<br>
Index: lib/Transforms/Utils/InlineFunction.cpp<br>
===================================================================<br>
--- lib/Transforms/Utils/InlineFunction.cpp<br>
+++ lib/Transforms/Utils/InlineFunction.cpp<br>
</div>@@ -755,8 +755,13 @@<br>
<div class="">       }<br>
<br>
       builder.CreateLifetimeStart(AI, AllocaSize);<br>
-      for (ReturnInst *RI : Returns)<br>
+      for (ReturnInst *RI : Returns) {<br>
+        // Don't insert llvm.lifetime.end calls between a musttail call and a<br>
+        // return.  The return kills all local allocas.<br>
+        if (InlinedMustTailCalls && getPrecedingMustTailCall(RI))<br>
+          continue;<br>
         IRBuilder<>(RI).CreateLifetimeEnd(AI, AllocaSize);<br>
+      }<br>
     }<br>
   }<br>
<br>
</div>@@ -774,8 +779,13 @@<br>
<div class="HOEnZb"><div class="h5"><br>
     // Insert a call to llvm.stackrestore before any return instructions in the<br>
     // inlined function.<br>
-    for (ReturnInst *RI : Returns)<br>
+    for (ReturnInst *RI : Returns) {<br>
+      // Don't insert llvm.stackrestore calls between a musttail call and a<br>
+      // return.  The return will restore the stack pointer.<br>
+      if (InlinedMustTailCalls && getPrecedingMustTailCall(RI))<br>
+        continue;<br>
       IRBuilder<>(RI).CreateCall(StackRestore, SavedPtr);<br>
+    }<br>
   }<br>
<br>
   // If we are inlining for an invoke instruction, we must make sure to rewrite<br>
Index: test/Transforms/Inline/inline-tail.ll<br>
===================================================================<br>
--- test/Transforms/Inline/inline-tail.ll<br>
+++ test/Transforms/Inline/inline-tail.ll<br>
@@ -49,6 +49,42 @@<br>
   ret void<br>
 }<br>
<br>
+; Don't insert lifetime end markers here, the lifetime is trivially over due<br>
+; the return.<br>
+; CHECK: define void @test_byval_a(<br>
+; CHECK: musttail call void @test_byval_c(<br>
+; CHECK-NEXT: ret void<br>
+<br>
+declare void @test_byval_c(i32* byval %p)<br>
+define internal void @test_byval_b(i32* byval %p) {<br>
+  musttail call void @test_byval_c(i32* byval %p)<br>
+  ret void<br>
+}<br>
+define void @test_byval_a(i32* byval %p) {<br>
+  musttail call void @test_byval_b(i32* byval %p)<br>
+  ret void<br>
+}<br>
+<br>
+; Don't insert a stack restore, we're about to return.<br>
+; CHECK: define void @test_dynalloca_a(<br>
+; CHECK: call i8* @llvm.stacksave(<br>
+; CHECK: alloca i8, i32 %n<br>
+; CHECK: musttail call void @test_dynalloca_c(<br>
+; CHECK-NEXT: ret void<br>
+<br>
+declare void @escape(i8* %buf)<br>
+declare void @test_dynalloca_c(i32* byval %p, i32 %n)<br>
+define internal void @test_dynalloca_b(i32* byval %p, i32 %n) alwaysinline {<br>
+  %buf = alloca i8, i32 %n              ; dynamic alloca<br>
+  call void @escape(i8* %buf)           ; escape it<br>
+  musttail call void @test_dynalloca_c(i32* byval %p, i32 %n)<br>
+  ret void<br>
+}<br>
+define void @test_dynalloca_a(i32* byval %p, i32 %n) {<br>
+  musttail call void @test_dynalloca_b(i32* byval %p, i32 %n)<br>
+  ret void<br>
+}<br>
+<br>
 ; We can't merge the returns.<br>
 ; CHECK: define void @test_multiret_a(<br>
 ; CHECK: musttail call void @test_multiret_c(<br>
</div></div><br>_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
<br></blockquote></div><br></div>