1 ; RUN: llc -mtriple=arm64-none-linux-gnu -verify-machineinstrs -show-mc-encoding < %s | FileCheck %s
2 ; RUN: llc -mtriple=arm64-none-linux-gnu -filetype=obj < %s | llvm-objdump -r - | FileCheck --check-prefix=CHECK-RELOC %s
3 ; RUN: llc -mtriple=arm64-none-linux-gnu -verify-machineinstrs -show-mc-encoding -code-model=tiny < %s | FileCheck %s --check-prefix=CHECK-TINY
4 ; RUN: llc -mtriple=arm64-none-linux-gnu -filetype=obj < %s -code-model=tiny | llvm-objdump -r - | FileCheck --check-prefix=CHECK-TINY-RELOC %s
5 ; FIXME: We currently error for the large code model
6 ; RUN: not llc -mtriple=arm64-none-linux-gnu -verify-machineinstrs -show-mc-encoding -code-model=large < %s 2>&1 | FileCheck %s --check-prefix=CHECK-LARGE
8 ; CHECK-LARGE: ELF TLS only supported in small memory model
10 @initial_exec_var = external thread_local(initialexec) global i32
12 define i32 @test_initial_exec() {
13 ; CHECK-LABEL: test_initial_exec:
14 %val = load i32, i32* @initial_exec_var
16 ; CHECK: adrp x[[GOTADDR:[0-9]+]], :gottprel:initial_exec_var
17 ; CHECK: ldr x[[TP_OFFSET:[0-9]+]], [x[[GOTADDR]], :gottprel_lo12:initial_exec_var]
18 ; CHECK: mrs x[[TP:[0-9]+]], TPIDR_EL0
19 ; CHECK: ldr w0, [x[[TP]], x[[TP_OFFSET]]]
21 ; CHECK-RELOC: R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
22 ; CHECK-RELOC: R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC
24 ; CHECK-TINY: ldr x[[TP_OFFSET:[0-9]+]], :gottprel:initial_exec_var
25 ; CHECK-TINY: mrs x[[TP:[0-9]+]], TPIDR_EL0
26 ; CHECK-TINY: ldr w0, [x[[TP]], x[[TP_OFFSET]]]
28 ; CHECK-TINY-RELOC: R_AARCH64_TLSIE_LD_GOTTPREL_PREL19
33 define i32* @test_initial_exec_addr() {
34 ; CHECK-LABEL: test_initial_exec_addr:
35 ret i32* @initial_exec_var
37 ; CHECK: adrp x[[GOTADDR:[0-9]+]], :gottprel:initial_exec_var
38 ; CHECK: ldr [[TP_OFFSET:x[0-9]+]], [x[[GOTADDR]], :gottprel_lo12:initial_exec_var]
39 ; CHECK: mrs [[TP:x[0-9]+]], TPIDR_EL0
40 ; CHECK: add x0, [[TP]], [[TP_OFFSET]]
42 ; CHECK-RELOC: R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
43 ; CHECK-RELOC: R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC
45 ; CHECK-TINY: ldr x[[TP_OFFSET:[0-9]+]], :gottprel:initial_exec_var
46 ; CHECK-TINY: mrs [[TP:x[0-9]+]], TPIDR_EL0
47 ; CHECK-TINY: add x0, [[TP]], x[[TP_OFFSET]]
49 ; CHECK-TINY-RELOC: R_AARCH64_TLSIE_LD_GOTTPREL_PREL19
53 @local_exec_var = thread_local(localexec) global i32 0
55 define i32 @test_local_exec() {
56 ; CHECK-LABEL: test_local_exec:
57 %val = load i32, i32* @local_exec_var
59 ; CHECK: mrs x[[R1:[0-9]+]], TPIDR_EL0
60 ; CHECK: add x[[R2:[0-9]+]], x[[R1]], :tprel_hi12:local_exec_var
61 ; CHECK: add x[[R3:[0-9]+]], x[[R2]], :tprel_lo12_nc:local_exec_var
62 ; CHECK: ldr w0, [x[[R3]]]
64 ; CHECK-RELOC: R_AARCH64_TLSLE_ADD_TPREL_HI12
65 ; CHECK-RELOC: R_AARCH64_TLSLE_ADD_TPREL_LO12_NC
67 ; CHECK-TINY: mrs x[[R1:[0-9]+]], TPIDR_EL0
68 ; CHECK-TINY: add x[[R2:[0-9]+]], x[[R1]], :tprel_hi12:local_exec_var
69 ; CHECK-TINY: add x[[R3:[0-9]+]], x[[R2]], :tprel_lo12_nc:local_exec_var
70 ; CHECK-TINY: ldr w0, [x[[R3]]]
72 ; CHECK-TINY-RELOC: R_AARCH64_TLSLE_ADD_TPREL_HI12
73 ; CHECK-TINY-RELOC: R_AARCH64_TLSLE_ADD_TPREL_LO12_NC
77 define i32* @test_local_exec_addr() {
78 ; CHECK-LABEL: test_local_exec_addr:
79 ret i32* @local_exec_var
81 ; CHECK: mrs x[[R1:[0-9]+]], TPIDR_EL0
82 ; CHECK: add x[[R2:[0-9]+]], x[[R1]], :tprel_hi12:local_exec_var
83 ; CHECK: add x0, x[[R2]], :tprel_lo12_nc:local_exec_var
86 ; CHECK-RELOC: R_AARCH64_TLSLE_ADD_TPREL_HI12
87 ; CHECK-RELOC: R_AARCH64_TLSLE_ADD_TPREL_LO12_NC
89 ; CHECK-TINY: mrs x[[R1:[0-9]+]], TPIDR_EL0
90 ; CHECK-TINY: add x[[R2:[0-9]+]], x[[R1]], :tprel_hi12:local_exec_var
91 ; CHECK-TINY: add x0, x[[R2]], :tprel_lo12_nc:local_exec_var
94 ; CHECK-TINY-RELOC: R_AARCH64_TLSLE_ADD_TPREL_HI12
95 ; CHECK-TINY-RELOC: R_AARCH64_TLSLE_ADD_TPREL_LO12_NC