Index: lib/Target/ARM/ARMExpandPseudoInsts.cpp =================================================================== --- lib/Target/ARM/ARMExpandPseudoInsts.cpp +++ lib/Target/ARM/ARMExpandPseudoInsts.cpp @@ -1242,7 +1242,7 @@ MachineConstantPoolValue *CPV = ARMConstantPoolSymbol::Create(MF->getFunction()->getContext(), "__aeabi_read_tp", PCLabelID, 0); - unsigned Reg = MI.getOperand(0).getReg(); + unsigned Reg = ARM::R0; MIB = BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(Thumb ? ARM::tLDRpci : ARM::LDRi12), Reg) .addConstantPoolIndex(MCP->getConstantPoolIndex(CPV, 4)); Index: lib/Target/ARM/ARMISelLowering.cpp =================================================================== --- lib/Target/ARM/ARMISelLowering.cpp +++ lib/Target/ARM/ARMISelLowering.cpp @@ -2892,8 +2892,6 @@ SDValue Offset; SDValue Chain = DAG.getEntryNode(); EVT PtrVT = getPointerTy(DAG.getDataLayout()); - // Get the Thread Pointer - SDValue ThreadPointer = DAG.getNode(ARMISD::THREAD_POINTER, dl, PtrVT); if (model == TLSModel::InitialExec) { MachineFunction &MF = DAG.getMachineFunction(); @@ -2930,9 +2928,12 @@ MachinePointerInfo::getConstantPool(DAG.getMachineFunction())); } + // Get the Thread Pointer, a call which will return the value into R0. + Chain = DAG.getNode(ARMISD::THREAD_POINTER, dl, MVT::Other, Chain); // The address of the thread local variable is the add of the thread // pointer with the offset of the variable. - return DAG.getNode(ISD::ADD, dl, PtrVT, ThreadPointer, Offset); + SDValue ThreadPointer = DAG.getCopyFromReg(Chain, dl, ARM::R0, PtrVT); + return DAG.getNode(ISD::ADD, dl, PtrVT, ThreadPointer.getValue(0), Offset); } SDValue @@ -3285,7 +3286,9 @@ default: return SDValue(); // Don't custom lower most intrinsics. case Intrinsic::thread_pointer: { EVT PtrVT = getPointerTy(DAG.getDataLayout()); - return DAG.getNode(ARMISD::THREAD_POINTER, dl, PtrVT); + SDValue ThreadPointer = DAG.getNode(ARMISD::THREAD_POINTER, dl, MVT::Other, + DAG.getEntryNode()); + return DAG.getCopyFromReg(ThreadPointer, dl, ARM::R0, PtrVT); } case Intrinsic::eh_sjlj_lsda: { MachineFunction &MF = DAG.getMachineFunction(); Index: lib/Target/ARM/ARMInstrInfo.td =================================================================== --- lib/Target/ARM/ARMInstrInfo.td +++ lib/Target/ARM/ARMInstrInfo.td @@ -57,7 +57,7 @@ def SDT_ARMPICAdd : SDTypeProfile<1, 2, [SDTCisSameAs<0, 1>, SDTCisPtrTy<1>, SDTCisVT<2, i32>]>; -def SDT_ARMThreadPointer : SDTypeProfile<1, 0, [SDTCisPtrTy<0>]>; +def SDT_ARMThreadPointer : SDTypeProfile<0, 0, []>; def SDT_ARMEH_SJLJ_Setjmp : SDTypeProfile<1, 2, [SDTCisInt<0>, SDTCisPtrTy<1>, SDTCisInt<2>]>; def SDT_ARMEH_SJLJ_Longjmp: SDTypeProfile<0, 2, [SDTCisPtrTy<0>, SDTCisInt<1>]>; @@ -165,7 +165,8 @@ def ARMadde : SDNode<"ARMISD::ADDE", SDTBinaryArithWithFlagsInOut>; def ARMsube : SDNode<"ARMISD::SUBE", SDTBinaryArithWithFlagsInOut>; -def ARMthread_pointer: SDNode<"ARMISD::THREAD_POINTER", SDT_ARMThreadPointer>; +def ARMthread_pointer: SDNode<"ARMISD::THREAD_POINTER", SDT_ARMThreadPointer, + [SDNPHasChain, SDNPSideEffect]>; def ARMeh_sjlj_setjmp: SDNode<"ARMISD::EH_SJLJ_SETJMP", SDT_ARMEH_SJLJ_Setjmp, [SDNPHasChain, SDNPSideEffect]>; @@ -5449,7 +5450,7 @@ let isCall = 1, Defs = [R0, R12, LR, CPSR], Uses = [SP] in { def TPsoft : ARMPseudoInst<(outs), (ins), 4, IIC_Br, - [(set R0, ARMthread_pointer)]>, Sched<[WriteBr]>; + [(ARMthread_pointer)]>, Sched<[WriteBr]>; } //===----------------------------------------------------------------------===// Index: lib/Target/ARM/ARMInstrThumb.td =================================================================== --- lib/Target/ARM/ARMInstrThumb.td +++ lib/Target/ARM/ARMInstrThumb.td @@ -1431,7 +1431,7 @@ // complete with fixup for the aeabi_read_tp function. let isCall = 1, Defs = [R0, R12, LR, CPSR], Uses = [SP] in def tTPsoft : tPseudoInst<(outs), (ins), 4, IIC_Br, - [(set R0, ARMthread_pointer)]>, + [(ARMthread_pointer)]>, Sched<[WriteBr]>; //===----------------------------------------------------------------------===// Index: test/CodeGen/ARM/2010-12-08-tpsoft.ll =================================================================== --- test/CodeGen/ARM/2010-12-08-tpsoft.ll +++ test/CodeGen/ARM/2010-12-08-tpsoft.ll @@ -28,9 +28,9 @@ ; ELFOBJ: Section { ; ELFOBJ: Name: .text ; ELFOBJ: SectionData ( -;;; BL __aeabi_read_tp is ---------+ -;;; V -; ELFOBJ-NEXT: 0000: 00482DE9 3C009FE5 00109FE7 FEFFFFEB +;;; BL __aeabi_read_tp is + +;;; V +; ELFOBJ-NEXT: 0000: 00482DE9 3C109FE5 FEFFFFEB 01109FE7 bb1: ; preds = %entry Index: test/CodeGen/ARM/aeabi-read-tp.ll =================================================================== --- test/CodeGen/ARM/aeabi-read-tp.ll +++ test/CodeGen/ARM/aeabi-read-tp.ll @@ -12,14 +12,14 @@ } ; CHECK-LABEL: f: -; CHECK-SHORT: ldr r1, [[VAR:.LCPI[0-9]+_[0-9]+]] -; CHECK-SHORT-NEXT: bl __aeabi_read_tp +; CHECK-SHORT: bl __aeabi_read_tp +; CHECK-SHORT-NEXT: ldr r1, [[VAR:.LCPI[0-9]+_[0-9]+]] ; CHECK-SHORT: [[VAR]]: ; CHECK-SHORT-NEXT: .long i(TPOFF) ; CHECK-LONG: ldr [[REG:r[0-9]+]], [[FUN:.LCPI[0-9]+_[0-9]+]] -; CHECK-LONG-NEXT: ldr r1, [[VAR:.LCPI[0-9]+_[0-9]+]] ; CHECK-LONG-NEXT: blx [[REG]] +; CHECK-LONG-NEXT: ldr r1, [[VAR:.LCPI[0-9]+_[0-9]+]] ; CHECK-LONG: [[VAR]]: ; CHECK-LONG-NEXT: .long i(TPOFF) ; CHECK-LONG: [[FUN]]: Index: test/CodeGen/Thumb2/tls2.ll =================================================================== --- test/CodeGen/Thumb2/tls2.ll +++ test/CodeGen/Thumb2/tls2.ll @@ -6,9 +6,14 @@ define i32 @f() { entry: ; CHECK-NOT-PIC-LABEL: f: -; CHECK-NOT-PIC: add r0, pc -; CHECK-NOT-PIC: ldr r1, [r0] -; CHECK-NOT-PIC: i(GOTTPOFF) +; CHECK-NOT-PIC: ldr r1, [[LCP:.*]] +; CHECK-NOT-PIC: bl __aeabi_read_tp +; CHECK-NOT-PIC: add r1, pc +; CHECK-NOT-PIC: ldr r1, [r1] +; CHECK-NOT-PIC: ldr r0, [r0, r1] +; CHECK-NOT-PIC: [[LCP]] +; CHECK-NOT-PIC-NEXT: .L +; CHECK-NOT-PIC-NEXT: i(GOTTPOFF) ; CHECK-PIC-LABEL: f: ; CHECK-PIC: bl __tls_get_addr @@ -19,9 +24,14 @@ define i32* @g() { entry: ; CHECK-NOT-PIC-LABEL: g: -; CHECK-NOT-PIC: add r0, pc -; CHECK-NOT-PIC: ldr r1, [r0] -; CHECK-NOT-PIC: i(GOTTPOFF) +; CHECK-NOT-PIC: ldr r1, [[LCP:.*]] +; CHECK-NOT-PIC: bl __aeabi_read_tp +; CHECK-NOT-PIC: add r1, pc +; CHECK-NOT-PIC: ldr r1, [r1] +; CHECK-NOT-PIC: add r0, r1 +; CHECK-NOT-PIC: [[LCP]] +; CHECK-NOT-PIC-NEXT: .L +; CHECK-NOT-PIC-NEXT: i(GOTTPOFF) ; CHECK-PIC-LABEL: g: ; CHECK-PIC: bl __tls_get_addr Index: test/CodeGen/Thumb2/tpsoft.ll =================================================================== --- test/CodeGen/Thumb2/tpsoft.ll +++ test/CodeGen/Thumb2/tpsoft.ll @@ -32,13 +32,13 @@ ; ELFOBJ: Section { ; ELFOBJ: Name: .text ; ELFOBJ-LE: SectionData ( -;;; BL __aeabi_read_tp is ---+ -;;; V -; ELFOBJ-LE-NEXT: 0000: 80B50E48 78440168 FFF7FEFF 40580D28 +;;; BL __aeabi_read_tp is -+ +;;; V +; ELFOBJ-LE-NEXT: 0000: 80B50E49 FFF7FEFF 79440968 40580D28 ; ELFOBJ-BE: SectionData ( -;;; BL __aeabi_read_tp is ---+ -;;; V -; ELFOBJ-BE-NEXT: 0000: B580480E 44786801 F7FFFFFE 5840280D +;;; BL __aeabi_read_tp is -+ +;;; V +; ELFOBJ-BE-NEXT: 0000: B580490E F7FFFFFE 44796809 5840280D bb1: ; preds = %entry