Index: lib/Target/X86/X86ISelLowering.cpp =================================================================== --- lib/Target/X86/X86ISelLowering.cpp +++ lib/Target/X86/X86ISelLowering.cpp @@ -2753,6 +2753,11 @@ isTailCall = false; bool IsMustTail = CLI.CS && CLI.CS->isMustTailCall(); + + // Cannot jump to address through GOT, see https://llvm.org/bugs/show_bug.cgi?id=15086 + if (Subtarget->isPICStyleGOT()) + isTailCall = false; + if (IsMustTail) { // Force this to be a tail call. The verifier rules are enough to ensure // that we can lower this successfully without moving the return address @@ -2925,22 +2930,6 @@ if (!isTailCall) { RegsToPass.push_back(std::make_pair(unsigned(X86::EBX), DAG.getNode(X86ISD::GlobalBaseReg, SDLoc(), getPointerTy()))); - } else { - // If we are tail calling and generating PIC/GOT style code load the - // address of the callee into ECX. The value in ecx is used as target of - // the tail jump. This is done to circumvent the ebx/callee-saved problem - // for tail calls on PIC/GOT architectures. Normally we would just put the - // address of GOT into ebx and then call target@PLT. But for tail calls - // ebx would be restored (since ebx is callee saved) before jumping to the - // target@PLT. - - // Note: The actual moving to ECX is done further down. - GlobalAddressSDNode *G = dyn_cast(Callee); - if (G && !G->getGlobal()->hasHiddenVisibility() && - !G->getGlobal()->hasProtectedVisibility()) - Callee = LowerGlobalAddress(Callee, DAG); - else if (isa(Callee)) - Callee = LowerExternalSymbol(Callee, DAG); } } Index: test/CodeGen/X86/pic.ll =================================================================== --- test/CodeGen/X86/pic.ll +++ test/CodeGen/X86/pic.ll @@ -196,9 +196,11 @@ ; LINUX-NEXT: .LJTI7_0: ; LINUX: .long .LBB7_2@GOTOFF ; LINUX: .long .LBB7_8@GOTOFF -; LINUX: .long .LBB7_14@GOTOFF -; LINUX: .long .LBB7_9@GOTOFF -; LINUX: .long .LBB7_10@GOTOFF +; LINUX: .long .LBB7_4@GOTOFF +; LINUX: .long .LBB7_6@GOTOFF +; LINUX: .long .LBB7_5@GOTOFF +; LINUX: .long .LBB7_8@GOTOFF +; LINUX: .long .LBB7_7@GOTOFF } declare void @foo1(...) Index: test/CodeGen/X86/tail-call-got.ll =================================================================== --- test/CodeGen/X86/tail-call-got.ll +++ test/CodeGen/X86/tail-call-got.ll @@ -5,8 +5,7 @@ define double @test1(double %x) nounwind readnone { ; CHECK-LABEL: test1: -; CHECK: movl foo@GOT -; CHECK-NEXT: jmpl +; CHECK: calll foo@PLT %1 = tail call double @foo(double %x) nounwind readnone ret double %1 } @@ -15,8 +14,7 @@ define double @test2(double %x) nounwind readnone { ; CHECK-LABEL: test2: -; CHECK: movl sin@GOT -; CHECK-NEXT: jmpl +; CHECK: calll sin@PLT %1 = tail call double @sin(double %x) nounwind readnone ret double %1 } Index: test/CodeGen/X86/tailcallpic1.ll =================================================================== --- test/CodeGen/X86/tailcallpic1.ll +++ test/CodeGen/X86/tailcallpic1.ll @@ -9,5 +9,5 @@ entry: %tmp11 = tail call fastcc i32 @tailcallee( i32 %in1, i32 %in2, i32 %in1, i32 %in2 ) ; [#uses=1] ret i32 %tmp11 -; CHECK: jmp tailcallee +; CHECK: calll tailcallee } Index: test/CodeGen/X86/tailcallpic2.ll =================================================================== --- test/CodeGen/X86/tailcallpic2.ll +++ test/CodeGen/X86/tailcallpic2.ll @@ -9,7 +9,6 @@ entry: %tmp11 = tail call fastcc i32 @tailcallee( i32 %in1, i32 %in2, i32 %in1, i32 %in2 ) ; [#uses=1] ret i32 %tmp11 -; CHECK: movl tailcallee@GOT -; CHECK: jmpl +; CHECK: calll tailcallee@PLT }