X86-64 TLS support for local exec and initial exec.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@68947 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Target/X86/X86ISelLowering.cpp b/lib/Target/X86/X86ISelLowering.cpp
index ff8382a..825e31d 100644
--- a/lib/Target/X86/X86ISelLowering.cpp
+++ b/lib/Target/X86/X86ISelLowering.cpp
@@ -4831,12 +4831,14 @@
 // Lower ISD::GlobalTLSAddress using the "initial exec" (for no-pic) or
 // "local exec" model.
 static SDValue LowerToTLSExecModel(GlobalAddressSDNode *GA, SelectionDAG &DAG,
-                                   const MVT PtrVT, TLSModel::Model model) {
+                                   const MVT PtrVT, TLSModel::Model model,
+                                   bool is64Bit) {
   DebugLoc dl = GA->getDebugLoc();
   // Get the Thread Pointer
   SDValue Base = DAG.getNode(X86ISD::SegmentBaseAddress,
                              DebugLoc::getUnknownLoc(), PtrVT,
-                             DAG.getRegister(X86::GS, MVT::i32));
+                             DAG.getRegister(is64Bit? X86::FS : X86::GS,
+                                             MVT::i32));
 
   SDValue ThreadPointer = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), Base,
                                       NULL, 0);
@@ -4871,9 +4873,11 @@
     switch (model) {
     case TLSModel::GeneralDynamic:
     case TLSModel::LocalDynamic: // not implemented
-    case TLSModel::InitialExec:  // not implemented
-    case TLSModel::LocalExec:    // not implemented
       return LowerToTLSGeneralDynamicModel64(GA, DAG, getPointerTy());
+
+    case TLSModel::InitialExec:
+    case TLSModel::LocalExec:
+      return LowerToTLSExecModel(GA, DAG, getPointerTy(), model, true);
     }
   } else {
     switch (model) {
@@ -4883,7 +4887,7 @@
 
     case TLSModel::InitialExec:
     case TLSModel::LocalExec:
-      return LowerToTLSExecModel(GA, DAG, getPointerTy(), model);
+      return LowerToTLSExecModel(GA, DAG, getPointerTy(), model, false);
     }
   }
   assert(0 && "Unreachable");