[X86] Don't try to generate direct calls to TLS globals
authorMichael Kuperstein <michael.m.kuperstein@intel.com>
Thu, 8 Jan 2015 11:50:58 +0000 (11:50 +0000)
committerMichael Kuperstein <michael.m.kuperstein@intel.com>
Thu, 8 Jan 2015 11:50:58 +0000 (11:50 +0000)
The call lowering assumes that if the callee is a global, we want to emit a direct call.
This is correct for regular globals, but not for TLS ones.

Differential Revision: http://reviews.llvm.org/D6862

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@225438 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/X86/X86ISelLowering.cpp
test/CodeGen/X86/pr22103.ll [new file with mode: 0644]

index 29321472e259c3f72c1241d2a144556db45a4f76..9555dec9b8906462138b1cf7b9de34331098bb10 100644 (file)
@@ -3083,10 +3083,11 @@ X86TargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
     // through a register, since the call instruction's 32-bit
     // pc-relative offset may not be large enough to hold the whole
     // address.
-  } else if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) {
+  } else if (Callee->getOpcode() == ISD::GlobalAddress) {
     // If the callee is a GlobalAddress node (quite common, every direct call
     // is) turn it into a TargetGlobalAddress node so that legalize doesn't hack
     // it.
+    GlobalAddressSDNode* G = cast<GlobalAddressSDNode>(Callee);
 
     // We should use extra load for direct calls to dllimported functions in
     // non-JIT mode.
diff --git a/test/CodeGen/X86/pr22103.ll b/test/CodeGen/X86/pr22103.ll
new file mode 100644 (file)
index 0000000..324b6b5
--- /dev/null
@@ -0,0 +1,19 @@
+; RUN: llc < %s | FileCheck %s\r
+; Don't try to emit a direct call through a TLS global.\r
+; This fixes PR22103\r
+\r
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"\r
+target triple = "x86_64-unknown-linux-gnu"\r
+\r
+@a = external thread_local global i64\r
+\r
+; Function Attrs: nounwind\r
+define void @_Z1fv() {\r
+; CHECK-NOT: callq *$a\r
+; CHECK: movq %fs:0, [[RAX:%r..]]\r
+; CHECK-NEXT: addq    a@GOTTPOFF(%rip), [[RAX]]\r
+; CHECK-NEXT: callq *%rax\r
+entry:\r
+  call void bitcast (i64* @a to void ()*)()\r
+  ret void\r
+}\r