// 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.
--- /dev/null
+; 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