[llvm] r195439 - Revert r195318 as it causes miscompilation (PR18029)

Kostya Serebryany kcc at google.com
Fri Nov 22 02:30:40 PST 2013


Author: kcc
Date: Fri Nov 22 04:30:39 2013
New Revision: 195439

URL: http://llvm.org/viewvc/llvm-project?rev=195439&view=rev
Log:
Revert r195318 as it causes miscompilation (PR18029)


Modified:
    llvm/trunk/lib/Target/X86/X86ISelLowering.cpp
    llvm/trunk/test/CodeGen/X86/tail-call-got.ll
    llvm/trunk/test/CodeGen/X86/tailcallpic2.ll

Modified: llvm/trunk/lib/Target/X86/X86ISelLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86ISelLowering.cpp?rev=195439&r1=195438&r2=195439&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86ISelLowering.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86ISelLowering.cpp Fri Nov 22 04:30:39 2013
@@ -2665,15 +2665,21 @@ X86TargetLowering::LowerCall(TargetLower
       RegsToPass.push_back(std::make_pair(unsigned(X86::EBX),
                DAG.getNode(X86ISD::GlobalBaseReg, SDLoc(), getPointerTy())));
     } else {
-      // If we are tail calling a global or external symbol in GOT pic mode, we
-      // cannot use a direct jump, since that would make lazy dynamic linking
-      // impossible (see PR15086).  So pretend this is not a tail call, to
-      // prevent the optimization to a jump.
+      // 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 at PLT. But for tail calls
+      // ebx would be restored (since ebx is callee saved) before jumping to the
+      // target at PLT.
+
+      // Note: The actual moving to ECX is done further down.
       GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee);
-      if ((G && !G->getGlobal()->hasHiddenVisibility() &&
-          !G->getGlobal()->hasProtectedVisibility()) ||
-          isa<ExternalSymbolSDNode>(Callee))
-        isTailCall = false;
+      if (G && !G->getGlobal()->hasHiddenVisibility() &&
+          !G->getGlobal()->hasProtectedVisibility())
+        Callee = LowerGlobalAddress(Callee, DAG);
+      else if (isa<ExternalSymbolSDNode>(Callee))
+        Callee = LowerExternalSymbol(Callee, DAG);
     }
   }
 

Modified: llvm/trunk/test/CodeGen/X86/tail-call-got.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/tail-call-got.ll?rev=195439&r1=195438&r2=195439&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/tail-call-got.ll (original)
+++ llvm/trunk/test/CodeGen/X86/tail-call-got.ll Fri Nov 22 04:30:39 2013
@@ -5,7 +5,8 @@ target triple = "i386-unknown-freebsd9.0
 
 define double @test1(double %x) nounwind readnone {
 ; CHECK-LABEL: test1:
-; CHECK: calll foo at PLT
+; CHECK: movl foo at GOT
+; CHECK-NEXT: jmpl
   %1 = tail call double @foo(double %x) nounwind readnone
   ret double %1
 }
@@ -14,7 +15,8 @@ declare double @foo(double) readnone
 
 define double @test2(double %x) nounwind readnone {
 ; CHECK-LABEL: test2:
-; CHECK: calll sin at PLT
+; CHECK: movl sin at GOT
+; CHECK-NEXT: jmpl
   %1 = tail call double @sin(double %x) nounwind readnone
   ret double %1
 }

Modified: llvm/trunk/test/CodeGen/X86/tailcallpic2.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/tailcallpic2.ll?rev=195439&r1=195438&r2=195439&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/tailcallpic2.ll (original)
+++ llvm/trunk/test/CodeGen/X86/tailcallpic2.ll Fri Nov 22 04:30:39 2013
@@ -9,7 +9,7 @@ define fastcc i32 @tailcaller(i32 %in1,
 entry:
 	%tmp11 = tail call fastcc i32 @tailcallee( i32 %in1, i32 %in2, i32 %in1, i32 %in2 )		; <i32> [#uses=1]
 	ret i32 %tmp11
-; Note that this call via PLT could be further optimized into a direct call (no GOT, no PLT):
-; CHECK: calll tailcallee at PLT
+; CHECK: movl tailcallee at GOT
+; CHECK: jmpl
 }
 





More information about the llvm-commits mailing list