Skip to content

Commit ed38280

Browse files
ardbiesheuveltstellar
authored andcommitted
[ARM] Use hardware TLS register in Thumb2 mode when -mtp=cp15 is passed
In ARM mode, passing -mtp=cp15 forces the use of an inline MRC system register read to move the thread pointer value into a register. Currently, in Thumb2 mode, -mtp=cp15 is ignored, and a call to the __aeabi_read_tp helper is emitted instead. This is inconsistent, and breaks the Linux/ARM build for Thumb2 targets, as the Linux kernel does not provide an implementation of __aeabi_read_tp,. Reviewed By: nickdesaulniers, peter.smith Differential Revision: https://reviews.llvm.org/D112600 (cherry picked from commit d7e089f)
1 parent 216200a commit ed38280

File tree

4 files changed

+12
-2
lines changed

4 files changed

+12
-2
lines changed

llvm/lib/Target/ARM/ARMInstrThumb.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1520,6 +1520,7 @@ def tTBH_JT : tPseudoInst<(outs),
15201520
let isCall = 1, Defs = [R0, R12, LR, CPSR], Uses = [SP] in
15211521
def tTPsoft : tPseudoInst<(outs), (ins), 4, IIC_Br,
15221522
[(set R0, ARMthread_pointer)]>,
1523+
Requires<[IsThumb, IsReadTPSoft]>,
15231524
Sched<[WriteBr]>;
15241525

15251526
//===----------------------------------------------------------------------===//

llvm/lib/Target/ARM/ARMInstrThumb2.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4670,6 +4670,9 @@ def t2CDP2 : T2Cop<0b1111, (outs), (ins p_imm:$cop, imm0_15:$opc1,
46704670
}
46714671

46724672

4673+
// Reading thread pointer from coprocessor register
4674+
def : T2Pat<(ARMthread_pointer), (t2MRC 15, 0, 13, 0, 3)>,
4675+
Requires<[IsThumb2, IsReadTPHard]>;
46734676

46744677
//===----------------------------------------------------------------------===//
46754678
// ARMv8.1 Privilege Access Never extension

llvm/test/CodeGen/ARM/readtp.ll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
; RUN: llc -mtriple=armeb-linux-gnueabihf -O2 -mattr=+read-tp-hard %s -o - | FileCheck %s -check-prefix=CHECK-HARD
22
; RUN: llc -mtriple=armeb-linux-gnueabihf -O2 %s -o - | FileCheck %s -check-prefix=CHECK-SOFT
3+
; RUN: llc -mtriple=thumbv7-linux-gnueabihf -O2 -mattr=+read-tp-hard %s -o - | FileCheck %s -check-prefix=CHECK-HARD
4+
; RUN: llc -mtriple=thumbv7-linux-gnueabihf -O2 %s -o - | FileCheck %s -check-prefix=CHECK-SOFT
35

46

57
; __thread int counter;
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
; RUN: llc -mtriple arm-linux-gnueabi -filetype asm -o - %s | FileCheck %s
1+
; RUN: llc -mtriple arm-linux-gnueabi -o - %s | FileCheck %s -check-prefix=CHECK-SOFT
2+
; RUN: llc -mtriple arm-linux-gnueabi -mattr=+read-tp-hard -o - %s | FileCheck %s -check-prefix=CHECK-HARD
3+
; RUN: llc -mtriple thumbv7-linux-gnueabi -o - %s | FileCheck %s -check-prefix=CHECK-SOFT
4+
; RUN: llc -mtriple thumbv7-linux-gnueabi -mattr=+read-tp-hard -o - %s | FileCheck %s -check-prefix=CHECK-HARD
25

36
declare i8* @llvm.thread.pointer()
47

@@ -8,5 +11,6 @@ entry:
811
ret i8* %tmp1
912
}
1013

11-
; CHECK: bl __aeabi_read_tp
14+
; CHECK-SOFT: bl __aeabi_read_tp
15+
; CHECK-HARD: mrc p15, #0, {{r[0-9]+}}, c13, c0, #3
1216

0 commit comments

Comments
 (0)