<div dir="ltr">Woops, <span style="color:rgb(0,0,0)">r238501.</span></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, May 28, 2015 at 2:05 PM, Benjamin Kramer <span dir="ltr"><<a href="mailto:benny.kra@gmail.com" target="_blank">benny.kra@gmail.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="HOEnZb"><div class="h5"><br>
> On 28.05.2015, at 22:44, Reid Kleckner <<a href="mailto:reid@kleckner.net">reid@kleckner.net</a>> wrote:<br>
><br>
> Author: rnk<br>
> Date: Thu May 28 15:44:28 2015<br>
> New Revision: 238487<br>
><br>
> URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject-3Frev-3D238487-26view-3Drev&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=gT-_LpdN2R8aXJn6udjVIneiNb_l219Lg620INe464o&s=g0PmnJfd_wSpqm0PRqqx8Nq2BiYWsF8B6MuUcQRVy8I&e=" target="_blank">http://llvm.org/viewvc/llvm-project?rev=238487&view=rev</a><br>
> Log:<br>
> Disable x86 tail call optimizations that jump through GOT<br>
><br>
> For x86 targets, do not do sibling call optimization when materializing<br>
> the callee's address would require a GOT relocation. We can still do<br>
> tail calls to internal functions, hidden functions, and protected<br>
> functions, because they do not require this kind of relocation. It is<br>
> still possible to get GOT relocations when the user explicitly asks for<br>
> it with musttail or -tailcallopt, both of which are supposed to<br>
> guarantee TCO.<br>
><br>
> Based on a patch by Chih-hung Hsieh.<br>
><br>
> Reviewers: srhines, timmurray, danalbert, enh, void, nadav, rnk<br>
><br>
> Subscribers: joerg, davidxl, llvm-commits<br>
><br>
> Differential Revision: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__reviews.llvm.org_D9799&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=gT-_LpdN2R8aXJn6udjVIneiNb_l219Lg620INe464o&s=RJK_Gh6utKrOmmBZnftNlcaXlMpmrOkqBqEONQdWGR8&e=" target="_blank">http://reviews.llvm.org/D9799</a><br>
><br>
> Added:<br>
> llvm/trunk/test/CodeGen/X86/tailcallpic3.ll<br>
> Modified:<br>
> llvm/trunk/lib/Target/X86/X86ISelLowering.cpp<br>
> llvm/trunk/test/CodeGen/X86/pic.ll<br>
> llvm/trunk/test/CodeGen/X86/tail-call-got.ll<br>
> llvm/trunk/test/CodeGen/X86/tailcallpic1.ll<br>
><br>
> Modified: llvm/trunk/lib/Target/X86/X86ISelLowering.cpp<br>
> URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_llvm_trunk_lib_Target_X86_X86ISelLowering.cpp-3Frev-3D238487-26r1-3D238486-26r2-3D238487-26view-3Ddiff&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=gT-_LpdN2R8aXJn6udjVIneiNb_l219Lg620INe464o&s=pC20QDXFyEruJB8cHJDesHKw8OrUqFjoh94_VFlep44&e=" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86ISelLowering.cpp?rev=238487&r1=238486&r2=238487&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/lib/Target/X86/X86ISelLowering.cpp (original)<br>
> +++ llvm/trunk/lib/Target/X86/X86ISelLowering.cpp Thu May 28 15:44:28 2015<br>
> @@ -2780,6 +2780,24 @@ X86TargetLowering::LowerCall(TargetLower<br>
> if (MF.getTarget().Options.DisableTailCalls)<br>
> isTailCall = false;<br>
><br>
> + if (Subtarget->isPICStyleGOT() &&<br>
> + !MF.getTarget().Options.GuaranteedTailCallOpt) {<br>
> + // If we are using a GOT, disable tail calls to external symbols with<br>
> + // default visibility. Tail calling such a symbol requires using a GOT<br>
> + // relocation, which forces early binding of the symbol. This breaks code<br>
> + // that require lazy function symbol resolution. Using musttail or<br>
> + // GuaranteedTailCallOpt will override this.<br>
> + GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee);<br>
> + if (!G || (!G->getGlobal()->hasLocalLinkage() &&<br>
> + G->getGlobal()->hasDefaultVisibility())) {<br>
> + isTailCall = false;<br>
> + if (G) {<br>
> + llvm::errs() << "disabling tail call for default visibility symbol\n";<br>
> + G->getGlobal()->dump();<br>
<br>
</div></div>printf debugging leftovers?<br>
<br>
- Ben<br>
<div class="HOEnZb"><div class="h5"><br>
> + }<br>
> + }<br>
> + }<br>
> +<br>
> bool IsMustTail = CLI.CS && CLI.CS->isMustTailCall();<br>
> if (IsMustTail) {<br>
> // Force this to be a tail call. The verifier rules are enough to ensure<br>
> @@ -2964,8 +2982,8 @@ X86TargetLowering::LowerCall(TargetLower<br>
><br>
> // Note: The actual moving to ECX is done further down.<br>
> GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee);<br>
> - if (G && !G->getGlobal()->hasHiddenVisibility() &&<br>
> - !G->getGlobal()->hasProtectedVisibility())<br>
> + if (G && !G->getGlobal()->hasLocalLinkage() &&<br>
> + G->getGlobal()->hasDefaultVisibility())<br>
> Callee = LowerGlobalAddress(Callee, DAG);<br>
> else if (isa<ExternalSymbolSDNode>(Callee))<br>
> Callee = LowerExternalSymbol(Callee, DAG);<br>
><br>
> Modified: llvm/trunk/test/CodeGen/X86/pic.ll<br>
> URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_llvm_trunk_test_CodeGen_X86_pic.ll-3Frev-3D238487-26r1-3D238486-26r2-3D238487-26view-3Ddiff&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=gT-_LpdN2R8aXJn6udjVIneiNb_l219Lg620INe464o&s=XTuWqCBMDdEb2rj_izE0PonUxRoWDq8qTQCkANzAE3Q&e=" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/pic.ll?rev=238487&r1=238486&r2=238487&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/test/CodeGen/X86/pic.ll (original)<br>
> +++ llvm/trunk/test/CodeGen/X86/pic.ll Thu May 28 15:44:28 2015<br>
> @@ -196,9 +196,11 @@ bb12:<br>
> ; LINUX-NEXT: .LJTI7_0:<br>
> ; LINUX: .long .LBB7_2@GOTOFF<br>
> ; LINUX: .long .LBB7_8@GOTOFF<br>
> -; LINUX: .long .LBB7_14@GOTOFF<br>
> -; LINUX: .long .LBB7_9@GOTOFF<br>
> -; LINUX: .long .LBB7_10@GOTOFF<br>
> +; LINUX: .long .LBB7_4@GOTOFF<br>
> +; LINUX: .long .LBB7_6@GOTOFF<br>
> +; LINUX: .long .LBB7_5@GOTOFF<br>
> +; LINUX: .long .LBB7_8@GOTOFF<br>
> +; LINUX: .long .LBB7_7@GOTOFF<br>
> }<br>
><br>
> declare void @foo1(...)<br>
><br>
> Modified: llvm/trunk/test/CodeGen/X86/tail-call-got.ll<br>
> URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_llvm_trunk_test_CodeGen_X86_tail-2Dcall-2Dgot.ll-3Frev-3D238487-26r1-3D238486-26r2-3D238487-26view-3Ddiff&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=gT-_LpdN2R8aXJn6udjVIneiNb_l219Lg620INe464o&s=w0Ql4EHwNNGp2i8l8ryMM3TzSUHFHNCRAoR5Qk5P7Xg&e=" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/tail-call-got.ll?rev=238487&r1=238486&r2=238487&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/test/CodeGen/X86/tail-call-got.ll (original)<br>
> +++ llvm/trunk/test/CodeGen/X86/tail-call-got.ll Thu May 28 15:44:28 2015<br>
> @@ -1,12 +1,14 @@<br>
> ; RUN: llc < %s -relocation-model=pic -mattr=+sse2 | FileCheck %s<br>
><br>
> +; We used to do tail calls through the GOT for these symbols, but it was<br>
> +; disabled due to PR15086.<br>
> +<br>
> target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32"<br>
> target triple = "i386-unknown-freebsd9.0"<br>
><br>
> define double @test1(double %x) nounwind readnone {<br>
> ; CHECK-LABEL: test1:<br>
> -; CHECK: movl foo@GOT<br>
> -; CHECK-NEXT: jmpl<br>
> +; CHECK: calll foo@PLT<br>
> %1 = tail call double @foo(double %x) nounwind readnone<br>
> ret double %1<br>
> }<br>
> @@ -15,10 +17,18 @@ declare double @foo(double) readnone<br>
><br>
> define double @test2(double %x) nounwind readnone {<br>
> ; CHECK-LABEL: test2:<br>
> -; CHECK: movl sin@GOT<br>
> -; CHECK-NEXT: jmpl<br>
> +; CHECK: calll sin@PLT<br>
> %1 = tail call double @sin(double %x) nounwind readnone<br>
> ret double %1<br>
> }<br>
><br>
> declare double @sin(double) readnone<br>
> +<br>
> +define double @test3(double %x) nounwind readnone {<br>
> +; CHECK-LABEL: test3:<br>
> +; CHECK: calll sin2@PLT<br>
> + %1 = tail call double @sin2(double %x) nounwind readnone<br>
> + ret double %1<br>
> +}<br>
> +<br>
> +declare double @sin2(double) readnone<br>
><br>
> Modified: llvm/trunk/test/CodeGen/X86/tailcallpic1.ll<br>
> URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_llvm_trunk_test_CodeGen_X86_tailcallpic1.ll-3Frev-3D238487-26r1-3D238486-26r2-3D238487-26view-3Ddiff&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=gT-_LpdN2R8aXJn6udjVIneiNb_l219Lg620INe464o&s=vCdRbUKi6eYlRNkAZbEOMhgM7gwcl_NkalirVMBMth8&e=" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/tailcallpic1.ll?rev=238487&r1=238486&r2=238487&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/test/CodeGen/X86/tailcallpic1.ll (original)<br>
> +++ llvm/trunk/test/CodeGen/X86/tailcallpic1.ll Thu May 28 15:44:28 2015<br>
> @@ -1,5 +1,8 @@<br>
> ; RUN: llc < %s -tailcallopt -mtriple=i686-pc-linux-gnu -relocation-model=pic | FileCheck %s<br>
><br>
> +; This test uses guaranteed TCO so these will be tail calls, despite the early<br>
> +; binding issues.<br>
> +<br>
> define protected fastcc i32 @tailcallee(i32 %a1, i32 %a2, i32 %a3, i32 %a4) {<br>
> entry:<br>
> ret i32 %a3<br>
><br>
> Added: llvm/trunk/test/CodeGen/X86/tailcallpic3.ll<br>
> URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_llvm_trunk_test_CodeGen_X86_tailcallpic3.ll-3Frev-3D238487-26view-3Dauto&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=gT-_LpdN2R8aXJn6udjVIneiNb_l219Lg620INe464o&s=DPPVJryXsCirw7HTgcEKcslTZeInORBwzc_d_G2Gv0E&e=" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/tailcallpic3.ll?rev=238487&view=auto</a><br>
> ==============================================================================<br>
> --- llvm/trunk/test/CodeGen/X86/tailcallpic3.ll (added)<br>
> +++ llvm/trunk/test/CodeGen/X86/tailcallpic3.ll Thu May 28 15:44:28 2015<br>
> @@ -0,0 +1,73 @@<br>
> +; RUN: llc < %s -mtriple=i686-pc-linux-gnu -relocation-model=pic | FileCheck %s<br>
> +<br>
> +; While many of these could be tail called, we don't do it because it forces<br>
> +; early binding.<br>
> +<br>
> +declare void @external()<br>
> +<br>
> +define hidden void @tailcallee_hidden() {<br>
> +entry:<br>
> + ret void<br>
> +}<br>
> +<br>
> +define void @tailcall_hidden() {<br>
> +entry:<br>
> + tail call void @tailcallee_hidden()<br>
> + ret void<br>
> +}<br>
> +; CHECK: tailcall_hidden:<br>
> +; CHECK: jmp tailcallee_hidden<br>
> +<br>
> +define internal void @tailcallee_internal() {<br>
> +entry:<br>
> + ret void<br>
> +}<br>
> +<br>
> +define void @tailcall_internal() {<br>
> +entry:<br>
> + tail call void @tailcallee_internal()<br>
> + ret void<br>
> +}<br>
> +; CHECK: tailcall_internal:<br>
> +; CHECK: jmp tailcallee_internal<br>
> +<br>
> +define default void @tailcallee_default() {<br>
> +entry:<br>
> + ret void<br>
> +}<br>
> +<br>
> +define void @tailcall_default() {<br>
> +entry:<br>
> + tail call void @tailcallee_default()<br>
> + ret void<br>
> +}<br>
> +; CHECK: tailcall_default:<br>
> +; CHECK: calll tailcallee_default@PLT<br>
> +<br>
> +define void @tailcallee_default_implicit() {<br>
> +entry:<br>
> + ret void<br>
> +}<br>
> +<br>
> +define void @tailcall_default_implicit() {<br>
> +entry:<br>
> + tail call void @tailcallee_default_implicit()<br>
> + ret void<br>
> +}<br>
> +; CHECK: tailcall_default_implicit:<br>
> +; CHECK: calll tailcallee_default_implicit@PLT<br>
> +<br>
> +define void @tailcall_external() {<br>
> + tail call void @external()<br>
> + ret void<br>
> +}<br>
> +; CHECK: tailcall_external:<br>
> +; CHECK: calll external@PLT<br>
> +<br>
> +define void @musttail_external() {<br>
> + musttail call void @external()<br>
> + ret void<br>
> +}<br>
> +; CHECK: musttail_external:<br>
> +; CHECK: movl external@GOT<br>
> +; CHECK: jmpl<br>
><br>
><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>
<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>
</div></div></blockquote></div><br></div>