1 # RUN: llvm-mc %s -triple=riscv64 -riscv-no-aliases \
2 # RUN: | FileCheck -check-prefixes=CHECK-EXPAND,CHECK-INST,CHECK-ASM-NOALIAS %s
3 # RUN: llvm-mc %s -triple=riscv64 \
4 # RUN: | FileCheck -check-prefixes=CHECK-EXPAND,CHECK-ALIAS,CHECK-ASM %s
5 # RUN: llvm-mc -filetype=obj -triple riscv64 < %s \
6 # RUN: | llvm-objdump -M no-aliases -d - \
7 # RUN: | FileCheck -check-prefixes=CHECK-OBJ-NOALIAS,CHECK-EXPAND,CHECK-INST %s
8 # RUN: llvm-mc -filetype=obj -triple riscv64 < %s \
9 # RUN: | llvm-objdump -d - \
10 # RUN: | FileCheck -check-prefixes=CHECK-EXPAND,CHECK-ALIAS %s
12 # The following check prefixes are used in this test:
13 # CHECK-INST.....Match the canonical instr (tests alias to instr. mapping)
14 # CHECK-ALIAS....Match the alias (tests instr. to alias mapping)
15 # CHECK-EXPAND...Match canonical instr. unconditionally (tests alias expansion)
20 # Needed for testing valid %pcrel_lo expressions
21 .Lpcrel_hi0: auipc a0, %pcrel_hi(foo)
23 # Needed for testing li with a symbol difference
27 # CHECK-INST: addi a0, zero, 0
28 # CHECK-ALIAS: li a0, 0
30 # CHECK-INST: addi a0, zero, 1
31 # CHECK-ALIAS: li a0, 1
33 # CHECK-INST: addi a0, zero, -1
34 # CHECK-ALIAS: li a0, -1
36 # CHECK-INST: addi a0, zero, 2047
37 # CHECK-ALIAS: li a0, 2047
39 # CHECK-INST: addi a0, zero, -2047
40 # CHECK-ALIAS: li a0, -2047
42 # CHECK-INST: addi a1, zero, 1
43 # CHECK-INST: slli a1, a1, 11
44 # CHECK-ALIAS: li a1, 1
45 # CHECK-ALIAS: slli a1, a1, 11
47 # CHECK-INST: addi a1, zero, -2048
48 # CHECK-ALIAS: li a1, -2048
50 # CHECK-EXPAND: lui a1, 1
51 # CHECK-EXPAND: addiw a1, a1, -2047
53 # CHECK-EXPAND: lui a1, 1048575
54 # CHECK-EXPAND: addiw a1, a1, 2047
56 # CHECK-EXPAND: lui a1, 1
57 # CHECK-EXPAND: addiw a1, a1, -1
59 # CHECK-EXPAND: lui a1, 1048575
60 # CHECK-EXPAND: addiw a1, a1, 1
62 # CHECK-EXPAND: lui a2, 1
64 # CHECK-EXPAND: lui a2, 1048575
66 # CHECK-EXPAND: lui a2, 1
67 # CHECK-EXPAND-NEXT: addiw a2, a2, 1
69 # CHECK-EXPAND: lui a2, 1048575
70 # CHECK-EXPAND: addiw a2, a2, -1
72 # CHECK-EXPAND: lui a2, 524288
73 # CHECK-EXPAND-NEXT: addiw a2, a2, -1
75 # CHECK-EXPAND: lui a2, 524288
76 # CHECK-EXPAND-NEXT: addiw a2, a2, 1
78 # CHECK-EXPAND: lui a2, 524288
80 # CHECK-EXPAND: lui a2, 524288
83 # CHECK-INST: addi a2, zero, 1
84 # CHECK-INST-NEXT: slli a2, a2, 31
85 # CHECK-ALIAS: li a2, 1
86 # CHECK-ALIAS-NEXT: slli a2, a2, 31
88 # CHECK-INST: addi a2, zero, -1
89 # CHECK-INST-NEXT: srli a2, a2, 32
90 # CHECK-ALIAS: li a2, -1
91 # CHECK-ALIAS-NEXT: srli a2, a2, 32
94 # CHECK-INST: addi t0, zero, 1
95 # CHECK-INST-NEXT: slli t0, t0, 32
96 # CHECK-ALIAS: li t0, 1
97 # CHECK-ALIAS-NEXT: slli t0, t0, 32
99 # CHECK-INST: addi t1, zero, -1
100 # CHECK-INST-NEXT: slli t1, t1, 63
101 # CHECK-ALIAS: li t1, -1
102 # CHECK-ALIAS-NEXT: slli t1, t1, 63
103 li t1
, 0x8000000000000000
104 # CHECK-INST: addi t1, zero, -1
105 # CHECK-INST-NEXT: slli t1, t1, 63
106 # CHECK-ALIAS: li t1, -1
107 # CHECK-ALIAS-NEXT: slli t1, t1, 63
108 li t1
, -0x8000000000000000
109 # CHECK-EXPAND: lui t2, 9321
110 # CHECK-EXPAND-NEXT: addiw t2, t2, -1329
111 # CHECK-EXPAND-NEXT: slli t2, t2, 35
112 li t2
, 0x1234567800000000
113 # CHECK-INST: addi t3, zero, 7
114 # CHECK-INST-NEXT: slli t3, t3, 36
115 # CHECK-INST-NEXT: addi t3, t3, 11
116 # CHECK-INST-NEXT: slli t3, t3, 24
117 # CHECK-INST-NEXT: addi t3, t3, 15
118 # CHECK-ALIAS: li t3, 7
119 # CHECK-ALIAS-NEXT: slli t3, t3, 36
120 # CHECK-ALIAS-NEXT: addi t3, t3, 11
121 # CHECK-ALIAS-NEXT: slli t3, t3, 24
122 # CHECK-ALIAS-NEXT: addi t3, t3, 15
123 li t3
, 0x700000000B00000F
124 # CHECK-EXPAND: lui t4, 583
125 # CHECK-EXPAND-NEXT: addiw t4, t4, -1875
126 # CHECK-EXPAND-NEXT: slli t4, t4, 14
127 # CHECK-EXPAND-NEXT: addi t4, t4, -947
128 # CHECK-EXPAND-NEXT: slli t4, t4, 12
129 # CHECK-EXPAND-NEXT: addi t4, t4, 1511
130 # CHECK-EXPAND-NEXT: slli t4, t4, 13
131 # CHECK-EXPAND-NEXT: addi t4, t4, -272
132 li t4
, 0x123456789abcdef0
133 # CHECK-INST: addi t5, zero, -1
134 # CHECK-ALIAS: li t5, -1
135 li t5
, 0xFFFFFFFFFFFFFFFF
136 # CHECK-EXPAND: lui t6, 262145
137 # CHECK-EXPAND-NEXT: slli t6, t6, 1
139 # CHECK-EXPAND: lui t0, 262145
140 # CHECK-EXPAND-NEXT: slli t0, t0, 2
142 # CHECK-EXPAND: lui t1, 4097
143 # CHECK-EXPAND-NEXT: slli t1, t1, 20
144 li x6
, 0x100100000000
145 # CHECK-EXPAND: lui t2, 983056
146 # CHECK-EXPAND-NEXT: srli t2, t2, 16
147 li x7
, 0xFFFFFFFFF001
148 # CHECK-EXPAND: lui s0, 1044481
149 # CHECK-EXPAND-NEXT: slli s0, s0, 12
150 # CHECK-EXPAND-NEXT: srli s0, s0, 24
152 # CHECK-EXPAND: lui s1, 4097
153 # CHECK-EXPAND-NEXT: slli s1, s1, 20
154 # CHECK-EXPAND-NEXT: addi s1, s1, -3
155 li x9
, 0x1000FFFFFFFD
156 # CHECK-INST: lui a0, 983040
157 # CHECK-INST-NEXT: srli a0, a0, 3
158 # CHECK-INST-NEXT: xori a0, a0, -1
159 # CHECK-ALIAS: lui a0, 983040
160 # CHECK-ALIAS-NEXT: srli a0, a0, 3
161 # CHECK-ALIAS-NEXT: not a0, a0
162 li x10
, 0xE000000001FFFFFF
163 # CHECK-INST: addi a1, zero, -2047
164 # CHECK-INST-NEXT: slli a1, a1, 39
165 # CHECK-INST-NEXT: addi a1, a1, -2048
166 # CHECK-INST-NEXT: addi a1, a1, -1
167 # CHECK-ALIAS: li a1, -2047
168 # CHECK-ALIAS-NEXT: slli a1, a1, 39
169 # CHECK-ALIAS-NEXT: addi a1, a1, -2048
170 # CHECK-ALIAS-NEXT: addi a1, a1, -1
171 li x11
, 0xFFFC007FFFFFF7FF
173 # CHECK-INST: lui a2, 349525
174 # CHECK-INST-NEXT: addiw a2, a2, 1365
175 # CHECK-INST-NEXT: slli a2, a2, 1
176 # CHECK-ALIAS: lui a2, 349525
177 # CHECK-ALIAS-NEXT: addiw a2, a2, 1365
178 # CHECK-ALIAS-NEXT: slli a2, a2, 1
181 # CHECK-INST: lui a3, 699051
182 # CHECK-INST-NEXT: addiw a3, a3, -1365
183 # CHECK-INST-NEXT: slli a3, a3, 1
184 # CHECK-ALIAS: lui a3, 699051
185 # CHECK-ALIAS-NEXT: addiw a3, a3, -1365
186 # CHECK-ALIAS-NEXT: slli a3, a3, 1
187 li x13
, 0xffffffff55555556
189 # CHECK-S-OBJ-NOALIAS: lui t0, 524288
190 # CHECK-S-OBJ-NOALIAS-NEXT: addi t0, t0, -1365
191 # CHECK-S-OBJ: lui t0, 524288
192 # CHECK-S-OBJ-NEXT: addi t0, t0, -1365
195 # CHECK-INST: addi a0, zero, 1110
196 # CHECK-ALIAS: li a0, 1110
199 # CHECK-OBJ-NOALIAS: addi a0, zero, 0
200 # CHECK-OBJ: R_RISCV_LO12
202 # CHECK-OBJ-NOALIAS: addi a0, zero, 0
203 # CHECK-OBJ: R_RISCV_PCREL_LO12
204 li a0
, %pcrel_lo
(.Lpcrel_hi0)
207 # CHECK-EXPAND: lui a0, 291
208 # CHECK-EXPAND: addiw a0, a0, 1110
212 # CHECK-EXPAND: lui a0, 1620
213 # CHECK-EXPAND: addiw a0, a0, 801
216 .equ CONST, .Lbuf_end - .Lbuf
217 # CHECK-ASM: li a0, CONST
218 # CHECK-ASM-NOALIAS: addi a0, zero, CONST
219 # CHECK-OBJ-NOALIAS: addi a0, zero, 8
222 # CHECK-ASM: addi a0, zero, .Lbuf_end-.Lbuf
223 # CHECK-ASM-NOALIAS: addi a0, zero, .Lbuf_end-.Lbuf
224 # CHECK-OBJ-NOALIAS: addi a0, zero, 8
225 li a0
, .Lbuf_end - .Lbuf
227 # CHECK-INST: addi a0, zero, 0
228 # CHECK-ALIAS: li a0, 0
231 # CHECK-INST: addi a0, zero, 1
232 # CHECK-ALIAS: li a0, 1
235 # CHECK-INST: addi a0, zero, -1
236 # CHECK-ALIAS: li a0, -1
239 # CHECK-INST: addi a0, zero, 2047
240 # CHECK-ALIAS: li a0, 2047
243 # CHECK-INST: addi a0, zero, -2047
244 # CHECK-ALIAS: li a0, -2047
247 # CHECK-INST: addi a1, zero, 1
248 # CHECK-INST: slli a1, a1, 11
249 # CHECK-ALIAS: li a1, 1
250 # CHECK-ALIAS: slli a1, a1, 11
253 # CHECK-INST: addi a1, zero, -2048
254 # CHECK-ALIAS: li a1, -2048
257 # CHECK-EXPAND: lui a1, 1
258 # CHECK-EXPAND: addiw a1, a1, -2047
261 # CHECK-EXPAND: lui a1, 1048575
262 # CHECK-EXPAND: addiw a1, a1, 2047
265 # CHECK-EXPAND: lui a1, 1
266 # CHECK-EXPAND: addiw a1, a1, -1
269 # CHECK-EXPAND: lui a1, 1048575
270 # CHECK-EXPAND: addiw a1, a1, 1
273 # CHECK-EXPAND: lui a2, 1
276 # CHECK-EXPAND: lui a2, 1048575
279 # CHECK-EXPAND: lui a2, 1
280 # CHECK-EXPAND: addiw a2, a2, 1
283 # CHECK-EXPAND: lui a2, 1048575
284 # CHECK-EXPAND: addiw a2, a2, -1
287 # CHECK-EXPAND: lui a2, 524288
288 # CHECK-EXPAND: addiw a2, a2, -1
291 # CHECK-EXPAND: lui a2, 524288
292 # CHECK-EXPAND: addiw a2, a2, 1
295 # CHECK-EXPAND: lui a2, 524288
298 # CHECK-EXPAND: lui a2, 524288
302 # CHECK-INST: addi a2, zero, 1
303 # CHECK-INST-NEXT: slli a2, a2, 31
304 # CHECK-ALIAS: li a2, 1
305 # CHECK-ALIAS-NEXT: slli a2, a2, 31
308 # CHECK-INST: addi a2, zero, -1
309 # CHECK-INST-NEXT: srli a2, a2, 32
310 # CHECK-ALIAS: li a2, -1
311 # CHECK-ALIAS-NEXT: srli a2, a2, 32
315 # CHECK-INST: addi t0, zero, 1
316 # CHECK-INST-NEXT: slli t0, t0, 32
317 # CHECK-ALIAS: li t0, 1
318 # CHECK-ALIAS-NEXT: slli t0, t0, 32
321 # CHECK-INST: addi t1, zero, -1
322 # CHECK-INST-NEXT: slli t1, t1, 63
323 # CHECK-ALIAS: li t1, -1
324 # CHECK-ALIAS-NEXT: slli t1, t1, 63
325 la t1
, 0x8000000000000000
326 lla t1
, 0x8000000000000000
327 # CHECK-INST: addi t1, zero, -1
328 # CHECK-INST-NEXT: slli t1, t1, 63
329 # CHECK-ALIAS: li t1, -1
330 # CHECK-ALIAS-NEXT: slli t1, t1, 63
331 la t1
, -0x8000000000000000
332 lla t1
, -0x8000000000000000
333 # CHECK-EXPAND: lui t2, 9321
334 # CHECK-EXPAND-NEXT: addiw t2, t2, -1329
335 # CHECK-EXPAND-NEXT: slli t2, t2, 35
336 la t2
, 0x1234567800000000
337 lla t2
, 0x1234567800000000
338 # CHECK-INST: addi t3, zero, 7
339 # CHECK-INST-NEXT: slli t3, t3, 36
340 # CHECK-INST-NEXT: addi t3, t3, 11
341 # CHECK-INST-NEXT: slli t3, t3, 24
342 # CHECK-INST-NEXT: addi t3, t3, 15
343 # CHECK-ALIAS: li t3, 7
344 # CHECK-ALIAS-NEXT: slli t3, t3, 36
345 # CHECK-ALIAS-NEXT: addi t3, t3, 11
346 # CHECK-ALIAS-NEXT: slli t3, t3, 24
347 # CHECK-ALIAS-NEXT: addi t3, t3, 15
348 la t3
, 0x700000000B00000F
349 lla t3
, 0x700000000B00000F
350 # CHECK-EXPAND: lui t4, 583
351 # CHECK-EXPAND-NEXT: addiw t4, t4, -1875
352 # CHECK-EXPAND-NEXT: slli t4, t4, 14
353 # CHECK-EXPAND-NEXT: addi t4, t4, -947
354 # CHECK-EXPAND-NEXT: slli t4, t4, 12
355 # CHECK-EXPAND-NEXT: addi t4, t4, 1511
356 # CHECK-EXPAND-NEXT: slli t4, t4, 13
357 # CHECK-EXPAND-NEXT: addi t4, t4, -272
358 la t4
, 0x123456789abcdef0
359 lla t4
, 0x123456789abcdef0
360 # CHECK-INST: addi t5, zero, -1
361 # CHECK-ALIAS: li t5, -1
362 la t5
, 0xFFFFFFFFFFFFFFFF
363 lla t5
, 0xFFFFFFFFFFFFFFFF
364 # CHECK-EXPAND: lui t6, 262145
365 # CHECK-EXPAND-NEXT: slli t6, t6, 1
368 # CHECK-EXPAND: lui t0, 262145
369 # CHECK-EXPAND-NEXT: slli t0, t0, 2
372 # CHECK-EXPAND: lui t1, 4097
373 # CHECK-EXPAND-NEXT: slli t1, t1, 20
374 la x6
, 0x100100000000
375 lla x6
, 0x100100000000
376 # CHECK-EXPAND: lui t2, 983056
377 # CHECK-EXPAND-NEXT: srli t2, t2, 16
378 la x7
, 0xFFFFFFFFF001
379 lla x7
, 0xFFFFFFFFF001
380 # CHECK-EXPAND: lui s0, 1044481
381 # CHECK-EXPAND-NEXT: slli s0, s0, 12
382 # CHECK-EXPAND-NEXT: srli s0, s0, 24
385 # CHECK-EXPAND: lui s1, 4097
386 # CHECK-EXPAND-NEXT: slli s1, s1, 20
387 # CHECK-EXPAND-NEXT: addi s1, s1, -3
388 la x9
, 0x1000FFFFFFFD
389 lla x9
, 0x1000FFFFFFFD
390 # CHECK-INST: lui a0, 983040
391 # CHECK-INST-NEXT: srli a0, a0, 3
392 # CHECK-INST-NEXT: xori a0, a0, -1
393 # CHECK-ALIAS: lui a0, 983040
394 # CHECK-ALIAS-NEXT: srli a0, a0, 3
395 # CHECK-ALIAS-NEXT: not a0, a0
396 la x10
, 0xE000000001FFFFFF
397 lla x10
, 0xE000000001FFFFFF
398 # CHECK-INST: addi a1, zero, -2047
399 # CHECK-INST-NEXT: slli a1, a1, 39
400 # CHECK-INST-NEXT: addi a1, a1, -2048
401 # CHECK-INST-NEXT: addi a1, a1, -1
402 # CHECK-ALIAS: li a1, -2047
403 # CHECK-ALIAS-NEXT: slli a1, a1, 39
404 # CHECK-ALIAS-NEXT: addi a1, a1, -2048
405 # CHECK-ALIAS-NEXT: addi a1, a1, -1
406 la x11
, 0xFFFC007FFFFFF7FF
407 lla x11
, 0xFFFC007FFFFFF7FF
409 # CHECK-INST: lui a2, 349525
410 # CHECK-INST-NEXT: addiw a2, a2, 1365
411 # CHECK-INST-NEXT: slli a2, a2, 1
412 # CHECK-ALIAS: lui a2, 349525
413 # CHECK-ALIAS-NEXT: addiw a2, a2, 1365
414 # CHECK-ALIAS-NEXT: slli a2, a2, 1
418 # CHECK-INST: lui a3, 699051
419 # CHECK-INST-NEXT: addiw a3, a3, -1365
420 # CHECK-INST-NEXT: slli a3, a3, 1
421 # CHECK-ALIAS: lui a3, 699051
422 # CHECK-ALIAS-NEXT: addiw a3, a3, -1365
423 # CHECK-ALIAS-NEXT: slli a3, a3, 1
424 la x13
, 0xffffffff55555556
425 lla x13
, 0xffffffff55555556
427 # CHECK-S-OBJ-NOALIAS: lui t0, 524288
428 # CHECK-S-OBJ-NOALIAS-NEXT: addi t0, t0, -1365
429 # CHECK-S-OBJ: lui t0, 524288
430 # CHECK-S-OBJ-NEXT: addi t0, t0, -1365
434 .equ CONSTANT, 0x123456
435 # CHECK-EXPAND: lui a0, 291
436 # CHECK-EXPAND: addiw a0, a0, 1110
440 .equ CONSTANT, 0x654321
441 # CHECK-EXPAND: lui a0, 1620
442 # CHECK-EXPAND: addiw a0, a0, 801
446 # CHECK-INST: subw t6, zero, ra
447 # CHECK-ALIAS: negw t6, ra
449 # CHECK-INST: addiw t6, ra, 0
450 # CHECK-ALIAS: sext.w t6, ra
453 # The following aliases are accepted as input but the canonical form
454 # of the instruction will always be printed.
455 # CHECK-INST: addiw a2, a3, 4
456 # CHECK-ALIAS: addiw a2, a3, 4
459 # CHECK-INST: slliw a2, a3, 4
460 # CHECK-ALIAS: slliw a2, a3, 4
463 # CHECK-INST: srliw a2, a3, 4
464 # CHECK-ALIAS: srliw a2, a3, 4
467 # CHECK-INST: sraiw a2, a3, 4
468 # CHECK-ALIAS: sraiw a2, a3, 4
471 # CHECK-EXPAND: lwu a0, 0(a1)
473 # CHECK-EXPAND: ld a0, 0(a1)
475 # CHECK-EXPAND: sd a0, 0(a1)
478 # CHECK-EXPAND: slli a0, a1, 56
479 # CHECK-EXPAND: srai a0, a0, 56
482 # CHECK-EXPAND: slli a0, a1, 48
483 # CHECK-EXPAND: srai a0, a0, 48
486 # CHECK-INST: andi a0, a1, 255
487 # CHECK-ALIAS: andi a0, a1, 255
490 # CHECK-EXPAND: slli a0, a1, 48
491 # CHECK-EXPAND: srli a0, a0, 48
494 # CHECK-EXPAND: slli a0, a1, 32
495 # CHECK-EXPAND: srli a0, a0, 32