Skip to content

Commit

Permalink
[ARM] Use hardware TLS register in Thumb2 mode when -mtp=cp15 is passed
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ardbiesheuvel authored and nickdesaulniers committed Oct 27, 2021
1 parent 33427fd commit d7e089f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions llvm/lib/Target/ARM/ARMInstrThumb.td
Original file line number Diff line number Diff line change
Expand Up @@ -1520,6 +1520,7 @@ def tTBH_JT : tPseudoInst<(outs),
let isCall = 1, Defs = [R0, R12, LR, CPSR], Uses = [SP] in
def tTPsoft : tPseudoInst<(outs), (ins), 4, IIC_Br,
[(set R0, ARMthread_pointer)]>,
Requires<[IsThumb, IsReadTPSoft]>,
Sched<[WriteBr]>;

//===----------------------------------------------------------------------===//
Expand Down
3 changes: 3 additions & 0 deletions llvm/lib/Target/ARM/ARMInstrThumb2.td
Original file line number Diff line number Diff line change
Expand Up @@ -4671,6 +4671,9 @@ def t2CDP2 : T2Cop<0b1111, (outs), (ins p_imm:$cop, imm0_15:$opc1,
}


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

//===----------------------------------------------------------------------===//
// ARMv8.1 Privilege Access Never extension
Expand Down
2 changes: 2 additions & 0 deletions llvm/test/CodeGen/ARM/readtp.ll
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
; RUN: llc -mtriple=armeb-linux-gnueabihf -O2 -mattr=+read-tp-hard %s -o - | FileCheck %s -check-prefix=CHECK-HARD
; RUN: llc -mtriple=armeb-linux-gnueabihf -O2 %s -o - | FileCheck %s -check-prefix=CHECK-SOFT
; RUN: llc -mtriple=thumbv7-linux-gnueabihf -O2 -mattr=+read-tp-hard %s -o - | FileCheck %s -check-prefix=CHECK-HARD
; RUN: llc -mtriple=thumbv7-linux-gnueabihf -O2 %s -o - | FileCheck %s -check-prefix=CHECK-SOFT


; __thread int counter;
Expand Down
8 changes: 6 additions & 2 deletions llvm/test/CodeGen/ARM/thread_pointer.ll
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
; RUN: llc -mtriple arm-linux-gnueabi -filetype asm -o - %s | FileCheck %s
; RUN: llc -mtriple arm-linux-gnueabi -o - %s | FileCheck %s -check-prefix=CHECK-SOFT
; RUN: llc -mtriple arm-linux-gnueabi -mattr=+read-tp-hard -o - %s | FileCheck %s -check-prefix=CHECK-HARD
; RUN: llc -mtriple thumbv7-linux-gnueabi -o - %s | FileCheck %s -check-prefix=CHECK-SOFT
; RUN: llc -mtriple thumbv7-linux-gnueabi -mattr=+read-tp-hard -o - %s | FileCheck %s -check-prefix=CHECK-HARD

declare i8* @llvm.thread.pointer()

Expand All @@ -8,5 +11,6 @@ entry:
ret i8* %tmp1
}

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

0 comments on commit d7e089f

Please sign in to comment.