[llvm-commits] [llvm] r69350 - in /llvm/trunk: lib/Target/X86/X86ISelLowering.cpp lib/Target/X86/X86Instr64bit.td lib/Target/X86/X86InstrInfo.td test/CodeGen/X86/2009-04-17-tls-fast.ll
Rafael Espindola
rafael.espindola at gmail.com
Fri Apr 17 07:36:00 PDT 2009
Author: rafael
Date: Fri Apr 17 09:35:58 2009
New Revision: 69350
URL: http://llvm.org/viewvc/llvm-project?rev=69350&view=rev
Log:
For general dynamic TLS access we must use
leaq foo at TLSGD(%rip), %rdi
as part of the instruction sequence. Using a register other than %rdi and then
copying it to %rdi is not valid.
Added:
llvm/trunk/test/CodeGen/X86/2009-04-17-tls-fast.ll
Modified:
llvm/trunk/lib/Target/X86/X86ISelLowering.cpp
llvm/trunk/lib/Target/X86/X86Instr64bit.td
llvm/trunk/lib/Target/X86/X86InstrInfo.td
Modified: llvm/trunk/lib/Target/X86/X86ISelLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86ISelLowering.cpp?rev=69350&r1=69349&r2=69350&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86ISelLowering.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86ISelLowering.cpp Fri Apr 17 09:35:58 2009
@@ -4754,6 +4754,23 @@
return LowerGlobalAddress(GV, Op.getDebugLoc(), Offset, DAG);
}
+static SDValue
+GetTLSADDR(SelectionDAG &DAG, SDValue Chain, GlobalAddressSDNode *GA,
+ SDValue *InFlag) {
+ SDVTList NodeTys = DAG.getVTList(MVT::Other, MVT::Flag);
+ DebugLoc dl = GA->getDebugLoc();
+ SDValue TGA = DAG.getTargetGlobalAddress(GA->getGlobal(),
+ GA->getValueType(0),
+ GA->getOffset());
+ if (InFlag) {
+ SDValue Ops[] = { Chain, TGA, *InFlag };
+ return DAG.getNode(X86ISD::TLSADDR, dl, NodeTys, Ops, 3);
+ } else {
+ SDValue Ops[] = { Chain, TGA };
+ return DAG.getNode(X86ISD::TLSADDR, dl, NodeTys, Ops, 2);
+ }
+}
+
// Lower ISD::GlobalTLSAddress using the "general dynamic" model, 32 bit
static SDValue
LowerToTLSGeneralDynamicModel32(GlobalAddressSDNode *GA, SelectionDAG &DAG,
@@ -4766,22 +4783,10 @@
PtrVT), InFlag);
InFlag = Chain.getValue(1);
- // emit leal symbol at TLSGD(,%ebx,1), %eax
- SDVTList NodeTys = DAG.getVTList(PtrVT, MVT::Other, MVT::Flag);
- SDValue TGA = DAG.getTargetGlobalAddress(GA->getGlobal(),
- GA->getValueType(0),
- GA->getOffset());
- SDValue Ops[] = { Chain, TGA, InFlag };
- SDValue Result = DAG.getNode(X86ISD::TLSADDR, dl, NodeTys, Ops, 3);
- InFlag = Result.getValue(2);
- Chain = Result.getValue(1);
-
- // call ___tls_get_addr. This function receives its argument in
- // the register EAX.
- Chain = DAG.getCopyToReg(Chain, dl, X86::EAX, Result, InFlag);
+ Chain = GetTLSADDR(DAG, Chain, GA, &InFlag);
InFlag = Chain.getValue(1);
- NodeTys = DAG.getVTList(MVT::Other, MVT::Flag);
+ SDVTList NodeTys = DAG.getVTList(MVT::Other, MVT::Flag);
SDValue Ops1[] = { Chain,
DAG.getTargetExternalSymbol("___tls_get_addr",
PtrVT),
@@ -4801,22 +4806,10 @@
SDValue InFlag, Chain;
DebugLoc dl = GA->getDebugLoc(); // ? function entry point might be better
- // emit leaq symbol at TLSGD(%rip), %rdi
- SDVTList NodeTys = DAG.getVTList(PtrVT, MVT::Other, MVT::Flag);
- SDValue TGA = DAG.getTargetGlobalAddress(GA->getGlobal(),
- GA->getValueType(0),
- GA->getOffset());
- SDValue Ops[] = { DAG.getEntryNode(), TGA};
- SDValue Result = DAG.getNode(X86ISD::TLSADDR, dl, NodeTys, Ops, 2);
- Chain = Result.getValue(1);
- InFlag = Result.getValue(2);
-
- // call __tls_get_addr. This function receives its argument in
- // the register RDI.
- Chain = DAG.getCopyToReg(Chain, dl, X86::RDI, Result, InFlag);
+ Chain = GetTLSADDR(DAG, DAG.getEntryNode(), GA, NULL);
InFlag = Chain.getValue(1);
- NodeTys = DAG.getVTList(MVT::Other, MVT::Flag);
+ SDVTList NodeTys = DAG.getVTList(MVT::Other, MVT::Flag);
SDValue Ops1[] = { Chain,
DAG.getTargetExternalSymbol("__tls_get_addr",
PtrVT),
Modified: llvm/trunk/lib/Target/X86/X86Instr64bit.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86Instr64bit.td?rev=69350&r1=69349&r2=69350&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86Instr64bit.td (original)
+++ llvm/trunk/lib/Target/X86/X86Instr64bit.td Fri Apr 17 09:35:58 2009
@@ -1303,9 +1303,11 @@
// Thread Local Storage Instructions
//===----------------------------------------------------------------------===//
-def TLS_addr64 : I<0, Pseudo, (outs GR64:$dst), (ins i64imm:$sym),
- ".byte\t0x66; leaq\t${sym:mem}(%rip), $dst; .word\t0x6666; rex64",
- [(set GR64:$dst, (X86tlsaddr tglobaltlsaddr:$sym))]>;
+let hasSideEffects = 1, Uses = [RDI] in
+def TLS_addr64 : I<0, Pseudo, (outs), (ins i64imm:$sym),
+ ".byte\t0x66; leaq\t${sym:mem}(%rip), %rdi; .word\t0x6666; rex64",
+ [(X86tlsaddr tglobaltlsaddr:$sym)]>,
+ Requires<[In64BitMode]>;
let AddedComplexity = 5 in
def MOV64GSrm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
Modified: llvm/trunk/lib/Target/X86/X86InstrInfo.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86InstrInfo.td?rev=69350&r1=69349&r2=69350&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86InstrInfo.td (original)
+++ llvm/trunk/lib/Target/X86/X86InstrInfo.td Fri Apr 17 09:35:58 2009
@@ -63,7 +63,7 @@
def SDTX86Wrapper : SDTypeProfile<1, 1, [SDTCisSameAs<0, 1>, SDTCisPtrTy<0>]>;
-def SDT_X86TLSADDR : SDTypeProfile<1, 1, [SDTCisPtrTy<0>, SDTCisInt<1>]>;
+def SDT_X86TLSADDR : SDTypeProfile<0, 1, [SDTCisInt<0>]>;
def SDT_X86SegmentBaseAddress : SDTypeProfile<1, 1, [SDTCisPtrTy<0>]>;
@@ -2977,10 +2977,11 @@
// Thread Local Storage Instructions
//
-let Uses = [EBX] in
-def TLS_addr32 : I<0, Pseudo, (outs GR32:$dst), (ins i32imm:$sym),
- "leal\t${sym:mem}(,%ebx,1), $dst",
- [(set GR32:$dst, (X86tlsaddr tglobaltlsaddr:$sym))]>;
+let hasSideEffects = 1, Uses = [EAX, EBX] in
+def TLS_addr32 : I<0, Pseudo, (outs), (ins i32imm:$sym),
+ "leal\t${sym:mem}(,%ebx,1), %eax",
+ [(X86tlsaddr tglobaltlsaddr:$sym)]>,
+ Requires<[In32BitMode]>;
let AddedComplexity = 5 in
def GS_MOV32rm : I<0x8B, MRMSrcMem, (outs GR32:$dst), (ins i32mem:$src),
Added: llvm/trunk/test/CodeGen/X86/2009-04-17-tls-fast.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/2009-04-17-tls-fast.ll?rev=69350&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/X86/2009-04-17-tls-fast.ll (added)
+++ llvm/trunk/test/CodeGen/X86/2009-04-17-tls-fast.ll Fri Apr 17 09:35:58 2009
@@ -0,0 +1,17 @@
+; RUN: llvm-as < %s | llc -march=x86-64 -mtriple=x86_64-linux-gnu -relocation-model=pic -regalloc=local > %t
+; RUN: grep {leaq foo at TLSGD(%rip), %rdi} %t
+
+ at foo = internal thread_local global i32 100
+
+define void @f(i32 %n) nounwind {
+entry:
+ %n_addr = alloca i32
+ %p = alloca i32*
+ %"alloca point" = bitcast i32 0 to i32
+ store i32 %n, i32* %n_addr
+ store i32* @foo, i32** %p, align 8
+ br label %return
+
+return:
+ ret void
+}
More information about the llvm-commits
mailing list