<div dir="ltr">Hi Sean,<div><br></div><div>I've temporarily reverted this here:</div><div><br></div><div><div>echristo@athyra ~/s/llvm> git svn dcommit</div><div>Committing to <a href="https://llvm.org/svn/llvm-project/llvm/trunk">https://llvm.org/svn/llvm-project/llvm/trunk</a> ...</div><div><span style="white-space:pre">   </span>M<span style="white-space:pre">    </span>lib/Target/PowerPC/PPCISelLowering.cpp</div><div><span style="white-space:pre">        </span>M<span style="white-space:pre">    </span>test/CodeGen/PowerPC/duplicate-returns-for-tailcall.ll</div><div>Committed r320106</div></div><div><br></div><div>since we were showing it as breaking asan and ubsan tests. Unfortunately this wasn't on the bots as they're currently down, but it was evident with an asan build.</div><div><br></div><div>I've approved patches to get the external bots up so we'll see if we can reproduce there and I'll work with you on getting some sort of test case here.</div><div><br></div><div>-eric</div></div><br><div class="gmail_quote"><div dir="ltr">On Tue, Nov 28, 2017 at 12:26 PM Sean Fertile via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: sfertile<br>
Date: Tue Nov 28 12:25:58 2017<br>
New Revision: 319218<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=319218&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=319218&view=rev</a><br>
Log:<br>
[PowerPC] Allow tail calls of fastcc functions from C CallingConv functions.<br>
<br>
Allow fastcc callees to be tail-called from ccc callers.<br>
<br>
Differential Revision: <a href="https://reviews.llvm.org/D40355" rel="noreferrer" target="_blank">https://reviews.llvm.org/D40355</a><br>
<br>
Modified:<br>
    llvm/trunk/lib/Target/PowerPC/PPCISelLowering.cpp<br>
    llvm/trunk/test/CodeGen/PowerPC/duplicate-returns-for-tailcall.ll<br>
<br>
Modified: llvm/trunk/lib/Target/PowerPC/PPCISelLowering.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PowerPC/PPCISelLowering.cpp?rev=319218&r1=319217&r2=319218&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PowerPC/PPCISelLowering.cpp?rev=319218&r1=319217&r2=319218&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Target/PowerPC/PPCISelLowering.cpp (original)<br>
+++ llvm/trunk/lib/Target/PowerPC/PPCISelLowering.cpp Tue Nov 28 12:25:58 2017<br>
@@ -4397,13 +4397,18 @@ hasSameArgumentList(const Function *Call<br>
 static bool<br>
 areCallingConvEligibleForTCO_64SVR4(CallingConv::ID CallerCC,<br>
                                     CallingConv::ID CalleeCC) {<br>
-  // Tail or Sibling call optimization (TCO/SCO) needs callee and caller to<br>
-  // have the same calling convention.<br>
-  if (CallerCC != CalleeCC)<br>
+  // tail calls are possible with fastcc and ccc.<br>
+  auto isTailCallableCC  = [] (CallingConv::ID CC){<br>
+      return  CC == CallingConv::C || CC == CallingConv::Fast;<br>
+  };<br>
+  if (!isTailCallableCC(CallerCC) || !isTailCallableCC(CalleeCC))<br>
     return false;<br>
<br>
-  // Tail or Sibling calls can be done with fastcc/ccc.<br>
-  return (CallerCC == CallingConv::Fast || CallerCC == CallingConv::C);<br>
+  // We can safely tail call both fastcc and ccc callees from a c calling<br>
+  // convention caller. If the caller is fastcc, we may have less stack space<br>
+  // then a non-fastcc caller with the same signature so disable tail-calls in<br>
+  // that case.<br>
+  return CallerCC == CallingConv::C || CallerCC == CalleeCC;<br>
 }<br>
<br>
 bool<br>
<br>
Modified: llvm/trunk/test/CodeGen/PowerPC/duplicate-returns-for-tailcall.ll<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/PowerPC/duplicate-returns-for-tailcall.ll?rev=319218&r1=319217&r2=319218&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/PowerPC/duplicate-returns-for-tailcall.ll?rev=319218&r1=319217&r2=319218&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/test/CodeGen/PowerPC/duplicate-returns-for-tailcall.ll (original)<br>
+++ llvm/trunk/test/CodeGen/PowerPC/duplicate-returns-for-tailcall.ll Tue Nov 28 12:25:58 2017<br>
@@ -42,10 +42,10 @@ if.end4:<br>
 if.then6:                                         ; preds = %if.end4<br>
   %call7 = tail call fastcc signext i32 @call3(i32 signext %a, i32 signext %b, i32 signext %c)<br>
   br label %return<br>
-; No duplication here because the calling convention mismatch means we won't tail-call<br>
+; tail calling a fastcc function from a ccc function is supported.<br>
 ; CHECK_LABEL: if.then13:<br>
-; CHECK:       tail call fastcc signext i32 @call3<br>
-; CHECK-NEXT:  br<br>
+; CHECK:       %[[T2:[a-zA-Z0-9]+]] = tail call fastcc signext i32 @call3<br>
+; CHECK-NEXT:  ret i32 %[[T2]]<br>
<br>
 return:                                           ; preds = %if.end4, %if.then6, %if.then2, %if.then<br>
   %retval.0 = phi i32 [ %call, %if.then ], [ %call3, %if.then2 ], [ %call7, %if.then6 ], [ %c, %if.end4 ]<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>