• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; Verify the call site info. If the call site info is not
2; in the valid state, an assert should be triggered.
3; RUN: llc < %s -debug-entry-values -mtriple=arm64-none-linux-gnu -stop-after=machineverifier -relocation-model=pic -aarch64-elf-ldtls-generation=1 < %s
4
5; RUN: llc -mtriple=arm64-none-linux-gnu -relocation-model=pic -aarch64-elf-ldtls-generation=1 -verify-machineinstrs < %s | FileCheck %s
6; RUN: llc -mtriple=arm64-none-linux-gnu -relocation-model=pic -aarch64-elf-ldtls-generation=1 -filetype=obj < %s | llvm-objdump -r - | FileCheck --check-prefix=CHECK-RELOC %s
7; RUN: llc -mtriple=arm64-none-linux-gnu -relocation-model=pic -verify-machineinstrs < %s | FileCheck --check-prefix=CHECK-NOLD %s
8; RUN: llc -mtriple=arm64-none-linux-gnu -relocation-model=pic -filetype=obj < %s | llvm-objdump -r - | FileCheck --check-prefix=CHECK-NOLD-RELOC %s
9; FIXME: We currently produce "small" code for the tiny model
10; RUN: llc -mtriple=arm64-none-linux-gnu -relocation-model=pic -aarch64-elf-ldtls-generation=1 -code-model=tiny -verify-machineinstrs < %s | FileCheck %s
11; FIXME: We currently error for the large code model
12; RUN: not --crash llc -mtriple=arm64-none-linux-gnu -relocation-model=pic -aarch64-elf-ldtls-generation=1 -code-model=large -verify-machineinstrs < %s 2>&1 | FileCheck %s --check-prefix=CHECK-LARGE
13
14; CHECK-LARGE: ELF TLS only supported in small memory model
15
16@general_dynamic_var = external thread_local global i32
17
18define i32 @test_generaldynamic() {
19; CHECK-LABEL: test_generaldynamic:
20
21  %val = load i32, i32* @general_dynamic_var
22  ret i32 %val
23
24; CHECK: adrp x[[TLSDESC_HI:[0-9]+]], :tlsdesc:general_dynamic_var
25; CHECK-NEXT: ldr [[CALLEE:x[0-9]+]], [x[[TLSDESC_HI]], :tlsdesc_lo12:general_dynamic_var]
26; CHECK-NEXT: add x0, x[[TLSDESC_HI]], :tlsdesc_lo12:general_dynamic_var
27; CHECK-NEXT: .tlsdesccall general_dynamic_var
28; CHECK-NEXT: blr [[CALLEE]]
29
30; CHECK-NOLD: adrp x[[TLSDESC_HI:[0-9]+]], :tlsdesc:general_dynamic_var
31; CHECK-NOLD-NEXT: ldr [[CALLEE:x[0-9]+]], [x[[TLSDESC_HI]], :tlsdesc_lo12:general_dynamic_var]
32; CHECK-NOLD-NEXT: add x0, x[[TLSDESC_HI]], :tlsdesc_lo12:general_dynamic_var
33; CHECK-NOLD-NEXT: .tlsdesccall general_dynamic_var
34; CHECK-NOLD-NEXT: blr [[CALLEE]]
35
36
37; CHECK: mrs x[[TP:[0-9]+]], TPIDR_EL0
38; CHECK: ldr w0, [x[[TP]], x0]
39; CHECK-NOLD: mrs x[[TP:[0-9]+]], TPIDR_EL0
40; CHECK-NOLD: ldr w0, [x[[TP]], x0]
41
42; CHECK-RELOC: R_AARCH64_TLSDESC_ADR_PAGE21
43; CHECK-RELOC: R_AARCH64_TLSDESC_LD64_LO12
44; CHECK-RELOC: R_AARCH64_TLSDESC_ADD_LO12
45; CHECK-RELOC: R_AARCH64_TLSDESC_CALL
46
47; CHECK-NOLD-RELOC: R_AARCH64_TLSDESC_ADR_PAGE21
48; CHECK-NOLD-RELOC: R_AARCH64_TLSDESC_LD64_LO12
49; CHECK-NOLD-RELOC: R_AARCH64_TLSDESC_ADD_LO12
50; CHECK-NOLD-RELOC: R_AARCH64_TLSDESC_CALL
51
52}
53
54define i32* @test_generaldynamic_addr() {
55; CHECK-LABEL: test_generaldynamic_addr:
56
57  ret i32* @general_dynamic_var
58
59; CHECK: adrp x[[TLSDESC_HI:[0-9]+]], :tlsdesc:general_dynamic_var
60; CHECK-NEXT: ldr [[CALLEE:x[0-9]+]], [x[[TLSDESC_HI]], :tlsdesc_lo12:general_dynamic_var]
61; CHECK-NEXT: add x0, x[[TLSDESC_HI]], :tlsdesc_lo12:general_dynamic_var
62; CHECK-NEXT: .tlsdesccall general_dynamic_var
63; CHECK-NEXT: blr [[CALLEE]]
64
65; CHECK: mrs [[TP:x[0-9]+]], TPIDR_EL0
66; CHECK: add x0, [[TP]], x0
67
68; CHECK-RELOC: R_AARCH64_TLSDESC_ADR_PAGE21
69; CHECK-RELOC: R_AARCH64_TLSDESC_LD64_LO12
70; CHECK-RELOC: R_AARCH64_TLSDESC_ADD_LO12
71; CHECK-RELOC: R_AARCH64_TLSDESC_CALL
72
73; CHECK-NOLD-RELOC: R_AARCH64_TLSDESC_ADR_PAGE21
74; CHECK-NOLD-RELOC: R_AARCH64_TLSDESC_LD64_LO12
75; CHECK-NOLD-RELOC: R_AARCH64_TLSDESC_ADD_LO12
76; CHECK-NOLD-RELOC: R_AARCH64_TLSDESC_CALL
77
78}
79
80@local_dynamic_var = external thread_local(localdynamic) global i32
81
82define i32 @test_localdynamic() {
83; CHECK-LABEL: test_localdynamic:
84
85  %val = load i32, i32* @local_dynamic_var
86  ret i32 %val
87
88; CHECK: adrp x[[TLSDESC_HI:[0-9]+]], :tlsdesc:_TLS_MODULE_BASE_
89; CHECK-NEXT: ldr [[CALLEE:x[0-9]+]], [x[[TLSDESC_HI]], :tlsdesc_lo12:_TLS_MODULE_BASE_]
90; CHECK-NEXT: add x0, x[[TLSDESC_HI]], :tlsdesc_lo12:_TLS_MODULE_BASE_
91; CHECK-NEXT: .tlsdesccall _TLS_MODULE_BASE_
92; CHECK-NEXT: blr [[CALLEE]]
93; CHECK-NEXT: add x[[TPOFF:[0-9]+]], x0, :dtprel_hi12:local_dynamic_var
94; CHECK-NEXT: add x[[TPOFF]], x[[TPOFF]], :dtprel_lo12_nc:local_dynamic_var
95; CHECK: mrs x[[TPIDR:[0-9]+]], TPIDR_EL0
96; CHECK: ldr w0, [x[[TPIDR]], x[[TPOFF]]]
97
98; CHECK-NOLD: adrp x[[TLSDESC_HI:[0-9]+]], :tlsdesc:local_dynamic_var
99; CHECK-NOLD-NEXT: ldr [[CALLEE:x[0-9]+]], [x[[TLSDESC_HI]], :tlsdesc_lo12:local_dynamic_var]
100; CHECK-NOLD-NEXT: add x0, x[[TLSDESC_HI]], :tlsdesc_lo12:local_dynamic_var
101; CHECK-NOLD-NEXT: .tlsdesccall local_dynamic_var
102; CHECK-NOLD-NEXT: blr [[CALLEE]]
103; CHECK-NOLD: mrs x[[TPIDR:[0-9]+]], TPIDR_EL0
104; CHECK-NOLD: ldr w0, [x[[TPIDR]], x0]
105
106
107; CHECK-RELOC: R_AARCH64_TLSDESC_ADR_PAGE21
108; CHECK-RELOC: R_AARCH64_TLSDESC_LD64_LO12
109; CHECK-RELOC: R_AARCH64_TLSDESC_ADD_LO12
110; CHECK-RELOC: R_AARCH64_TLSDESC_CALL
111; CHECK-RELOC: R_AARCH64_TLSLD_ADD_DTPREL_HI12
112; CHECK-RELOC: R_AARCH64_TLSLD_ADD_DTPREL_LO12_NC
113
114; CHECK-NOLD-RELOC: R_AARCH64_TLSDESC_ADR_PAGE21
115; CHECK-NOLD-RELOC: R_AARCH64_TLSDESC_LD64_LO12
116; CHECK-NOLD-RELOC: R_AARCH64_TLSDESC_ADD_LO12
117; CHECK-NOLD-RELOC: R_AARCH64_TLSDESC_CALL
118
119}
120
121define i32* @test_localdynamic_addr() {
122; CHECK-LABEL: test_localdynamic_addr:
123
124; CHECK: adrp x[[TLSDESC_HI:[0-9]+]], :tlsdesc:_TLS_MODULE_BASE_
125; CHECK-NEXT: ldr [[CALLEE:x[0-9]+]], [x[[TLSDESC_HI]], :tlsdesc_lo12:_TLS_MODULE_BASE_]
126; CHECK-NEXT: add x0, x[[TLSDESC_HI]], :tlsdesc_lo12:_TLS_MODULE_BASE_
127; CHECK-NEXT: .tlsdesccall _TLS_MODULE_BASE_
128; CHECK-NEXT: blr [[CALLEE]]
129; CHECK-NEXT: add x[[TPOFF:[0-9]+]], x0, :dtprel_hi12:local_dynamic_var
130; CHECK-NEXT: add x[[TPOFF]], x[[TPOFF]], :dtprel_lo12_nc:local_dynamic_var
131; CHECK: mrs x[[TPIDR:[0-9]+]], TPIDR_EL0
132; CHECK: add x0, x[[TPIDR]], x[[TPOFF]]
133
134; CHECK-NOLD: adrp x[[TLSDESC_HI:[0-9]+]], :tlsdesc:local_dynamic_var
135; CHECK-NOLD-NEXT: ldr [[CALLEE:x[0-9]+]], [x[[TLSDESC_HI]], :tlsdesc_lo12:local_dynamic_var]
136; CHECK-NOLD-NEXT: add x0, x[[TLSDESC_HI]], :tlsdesc_lo12:local_dynamic_var
137; CHECK-NOLD-NEXT: .tlsdesccall local_dynamic_var
138; CHECK-NOLD-NEXT: blr [[CALLEE]]
139; CHECK-NOLD: mrs x[[TPIDR:[0-9]+]], TPIDR_EL0
140; CHECK-NOLD: add x0, x[[TPIDR]], x0
141  ret i32* @local_dynamic_var
142
143; CHECK-RELOC: R_AARCH64_TLSDESC_ADR_PAGE21
144; CHECK-RELOC: R_AARCH64_TLSDESC_LD64_LO12
145; CHECK-RELOC: R_AARCH64_TLSDESC_ADD_LO12
146; CHECK-RELOC: R_AARCH64_TLSDESC_CALL
147; CHECK-RELOC: R_AARCH64_TLSLD_ADD_DTPREL_HI12
148; CHECK-RELOC: R_AARCH64_TLSLD_ADD_DTPREL_LO12_NC
149
150; CHECK-NOLD-RELOC: R_AARCH64_TLSDESC_ADR_PAGE21
151; CHECK-NOLD-RELOC: R_AARCH64_TLSDESC_LD64_LO12
152; CHECK-NOLD-RELOC: R_AARCH64_TLSDESC_ADD_LO12
153; CHECK-NOLD-RELOC: R_AARCH64_TLSDESC_CALL
154}
155
156; The entire point of the local-dynamic access model is to have a single call to
157; the expensive resolver. Make sure we achieve that goal.
158
159@local_dynamic_var2 = external thread_local(localdynamic) global i32
160
161define i32 @test_localdynamic_deduplicate() {
162; CHECK-LABEL: test_localdynamic_deduplicate:
163
164  %val = load i32, i32* @local_dynamic_var
165  %val2 = load i32, i32* @local_dynamic_var2
166
167  %sum = add i32 %val, %val2
168  ret i32 %sum
169
170; CHECK: adrp x[[DTPREL_HI:[0-9]+]], :tlsdesc:_TLS_MODULE_BASE_
171; CHECK-NEXT: ldr [[CALLEE:x[0-9]+]], [x[[DTPREL_HI]], :tlsdesc_lo12:_TLS_MODULE_BASE_]
172; CHECK-NEXT: add x0, x[[TLSDESC_HI]], :tlsdesc_lo12:_TLS_MODULE_BASE
173; CHECK-NEXT: .tlsdesccall _TLS_MODULE_BASE_
174; CHECK-NEXT: blr [[CALLEE]]
175
176; CHECK-NOT: _TLS_MODULE_BASE_
177
178; CHECK: ret
179}
180