<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Aug 28, 2015 at 10:16 AM, 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:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr">Test case?</div></blockquote><div><br></div><div>Forgot to 'git add', added in r246306.</div>







<div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"> Also, I think you can do a more precise analysis here. We should be able to tail call in this example:<div><br></div><div>i32* @f() {<br><div>  %a = tail call i32* @foo_readnone()</div><div>  store i32 0, i32* %b</div><div>  ret i32* %a</div></div><div>}</div><div><br></div><div>I think in the readnone case you just need to check that the return value is used by nothing more than the ReturnInst.</div></div></blockquote><div><br></div><div>I think that's possible, I'm willing to live with the current state of things until I'm finished adding a 'pure' attribute to LLVM IR.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div class=""><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Aug 28, 2015 at 9:44 AM, David Majnemer via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Author: majnemer<br>
Date: Fri Aug 28 11:44:09 2015<br>
New Revision: 246304<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=246304&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=246304&view=rev</a><br>
Log:<br>
[CodeGen] isInTailCallPosition didn't consider readnone tailcalls<br>
<br>
A readnone tailcall may still have a chain of computation which follows<br>
it that would invalidate a tailcall lowering.  Don't skip the analysis<br>
in such cases.<br>
<br>
This fixes PR24613.<br>
<br>
Modified:<br>
    llvm/trunk/lib/Analysis/ValueTracking.cpp<br>
    llvm/trunk/lib/CodeGen/Analysis.cpp<br>
<br>
Modified: llvm/trunk/lib/Analysis/ValueTracking.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ValueTracking.cpp?rev=246304&r1=246303&r2=246304&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ValueTracking.cpp?rev=246304&r1=246303&r2=246304&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Analysis/ValueTracking.cpp (original)<br>
+++ llvm/trunk/lib/Analysis/ValueTracking.cpp Fri Aug 28 11:44:09 2015<br>
@@ -3147,7 +3147,8 @@ bool llvm::isSafeToSpeculativelyExecute(<br>
         LI->getPointerOperand(), LI->getAlignment(), DL, CtxI, DT, TLI);<br>
   }<br>
   case Instruction::Call: {<br>
-    if (cast<CallInst>(Inst)->doesNotAccessMemory())<br>
+    auto *CI = cast<CallInst>(Inst);<br>
+    if (CI->doesNotAccessMemory() && !CI->isMustTailCall())<br>
       return true;<br>
     return false; // The called function could have undefined behavior or<br>
                   // side-effects.<br>
<br>
Modified: llvm/trunk/lib/CodeGen/Analysis.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/Analysis.cpp?rev=246304&r1=246303&r2=246304&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/Analysis.cpp?rev=246304&r1=246303&r2=246304&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/CodeGen/Analysis.cpp (original)<br>
+++ llvm/trunk/lib/CodeGen/Analysis.cpp Fri Aug 28 11:44:09 2015<br>
@@ -506,18 +506,16 @@ bool llvm::isInTailCallPosition(Immutabl<br>
<br>
   // If I will have a chain, make sure no other instruction that will have a<br>
   // chain interposes between I and the return.<br>
-  if (I->mayHaveSideEffects() || I->mayReadFromMemory() ||<br>
-      !isSafeToSpeculativelyExecute(I))<br>
-    for (BasicBlock::const_iterator BBI = std::prev(ExitBB->end(), 2);; --BBI) {<br>
-      if (&*BBI == I)<br>
-        break;<br>
-      // Debug info intrinsics do not get in the way of tail call optimization.<br>
-      if (isa<DbgInfoIntrinsic>(BBI))<br>
-        continue;<br>
-      if (BBI->mayHaveSideEffects() || BBI->mayReadFromMemory() ||<br>
-          !isSafeToSpeculativelyExecute(BBI))<br>
-        return false;<br>
-    }<br>
+  for (BasicBlock::const_iterator BBI = std::prev(ExitBB->end(), 2);; --BBI) {<br>
+    if (&*BBI == I)<br>
+      break;<br>
+    // Debug info intrinsics do not get in the way of tail call optimization.<br>
+    if (isa<DbgInfoIntrinsic>(BBI))<br>
+      continue;<br>
+    if (BBI->mayHaveSideEffects() || BBI->mayReadFromMemory() ||<br>
+        !isSafeToSpeculativelyExecute(BBI))<br>
+      return false;<br>
+  }<br>
<br>
   const Function *F = ExitBB->getParent();<br>
   return returnTypeIsEligibleForTailCall(<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div></div>