1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=riscv32 -relocation-model=pic < %s \
3 ; RUN: | FileCheck -check-prefix=RV32-PIC %s
4 ; RUN: llc -mtriple=riscv32 -relocation-model=pic < %s -enable-tlsdesc \
5 ; RUN: | FileCheck -check-prefix=RV32-PIC-TLSDESC %s
6 ; RUN: llc -mtriple=riscv64 -relocation-model=pic < %s \
7 ; RUN: | FileCheck -check-prefix=RV64-PIC %s
8 ; RUN: llc -mtriple=riscv64 -relocation-model=pic -enable-tlsdesc < %s \
9 ; RUN: | FileCheck -check-prefix=RV64-PIC-TLSDESC %s
10 ; RUN: llc -mtriple=riscv32 < %s | FileCheck -check-prefix=RV32-NOPIC %s
11 ; RUN: llc -mtriple=riscv32 < %s -enable-tlsdesc | FileCheck -check-prefix=RV32-NOPIC-TLSDESC %s
12 ; RUN: llc -mtriple=riscv64 < %s | FileCheck -check-prefix=RV64-NOPIC %s
13 ; RUN: llc -mtriple=riscv64 < %s -enable-tlsdesc | FileCheck -check-prefix=RV64-NOPIC-TLSDESC %s
15 ; Check that TLS symbols are lowered correctly based on the specified
16 ; model. Make sure they're external to avoid them all being optimised to Local
17 ; Exec for the executable.
19 @unspecified = external thread_local global i32
20 @ld = external thread_local(localdynamic) global i32
21 @ie = external thread_local(initialexec) global i32
22 @le = external thread_local(localexec) global i32
27 define ptr @f1() nounwind {
29 ; RV32-PIC: # %bb.0: # %entry
30 ; RV32-PIC-NEXT: addi sp, sp, -16
31 ; RV32-PIC-NEXT: sw ra, 12(sp) # 4-byte Folded Spill
32 ; RV32-PIC-NEXT: .Lpcrel_hi0:
33 ; RV32-PIC-NEXT: auipc a0, %tls_gd_pcrel_hi(unspecified)
34 ; RV32-PIC-NEXT: addi a0, a0, %pcrel_lo(.Lpcrel_hi0)
35 ; RV32-PIC-NEXT: call __tls_get_addr
36 ; RV32-PIC-NEXT: lw ra, 12(sp) # 4-byte Folded Reload
37 ; RV32-PIC-NEXT: addi sp, sp, 16
41 ; RV64-PIC: # %bb.0: # %entry
42 ; RV64-PIC-NEXT: addi sp, sp, -16
43 ; RV64-PIC-NEXT: sd ra, 8(sp) # 8-byte Folded Spill
44 ; RV64-PIC-NEXT: .Lpcrel_hi0:
45 ; RV64-PIC-NEXT: auipc a0, %tls_gd_pcrel_hi(unspecified)
46 ; RV64-PIC-NEXT: addi a0, a0, %pcrel_lo(.Lpcrel_hi0)
47 ; RV64-PIC-NEXT: call __tls_get_addr
48 ; RV64-PIC-NEXT: ld ra, 8(sp) # 8-byte Folded Reload
49 ; RV64-PIC-NEXT: addi sp, sp, 16
52 ; RV32-NOPIC-LABEL: f1:
53 ; RV32-NOPIC: # %bb.0: # %entry
54 ; RV32-NOPIC-NEXT: .Lpcrel_hi0:
55 ; RV32-NOPIC-NEXT: auipc a0, %tls_ie_pcrel_hi(unspecified)
56 ; RV32-NOPIC-NEXT: lw a0, %pcrel_lo(.Lpcrel_hi0)(a0)
57 ; RV32-NOPIC-NEXT: add a0, a0, tp
58 ; RV32-NOPIC-NEXT: ret
60 ; RV64-NOPIC-LABEL: f1:
61 ; RV64-NOPIC: # %bb.0: # %entry
62 ; RV64-NOPIC-NEXT: .Lpcrel_hi0:
63 ; RV64-NOPIC-NEXT: auipc a0, %tls_ie_pcrel_hi(unspecified)
64 ; RV64-NOPIC-NEXT: ld a0, %pcrel_lo(.Lpcrel_hi0)(a0)
65 ; RV64-NOPIC-NEXT: add a0, a0, tp
66 ; RV64-NOPIC-NEXT: ret
68 ; RV32-PIC-TLSDESC-LABEL: f1:
69 ; RV32-PIC-TLSDESC: # %bb.0: # %entry
70 ; RV32-PIC-TLSDESC-NEXT: .Ltlsdesc_hi0:
71 ; RV32-PIC-TLSDESC-NEXT: auipc a0, %tlsdesc_hi(unspecified)
72 ; RV32-PIC-TLSDESC-NEXT: lw a1, %tlsdesc_load_lo(.Ltlsdesc_hi0)(a0)
73 ; RV32-PIC-TLSDESC-NEXT: addi a0, a0, %tlsdesc_add_lo(.Ltlsdesc_hi0)
74 ; RV32-PIC-TLSDESC-NEXT: jalr t0, 0(a1), %tlsdesc_call(.Ltlsdesc_hi0)
75 ; RV32-PIC-TLSDESC-NEXT: add a0, a0, tp
76 ; RV32-PIC-TLSDESC-NEXT: ret
78 ; RV64-PIC-TLSDESC-LABEL: f1:
79 ; RV64-PIC-TLSDESC: # %bb.0: # %entry
80 ; RV64-PIC-TLSDESC-NEXT: .Ltlsdesc_hi0:
81 ; RV64-PIC-TLSDESC-NEXT: auipc a0, %tlsdesc_hi(unspecified)
82 ; RV64-PIC-TLSDESC-NEXT: ld a1, %tlsdesc_load_lo(.Ltlsdesc_hi0)(a0)
83 ; RV64-PIC-TLSDESC-NEXT: addi a0, a0, %tlsdesc_add_lo(.Ltlsdesc_hi0)
84 ; RV64-PIC-TLSDESC-NEXT: jalr t0, 0(a1), %tlsdesc_call(.Ltlsdesc_hi0)
85 ; RV64-PIC-TLSDESC-NEXT: add a0, a0, tp
86 ; RV64-PIC-TLSDESC-NEXT: ret
88 ; RV32-NOPIC-TLSDESC-LABEL: f1:
89 ; RV32-NOPIC-TLSDESC: # %bb.0: # %entry
90 ; RV32-NOPIC-TLSDESC-NEXT: .Lpcrel_hi0:
91 ; RV32-NOPIC-TLSDESC-NEXT: auipc a0, %tls_ie_pcrel_hi(unspecified)
92 ; RV32-NOPIC-TLSDESC-NEXT: lw a0, %pcrel_lo(.Lpcrel_hi0)(a0)
93 ; RV32-NOPIC-TLSDESC-NEXT: add a0, a0, tp
94 ; RV32-NOPIC-TLSDESC-NEXT: ret
96 ; RV64-NOPIC-TLSDESC-LABEL: f1:
97 ; RV64-NOPIC-TLSDESC: # %bb.0: # %entry
98 ; RV64-NOPIC-TLSDESC-NEXT: .Lpcrel_hi0:
99 ; RV64-NOPIC-TLSDESC-NEXT: auipc a0, %tls_ie_pcrel_hi(unspecified)
100 ; RV64-NOPIC-TLSDESC-NEXT: ld a0, %pcrel_lo(.Lpcrel_hi0)(a0)
101 ; RV64-NOPIC-TLSDESC-NEXT: add a0, a0, tp
102 ; RV64-NOPIC-TLSDESC-NEXT: ret
108 ; localdynamic specified
110 define ptr @f2() nounwind {
111 ; RV32-PIC-LABEL: f2:
112 ; RV32-PIC: # %bb.0: # %entry
113 ; RV32-PIC-NEXT: addi sp, sp, -16
114 ; RV32-PIC-NEXT: sw ra, 12(sp) # 4-byte Folded Spill
115 ; RV32-PIC-NEXT: .Lpcrel_hi1:
116 ; RV32-PIC-NEXT: auipc a0, %tls_gd_pcrel_hi(ld)
117 ; RV32-PIC-NEXT: addi a0, a0, %pcrel_lo(.Lpcrel_hi1)
118 ; RV32-PIC-NEXT: call __tls_get_addr
119 ; RV32-PIC-NEXT: lw ra, 12(sp) # 4-byte Folded Reload
120 ; RV32-PIC-NEXT: addi sp, sp, 16
123 ; RV64-PIC-LABEL: f2:
124 ; RV64-PIC: # %bb.0: # %entry
125 ; RV64-PIC-NEXT: addi sp, sp, -16
126 ; RV64-PIC-NEXT: sd ra, 8(sp) # 8-byte Folded Spill
127 ; RV64-PIC-NEXT: .Lpcrel_hi1:
128 ; RV64-PIC-NEXT: auipc a0, %tls_gd_pcrel_hi(ld)
129 ; RV64-PIC-NEXT: addi a0, a0, %pcrel_lo(.Lpcrel_hi1)
130 ; RV64-PIC-NEXT: call __tls_get_addr
131 ; RV64-PIC-NEXT: ld ra, 8(sp) # 8-byte Folded Reload
132 ; RV64-PIC-NEXT: addi sp, sp, 16
135 ; RV32-NOPIC-LABEL: f2:
136 ; RV32-NOPIC: # %bb.0: # %entry
137 ; RV32-NOPIC-NEXT: .Lpcrel_hi1:
138 ; RV32-NOPIC-NEXT: auipc a0, %tls_ie_pcrel_hi(ld)
139 ; RV32-NOPIC-NEXT: lw a0, %pcrel_lo(.Lpcrel_hi1)(a0)
140 ; RV32-NOPIC-NEXT: add a0, a0, tp
141 ; RV32-NOPIC-NEXT: ret
143 ; RV64-NOPIC-LABEL: f2:
144 ; RV64-NOPIC: # %bb.0: # %entry
145 ; RV64-NOPIC-NEXT: .Lpcrel_hi1:
146 ; RV64-NOPIC-NEXT: auipc a0, %tls_ie_pcrel_hi(ld)
147 ; RV64-NOPIC-NEXT: ld a0, %pcrel_lo(.Lpcrel_hi1)(a0)
148 ; RV64-NOPIC-NEXT: add a0, a0, tp
149 ; RV64-NOPIC-NEXT: ret
155 ; initialexec specified
157 define ptr @f3() nounwind {
158 ; RV32-PIC-LABEL: f3:
159 ; RV32-PIC: # %bb.0: # %entry
160 ; RV32-PIC-NEXT: .Lpcrel_hi2:
161 ; RV32-PIC-NEXT: auipc a0, %tls_ie_pcrel_hi(ie)
162 ; RV32-PIC-NEXT: lw a0, %pcrel_lo(.Lpcrel_hi2)(a0)
163 ; RV32-PIC-NEXT: add a0, a0, tp
166 ; RV64-PIC-LABEL: f3:
167 ; RV64-PIC: # %bb.0: # %entry
168 ; RV64-PIC-NEXT: .Lpcrel_hi2:
169 ; RV64-PIC-NEXT: auipc a0, %tls_ie_pcrel_hi(ie)
170 ; RV64-PIC-NEXT: ld a0, %pcrel_lo(.Lpcrel_hi2)(a0)
171 ; RV64-PIC-NEXT: add a0, a0, tp
174 ; RV32-NOPIC-LABEL: f3:
175 ; RV32-NOPIC: # %bb.0: # %entry
176 ; RV32-NOPIC-NEXT: .Lpcrel_hi2:
177 ; RV32-NOPIC-NEXT: auipc a0, %tls_ie_pcrel_hi(ie)
178 ; RV32-NOPIC-NEXT: lw a0, %pcrel_lo(.Lpcrel_hi2)(a0)
179 ; RV32-NOPIC-NEXT: add a0, a0, tp
180 ; RV32-NOPIC-NEXT: ret
182 ; RV64-NOPIC-LABEL: f3:
183 ; RV64-NOPIC: # %bb.0: # %entry
184 ; RV64-NOPIC-NEXT: .Lpcrel_hi2:
185 ; RV64-NOPIC-NEXT: auipc a0, %tls_ie_pcrel_hi(ie)
186 ; RV64-NOPIC-NEXT: ld a0, %pcrel_lo(.Lpcrel_hi2)(a0)
187 ; RV64-NOPIC-NEXT: add a0, a0, tp
188 ; RV64-NOPIC-NEXT: ret
190 ; RV32-PIC-TLSDESC-LABEL: f3:
191 ; RV32-PIC-TLSDESC: # %bb.0: # %entry
192 ; RV32-PIC-TLSDESC-NEXT: .Lpcrel_hi0:
193 ; RV32-PIC-TLSDESC-NEXT: auipc a0, %tls_ie_pcrel_hi(ie)
194 ; RV32-PIC-TLSDESC-NEXT: lw a0, %pcrel_lo(.Lpcrel_hi0)(a0)
195 ; RV32-PIC-TLSDESC-NEXT: add a0, a0, tp
196 ; RV32-PIC-TLSDESC-NEXT: ret
198 ; RV64-PIC-TLSDESC-LABEL: f3:
199 ; RV64-PIC-TLSDESC: # %bb.0: # %entry
200 ; RV64-PIC-TLSDESC-NEXT: .Lpcrel_hi0:
201 ; RV64-PIC-TLSDESC-NEXT: auipc a0, %tls_ie_pcrel_hi(ie)
202 ; RV64-PIC-TLSDESC-NEXT: ld a0, %pcrel_lo(.Lpcrel_hi0)(a0)
203 ; RV64-PIC-TLSDESC-NEXT: add a0, a0, tp
204 ; RV64-PIC-TLSDESC-NEXT: ret
206 ; RV32-NOPIC-TLSDESC-LABEL: f3:
207 ; RV32-NOPIC-TLSDESC: # %bb.0: # %entry
208 ; RV32-NOPIC-TLSDESC-NEXT: .Lpcrel_hi2:
209 ; RV32-NOPIC-TLSDESC-NEXT: auipc a0, %tls_ie_pcrel_hi(ie)
210 ; RV32-NOPIC-TLSDESC-NEXT: lw a0, %pcrel_lo(.Lpcrel_hi2)(a0)
211 ; RV32-NOPIC-TLSDESC-NEXT: add a0, a0, tp
212 ; RV32-NOPIC-TLSDESC-NEXT: ret
214 ; RV64-NOPIC-TLSDESC-LABEL: f3:
215 ; RV64-NOPIC-TLSDESC: # %bb.0: # %entry
216 ; RV64-NOPIC-TLSDESC-NEXT: .Lpcrel_hi2:
217 ; RV64-NOPIC-TLSDESC-NEXT: auipc a0, %tls_ie_pcrel_hi(ie)
218 ; RV64-NOPIC-TLSDESC-NEXT: ld a0, %pcrel_lo(.Lpcrel_hi2)(a0)
219 ; RV64-NOPIC-TLSDESC-NEXT: add a0, a0, tp
220 ; RV64-NOPIC-TLSDESC-NEXT: ret
226 ; localexec specified
228 define ptr @f4() nounwind {
229 ; RV32-PIC-LABEL: f4:
230 ; RV32-PIC: # %bb.0: # %entry
231 ; RV32-PIC-NEXT: lui a0, %tprel_hi(le)
232 ; RV32-PIC-NEXT: add a0, a0, tp, %tprel_add(le)
233 ; RV32-PIC-NEXT: addi a0, a0, %tprel_lo(le)
236 ; RV64-PIC-LABEL: f4:
237 ; RV64-PIC: # %bb.0: # %entry
238 ; RV64-PIC-NEXT: lui a0, %tprel_hi(le)
239 ; RV64-PIC-NEXT: add a0, a0, tp, %tprel_add(le)
240 ; RV64-PIC-NEXT: addi a0, a0, %tprel_lo(le)
243 ; RV32-NOPIC-LABEL: f4:
244 ; RV32-NOPIC: # %bb.0: # %entry
245 ; RV32-NOPIC-NEXT: lui a0, %tprel_hi(le)
246 ; RV32-NOPIC-NEXT: add a0, a0, tp, %tprel_add(le)
247 ; RV32-NOPIC-NEXT: addi a0, a0, %tprel_lo(le)
248 ; RV32-NOPIC-NEXT: ret
250 ; RV64-NOPIC-LABEL: f4:
251 ; RV64-NOPIC: # %bb.0: # %entry
252 ; RV64-NOPIC-NEXT: lui a0, %tprel_hi(le)
253 ; RV64-NOPIC-NEXT: add a0, a0, tp, %tprel_add(le)
254 ; RV64-NOPIC-NEXT: addi a0, a0, %tprel_lo(le)
255 ; RV64-NOPIC-NEXT: ret
257 ; RV32-PIC-TLSDESC-LABEL: f4:
258 ; RV32-PIC-TLSDESC: # %bb.0: # %entry
259 ; RV32-PIC-TLSDESC-NEXT: lui a0, %tprel_hi(le)
260 ; RV32-PIC-TLSDESC-NEXT: add a0, a0, tp, %tprel_add(le)
261 ; RV32-PIC-TLSDESC-NEXT: addi a0, a0, %tprel_lo(le)
262 ; RV32-PIC-TLSDESC-NEXT: ret
264 ; RV64-PIC-TLSDESC-LABEL: f4:
265 ; RV64-PIC-TLSDESC: # %bb.0: # %entry
266 ; RV64-PIC-TLSDESC-NEXT: lui a0, %tprel_hi(le)
267 ; RV64-PIC-TLSDESC-NEXT: add a0, a0, tp, %tprel_add(le)
268 ; RV64-PIC-TLSDESC-NEXT: addi a0, a0, %tprel_lo(le)
269 ; RV64-PIC-TLSDESC-NEXT: ret
271 ; RV32-NOPIC-TLSDESC-LABEL: f4:
272 ; RV32-NOPIC-TLSDESC: # %bb.0: # %entry
273 ; RV32-NOPIC-TLSDESC-NEXT: lui a0, %tprel_hi(le)
274 ; RV32-NOPIC-TLSDESC-NEXT: add a0, a0, tp, %tprel_add(le)
275 ; RV32-NOPIC-TLSDESC-NEXT: addi a0, a0, %tprel_lo(le)
276 ; RV32-NOPIC-TLSDESC-NEXT: ret
278 ; RV64-NOPIC-TLSDESC-LABEL: f4:
279 ; RV64-NOPIC-TLSDESC: # %bb.0: # %entry
280 ; RV64-NOPIC-TLSDESC-NEXT: lui a0, %tprel_hi(le)
281 ; RV64-NOPIC-TLSDESC-NEXT: add a0, a0, tp, %tprel_add(le)
282 ; RV64-NOPIC-TLSDESC-NEXT: addi a0, a0, %tprel_lo(le)
283 ; RV64-NOPIC-TLSDESC-NEXT: ret