1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=riscv32 -relocation-model=static < %s \
3 ; RUN: | FileCheck %s --check-prefix=RV32-STATIC
4 ; RUN: llc -mtriple=riscv32 -relocation-model=pic < %s \
5 ; RUN: | FileCheck %s --check-prefix=RV32-PIC
6 ; RUN: llc -mtriple=riscv64 -relocation-model=static < %s \
7 ; RUN: | FileCheck %s --check-prefix=RV64-STATIC
8 ; RUN: llc -mtriple=riscv64 -relocation-model=pic < %s \
9 ; RUN: | FileCheck %s --check-prefix=RV64-PIC
11 @preemptable_var = dso_preemptable global i32 42
12 define ptr @get_preemptable_var() nounwind {
13 ; RV32-STATIC-LABEL: get_preemptable_var:
14 ; RV32-STATIC: # %bb.0:
15 ; RV32-STATIC-NEXT: lui a0, %hi(preemptable_var)
16 ; RV32-STATIC-NEXT: addi a0, a0, %lo(preemptable_var)
17 ; RV32-STATIC-NEXT: ret
19 ; RV32-PIC-LABEL: get_preemptable_var:
21 ; RV32-PIC-NEXT: .Lpcrel_hi0:
22 ; RV32-PIC-NEXT: auipc a0, %got_pcrel_hi(preemptable_var)
23 ; RV32-PIC-NEXT: lw a0, %pcrel_lo(.Lpcrel_hi0)(a0)
26 ; RV64-STATIC-LABEL: get_preemptable_var:
27 ; RV64-STATIC: # %bb.0:
28 ; RV64-STATIC-NEXT: lui a0, %hi(preemptable_var)
29 ; RV64-STATIC-NEXT: addi a0, a0, %lo(preemptable_var)
30 ; RV64-STATIC-NEXT: ret
32 ; RV64-PIC-LABEL: get_preemptable_var:
34 ; RV64-PIC-NEXT: .Lpcrel_hi0:
35 ; RV64-PIC-NEXT: auipc a0, %got_pcrel_hi(preemptable_var)
36 ; RV64-PIC-NEXT: ld a0, %pcrel_lo(.Lpcrel_hi0)(a0)
38 ret ptr @preemptable_var
41 @dsolocal_var = dso_local global i32 42
42 define ptr @get_dsolocal_var() nounwind {
43 ; RV32-STATIC-LABEL: get_dsolocal_var:
44 ; RV32-STATIC: # %bb.0:
45 ; RV32-STATIC-NEXT: lui a0, %hi(dsolocal_var)
46 ; RV32-STATIC-NEXT: addi a0, a0, %lo(dsolocal_var)
47 ; RV32-STATIC-NEXT: ret
49 ; RV32-PIC-LABEL: get_dsolocal_var:
51 ; RV32-PIC-NEXT: .Lpcrel_hi1:
52 ; RV32-PIC-NEXT: auipc a0, %pcrel_hi(.Ldsolocal_var$local)
53 ; RV32-PIC-NEXT: addi a0, a0, %pcrel_lo(.Lpcrel_hi1)
56 ; RV64-STATIC-LABEL: get_dsolocal_var:
57 ; RV64-STATIC: # %bb.0:
58 ; RV64-STATIC-NEXT: lui a0, %hi(dsolocal_var)
59 ; RV64-STATIC-NEXT: addi a0, a0, %lo(dsolocal_var)
60 ; RV64-STATIC-NEXT: ret
62 ; RV64-PIC-LABEL: get_dsolocal_var:
64 ; RV64-PIC-NEXT: .Lpcrel_hi1:
65 ; RV64-PIC-NEXT: auipc a0, %pcrel_hi(.Ldsolocal_var$local)
66 ; RV64-PIC-NEXT: addi a0, a0, %pcrel_lo(.Lpcrel_hi1)
71 @weak_dsolocal_var = weak dso_local global i32 42
72 define ptr @get_weak_dsolocal_var() nounwind {
73 ; RV32-STATIC-LABEL: get_weak_dsolocal_var:
74 ; RV32-STATIC: # %bb.0:
75 ; RV32-STATIC-NEXT: lui a0, %hi(weak_dsolocal_var)
76 ; RV32-STATIC-NEXT: addi a0, a0, %lo(weak_dsolocal_var)
77 ; RV32-STATIC-NEXT: ret
79 ; RV32-PIC-LABEL: get_weak_dsolocal_var:
81 ; RV32-PIC-NEXT: .Lpcrel_hi2:
82 ; RV32-PIC-NEXT: auipc a0, %pcrel_hi(weak_dsolocal_var)
83 ; RV32-PIC-NEXT: addi a0, a0, %pcrel_lo(.Lpcrel_hi2)
86 ; RV64-STATIC-LABEL: get_weak_dsolocal_var:
87 ; RV64-STATIC: # %bb.0:
88 ; RV64-STATIC-NEXT: lui a0, %hi(weak_dsolocal_var)
89 ; RV64-STATIC-NEXT: addi a0, a0, %lo(weak_dsolocal_var)
90 ; RV64-STATIC-NEXT: ret
92 ; RV64-PIC-LABEL: get_weak_dsolocal_var:
94 ; RV64-PIC-NEXT: .Lpcrel_hi2:
95 ; RV64-PIC-NEXT: auipc a0, %pcrel_hi(weak_dsolocal_var)
96 ; RV64-PIC-NEXT: addi a0, a0, %pcrel_lo(.Lpcrel_hi2)
98 ret ptr @weak_dsolocal_var
101 @hidden_var = hidden global i32 42
102 define ptr @get_hidden_var() nounwind {
103 ; RV32-STATIC-LABEL: get_hidden_var:
104 ; RV32-STATIC: # %bb.0:
105 ; RV32-STATIC-NEXT: lui a0, %hi(hidden_var)
106 ; RV32-STATIC-NEXT: addi a0, a0, %lo(hidden_var)
107 ; RV32-STATIC-NEXT: ret
109 ; RV32-PIC-LABEL: get_hidden_var:
111 ; RV32-PIC-NEXT: .Lpcrel_hi3:
112 ; RV32-PIC-NEXT: auipc a0, %pcrel_hi(hidden_var)
113 ; RV32-PIC-NEXT: addi a0, a0, %pcrel_lo(.Lpcrel_hi3)
116 ; RV64-STATIC-LABEL: get_hidden_var:
117 ; RV64-STATIC: # %bb.0:
118 ; RV64-STATIC-NEXT: lui a0, %hi(hidden_var)
119 ; RV64-STATIC-NEXT: addi a0, a0, %lo(hidden_var)
120 ; RV64-STATIC-NEXT: ret
122 ; RV64-PIC-LABEL: get_hidden_var:
124 ; RV64-PIC-NEXT: .Lpcrel_hi3:
125 ; RV64-PIC-NEXT: auipc a0, %pcrel_hi(hidden_var)
126 ; RV64-PIC-NEXT: addi a0, a0, %pcrel_lo(.Lpcrel_hi3)
131 @protected_var = protected global i32 42
132 define ptr @get_protected_var() nounwind {
133 ; RV32-STATIC-LABEL: get_protected_var:
134 ; RV32-STATIC: # %bb.0:
135 ; RV32-STATIC-NEXT: lui a0, %hi(protected_var)
136 ; RV32-STATIC-NEXT: addi a0, a0, %lo(protected_var)
137 ; RV32-STATIC-NEXT: ret
139 ; RV32-PIC-LABEL: get_protected_var:
141 ; RV32-PIC-NEXT: .Lpcrel_hi4:
142 ; RV32-PIC-NEXT: auipc a0, %pcrel_hi(protected_var)
143 ; RV32-PIC-NEXT: addi a0, a0, %pcrel_lo(.Lpcrel_hi4)
146 ; RV64-STATIC-LABEL: get_protected_var:
147 ; RV64-STATIC: # %bb.0:
148 ; RV64-STATIC-NEXT: lui a0, %hi(protected_var)
149 ; RV64-STATIC-NEXT: addi a0, a0, %lo(protected_var)
150 ; RV64-STATIC-NEXT: ret
152 ; RV64-PIC-LABEL: get_protected_var:
154 ; RV64-PIC-NEXT: .Lpcrel_hi4:
155 ; RV64-PIC-NEXT: auipc a0, %pcrel_hi(protected_var)
156 ; RV64-PIC-NEXT: addi a0, a0, %pcrel_lo(.Lpcrel_hi4)
158 ret ptr @protected_var
161 define dso_preemptable ptr @preemptable_func() nounwind {
162 ; RV32-STATIC-LABEL: preemptable_func:
163 ; RV32-STATIC: # %bb.0:
164 ; RV32-STATIC-NEXT: lui a0, %hi(preemptable_func)
165 ; RV32-STATIC-NEXT: addi a0, a0, %lo(preemptable_func)
166 ; RV32-STATIC-NEXT: ret
168 ; RV32-PIC-LABEL: preemptable_func:
170 ; RV32-PIC-NEXT: .Lpcrel_hi5:
171 ; RV32-PIC-NEXT: auipc a0, %got_pcrel_hi(preemptable_func)
172 ; RV32-PIC-NEXT: lw a0, %pcrel_lo(.Lpcrel_hi5)(a0)
175 ; RV64-STATIC-LABEL: preemptable_func:
176 ; RV64-STATIC: # %bb.0:
177 ; RV64-STATIC-NEXT: lui a0, %hi(preemptable_func)
178 ; RV64-STATIC-NEXT: addi a0, a0, %lo(preemptable_func)
179 ; RV64-STATIC-NEXT: ret
181 ; RV64-PIC-LABEL: preemptable_func:
183 ; RV64-PIC-NEXT: .Lpcrel_hi5:
184 ; RV64-PIC-NEXT: auipc a0, %got_pcrel_hi(preemptable_func)
185 ; RV64-PIC-NEXT: ld a0, %pcrel_lo(.Lpcrel_hi5)(a0)
187 ret ptr @preemptable_func
190 define dso_local ptr @dsolocal_func() nounwind {
191 ; RV32-STATIC-LABEL: dsolocal_func:
192 ; RV32-STATIC: # %bb.0:
193 ; RV32-STATIC-NEXT: lui a0, %hi(dsolocal_func)
194 ; RV32-STATIC-NEXT: addi a0, a0, %lo(dsolocal_func)
195 ; RV32-STATIC-NEXT: ret
197 ; RV32-PIC-LABEL: dsolocal_func:
199 ; RV32-PIC-NEXT: .Lpcrel_hi6:
200 ; RV32-PIC-NEXT: auipc a0, %pcrel_hi(.Ldsolocal_func$local)
201 ; RV32-PIC-NEXT: addi a0, a0, %pcrel_lo(.Lpcrel_hi6)
204 ; RV64-STATIC-LABEL: dsolocal_func:
205 ; RV64-STATIC: # %bb.0:
206 ; RV64-STATIC-NEXT: lui a0, %hi(dsolocal_func)
207 ; RV64-STATIC-NEXT: addi a0, a0, %lo(dsolocal_func)
208 ; RV64-STATIC-NEXT: ret
210 ; RV64-PIC-LABEL: dsolocal_func:
212 ; RV64-PIC-NEXT: .Lpcrel_hi6:
213 ; RV64-PIC-NEXT: auipc a0, %pcrel_hi(.Ldsolocal_func$local)
214 ; RV64-PIC-NEXT: addi a0, a0, %pcrel_lo(.Lpcrel_hi6)
216 ret ptr @dsolocal_func
219 define weak dso_local ptr @weak_dsolocal_func() nounwind {
220 ; RV32-STATIC-LABEL: weak_dsolocal_func:
221 ; RV32-STATIC: # %bb.0:
222 ; RV32-STATIC-NEXT: lui a0, %hi(weak_dsolocal_func)
223 ; RV32-STATIC-NEXT: addi a0, a0, %lo(weak_dsolocal_func)
224 ; RV32-STATIC-NEXT: ret
226 ; RV32-PIC-LABEL: weak_dsolocal_func:
228 ; RV32-PIC-NEXT: .Lpcrel_hi7:
229 ; RV32-PIC-NEXT: auipc a0, %pcrel_hi(weak_dsolocal_func)
230 ; RV32-PIC-NEXT: addi a0, a0, %pcrel_lo(.Lpcrel_hi7)
233 ; RV64-STATIC-LABEL: weak_dsolocal_func:
234 ; RV64-STATIC: # %bb.0:
235 ; RV64-STATIC-NEXT: lui a0, %hi(weak_dsolocal_func)
236 ; RV64-STATIC-NEXT: addi a0, a0, %lo(weak_dsolocal_func)
237 ; RV64-STATIC-NEXT: ret
239 ; RV64-PIC-LABEL: weak_dsolocal_func:
241 ; RV64-PIC-NEXT: .Lpcrel_hi7:
242 ; RV64-PIC-NEXT: auipc a0, %pcrel_hi(weak_dsolocal_func)
243 ; RV64-PIC-NEXT: addi a0, a0, %pcrel_lo(.Lpcrel_hi7)
245 ret ptr @weak_dsolocal_func
248 ;; call .Ldsolocal_func$local either resolves to a constant at assembly time
249 ;; or produces a relocation referencing a non-preemptible local symbol.
250 define dso_local void @call_dsolocal_func() nounwind {
251 ; RV32-STATIC-LABEL: call_dsolocal_func:
252 ; RV32-STATIC: # %bb.0:
253 ; RV32-STATIC-NEXT: addi sp, sp, -16
254 ; RV32-STATIC-NEXT: sw ra, 12(sp) # 4-byte Folded Spill
255 ; RV32-STATIC-NEXT: call dsolocal_func
256 ; RV32-STATIC-NEXT: lw ra, 12(sp) # 4-byte Folded Reload
257 ; RV32-STATIC-NEXT: addi sp, sp, 16
258 ; RV32-STATIC-NEXT: ret
260 ; RV32-PIC-LABEL: call_dsolocal_func:
262 ; RV32-PIC-NEXT: addi sp, sp, -16
263 ; RV32-PIC-NEXT: sw ra, 12(sp) # 4-byte Folded Spill
264 ; RV32-PIC-NEXT: call .Ldsolocal_func$local
265 ; RV32-PIC-NEXT: lw ra, 12(sp) # 4-byte Folded Reload
266 ; RV32-PIC-NEXT: addi sp, sp, 16
269 ; RV64-STATIC-LABEL: call_dsolocal_func:
270 ; RV64-STATIC: # %bb.0:
271 ; RV64-STATIC-NEXT: addi sp, sp, -16
272 ; RV64-STATIC-NEXT: sd ra, 8(sp) # 8-byte Folded Spill
273 ; RV64-STATIC-NEXT: call dsolocal_func
274 ; RV64-STATIC-NEXT: ld ra, 8(sp) # 8-byte Folded Reload
275 ; RV64-STATIC-NEXT: addi sp, sp, 16
276 ; RV64-STATIC-NEXT: ret
278 ; RV64-PIC-LABEL: call_dsolocal_func:
280 ; RV64-PIC-NEXT: addi sp, sp, -16
281 ; RV64-PIC-NEXT: sd ra, 8(sp) # 8-byte Folded Spill
282 ; RV64-PIC-NEXT: call .Ldsolocal_func$local
283 ; RV64-PIC-NEXT: ld ra, 8(sp) # 8-byte Folded Reload
284 ; RV64-PIC-NEXT: addi sp, sp, 16
286 call ptr @dsolocal_func()