[DAGCombiner] Add target hook function to decide folding (mul (add x, c1), c2)
[llvm-project.git] / llvm / test / MC / RISCV / rv32i-valid.s
blob64883e8b5ba6f4299d63d62a1923b578cee5bf29
1 # RUN: llvm-mc %s -triple=riscv32 -riscv-no-aliases -show-encoding \
2 # RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
3 # RUN: llvm-mc %s -triple riscv64 -riscv-no-aliases -show-encoding \
4 # RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
5 # RUN: llvm-mc -filetype=obj -triple=riscv32 < %s \
6 # RUN: | llvm-objdump -M no-aliases -d -r - \
7 # RUN: | FileCheck -check-prefixes=CHECK-OBJ,CHECK-OBJ32,CHECK-ASM-AND-OBJ %s
8 # RUN: llvm-mc -filetype=obj -triple=riscv64 < %s \
9 # RUN: | llvm-objdump -M no-aliases -d -r - \
10 # RUN: | FileCheck -check-prefixes=CHECK-OBJ,CHECK-OBJ64,CHECK-ASM-AND-OBJ %s
12 .equ CONST, 30
14 # Needed for testing valid %pcrel_lo expressions
15 .Lpcrel_hi0: auipc a0, %pcrel_hi(foo)
17 # CHECK-ASM-AND-OBJ: lui a0, 2
18 # CHECK-ASM: encoding: [0x37,0x25,0x00,0x00]
19 lui a0, 2
20 # CHECK-ASM-AND-OBJ: lui s11, 552960
21 # CHECK-ASM: encoding: [0xb7,0x0d,0x00,0x87]
22 lui s11, (0x87000000>>12)
23 # CHECK-ASM-AND-OBJ: lui a0, 0
24 # CHECK-ASM: encoding: [0x37,0x05,0x00,0x00]
25 lui a0, %hi(2)
26 # CHECK-ASM-AND-OBJ: lui s11, 552960
27 # CHECK-ASM: encoding: [0xb7,0x0d,0x00,0x87]
28 lui s11, (0x87000000>>12)
29 # CHECK-ASM-AND-OBJ: lui s11, 552960
30 # CHECK-ASM: encoding: [0xb7,0x0d,0x00,0x87]
31 lui s11, %hi(0x87000000)
32 # CHECK-ASM-AND-OBJ: lui t0, 1048575
33 # CHECK-ASM: encoding: [0xb7,0xf2,0xff,0xff]
34 lui t0, 1048575
35 # CHECK-ASM-AND-OBJ: lui gp, 0
36 # CHECK-ASM: encoding: [0xb7,0x01,0x00,0x00]
37 lui gp, 0
38 # CHECK-ASM: lui a0, %hi(foo)
39 # CHECK-ASM: encoding: [0x37,0bAAAA0101,A,A]
40 # CHECK-OBJ: lui a0, 0
41 # CHECK-OBJ: R_RISCV_HI20 foo
42 lui a0, %hi(foo)
43 # CHECK-ASM-AND-OBJ: lui a0, 30
44 # CHECK-ASM: encoding: [0x37,0xe5,0x01,0x00]
45 lui a0, CONST
46 # CHECK-ASM-AND-OBJ: lui a0, 31
47 # CHECK-ASM: encoding: [0x37,0xf5,0x01,0x00]
48 lui a0, CONST+1
50 # CHECK-ASM-AND-OBJ: auipc a0, 2
51 # CHECK-ASM: encoding: [0x17,0x25,0x00,0x00]
52 auipc a0, 2
53 # CHECK-ASM-AND-OBJ: auipc s11, 552960
54 # CHECK-ASM: encoding: [0x97,0x0d,0x00,0x87]
55 auipc s11, (0x87000000>>12)
56 # CHECK-ASM-AND-OBJ: auipc t0, 1048575
57 # CHECK-ASM: encoding: [0x97,0xf2,0xff,0xff]
58 auipc t0, 1048575
59 # CHECK-ASM-AND-OBJ: auipc gp, 0
60 # CHECK-ASM: encoding: [0x97,0x01,0x00,0x00]
61 auipc gp, 0
62 # CHECK-ASM: auipc a0, %pcrel_hi(foo)
63 # CHECK-ASM: encoding: [0x17,0bAAAA0101,A,A]
64 # CHECK-OBJ: auipc a0, 0
65 # CHECK-OBJ: R_RISCV_PCREL_HI20 foo
66 auipc a0, %pcrel_hi(foo)
67 # CHECK-ASM-AND-OBJ: auipc a0, 30
68 # CHECK-ASM: encoding: [0x17,0xe5,0x01,0x00]
69 auipc a0, CONST
71 # CHECK-OBJ: jal a2, 0x100042
72 # CHECK-ASM: jal a2, 1048574
73 # CHECK-ASM: encoding: [0x6f,0xf6,0xff,0x7f]
74 jal a2, 1048574
75 # CHECK-OBJ: jal a3, 0x148
76 # CHECK-ASM: jal a3, 256
77 # CHECK-ASM: encoding: [0xef,0x06,0x00,0x10]
78 jal a3, 256
79 # CHECK-ASM: jal a0, foo
80 # CHECK-ASM: encoding: [0x6f,0bAAAA0101,A,A]
81 # CHECK-OBJ: jal a0, 0
82 # CHECK-OBJ: R_RISCV_JAL foo
83 jal a0, foo
84 # CHECK-ASM: jal a0, a0
85 # CHECK-ASM: encoding: [0x6f,0bAAAA0101,A,A]
86 # CHECK-OBJ: jal a0, 0
87 # CHECK-OBJ: R_RISCV_JAL a0
88 jal a0, a0
89 # CHECK-OBJ: jal a0, 0x72
90 # CHECK-ASM: jal a0, 30
91 # CHECK-ASM: encoding: [0x6f,0x05,0xe0,0x01]
92 jal a0, CONST
93 # CHECK-ASM-AND-OBJ: jal s0, 0
94 # CHECK-ASM: encoding: [0x6f,0x04,0x00,0x00]
95 jal s0, (0)
96 # CHECK-OBJ: jal s0, 0xf8
97 # CHECK-ASM: jal s0, 156
98 # CHECK-ASM: encoding: [0x6f,0x04,0xc0,0x09]
99 jal s0, (0xff-99)
100 # CHECK-ASM: encoding: [0x6f,0bAAAA0000,A,A]
101 # CHECK-OBJ: jal zero, 0
102 jal zero, .
104 # CHECK-ASM-AND-OBJ: jalr a0, -2048(a1)
105 # CHECK-ASM: encoding: [0x67,0x85,0x05,0x80]
106 jalr a0, -2048(a1)
107 # CHECK-ASM-AND-OBJ: jalr a0, -2048(a1)
108 # CHECK-ASM: encoding: [0x67,0x85,0x05,0x80]
109 jalr a0, %lo(2048)(a1)
110 # CHECK-ASM-AND-OBJ: jalr t2, 2047(t1)
111 # CHECK-ASM: encoding: [0xe7,0x03,0xf3,0x7f]
112 jalr t2, 2047(t1)
113 # CHECK-ASM-AND-OBJ: jalr sp, 256(zero)
114 # CHECK-ASM: encoding: [0x67,0x01,0x00,0x10]
115 jalr sp, zero, 256
116 # CHECK-ASM-AND-OBJ: jalr a1, 30(a2)
117 # CHECK-ASM: encoding: [0xe7,0x05,0xe6,0x01]
118 jalr a1, CONST(a2)
120 # CHECK-OBJ: beq s1, s1, 0xde
121 # CHECK-ASM: beq s1, s1, 102
122 # CHECK-ASM: encoding: [0x63,0x83,0x94,0x06]
123 beq s1, s1, 102
124 # CHECK-OBJ32: bne a4, a5, 0xfffff07c
125 # CHECK-OBJ64: bne a4, a5, 0xfffffffffffff07c
126 # CHECK-ASM: bne a4, a5, -4096
127 # CHECK-ASM: encoding: [0x63,0x10,0xf7,0x80]
128 bne a4, a5, -4096
129 # CHECK-OBJ: blt sp, gp, 0x107e
130 # CHECK-ASM: blt sp, gp, 4094
131 # CHECK-ASM: encoding: [0xe3,0x4f,0x31,0x7e]
132 blt sp, gp, 4094
133 # CHECK-OBJ32: bge s2, ra, 0xffffffa4
134 # CHECK-OBJ64: bge s2, ra, 0xffffffffffffffa4
135 # CHECK-ASM: bge s2, ra, -224
136 # CHECK-ASM: encoding: [0xe3,0x50,0x19,0xf2]
137 bge s2, ra, -224
138 # CHECK-ASM-AND-OBJ: bltu zero, zero, 0
139 # CHECK-ASM: encoding: [0x63,0x60,0x00,0x00]
140 bltu zero, zero, 0
141 # CHECK-OBJ: bgeu s8, sp, 0x28c
142 # CHECK-ASM: bgeu s8, sp, 512
143 # CHECK-ASM: encoding: [0x63,0x70,0x2c,0x20]
144 bgeu s8, sp, 512
145 # CHECK-OBJ: bgeu t0, t1, 0xae
146 # CHECK-ASM: bgeu t0, t1, 30
147 # CHECK-ASM: encoding: [0x63,0xff,0x62,0x00]
148 bgeu t0, t1, CONST
150 # CHECK-ASM-AND-OBJ: lb s3, 4(ra)
151 # CHECK-ASM: encoding: [0x83,0x89,0x40,0x00]
152 lb s3, 4(ra)
153 # CHECK-ASM-AND-OBJ: lb s3, 4(ra)
154 # CHECK-ASM: encoding: [0x83,0x89,0x40,0x00]
155 lb s3, +4(ra)
156 # CHECK-ASM-AND-OBJ: lh t1, -2048(zero)
157 # CHECK-ASM: encoding: [0x03,0x13,0x00,0x80]
158 lh t1, -2048(zero)
159 # CHECK-ASM-AND-OBJ: lh t1, -2048(zero)
160 # CHECK-ASM: encoding: [0x03,0x13,0x00,0x80]
161 lh t1, ~2047(zero)
162 # CHECK-ASM-AND-OBJ: lh t1, 0(zero)
163 # CHECK-ASM: encoding: [0x03,0x13,0x00,0x00]
164 lh t1, !1(zero)
165 # CHECK-ASM-AND-OBJ: lh t1, -2048(zero)
166 # CHECK-ASM: encoding: [0x03,0x13,0x00,0x80]
167 lh t1, %lo(2048)(zero)
168 # CHECK-ASM-AND-OBJ: lh sp, 2047(a0)
169 # CHECK-ASM: encoding: [0x03,0x11,0xf5,0x7f]
170 lh sp, 2047(a0)
171 # CHECK-ASM-AND-OBJ: lw a0, 97(a2)
172 # CHECK-ASM: encoding: [0x03,0x25,0x16,0x06]
173 lw a0, 97(a2)
174 # CHECK-ASM: lbu s5, %lo(foo)(s6)
175 # CHECK-ASM: encoding: [0x83,0x4a,0bAAAA1011,A]
176 # CHECK-OBJ: lbu s5, 0(s6)
177 # CHECK-OBJ: R_RISCV_LO12
178 lbu s5, %lo(foo)(s6)
179 # CHECK-ASM: lhu t3, %pcrel_lo(.Lpcrel_hi0)(t3)
180 # CHECK-ASM: encoding: [0x03,0x5e,0bAAAA1110,A]
181 # CHECK-OBJ: lhu t3, 0(t3)
182 # CHECK-OBJ: R_RISCV_PCREL_LO12
183 lhu t3, %pcrel_lo(.Lpcrel_hi0)(t3)
184 # CHECK-ASM-AND-OBJ: lb t0, 30(t1)
185 # CHECK-ASM: encoding: [0x83,0x02,0xe3,0x01]
186 lb t0, CONST(t1)
187 # CHECK-ASM-AND-OBJ: lb s0, 0(s1)
188 # CHECK-ASM: encoding: [0x03,0x84,0x04,0x00]
189 lb s0, (0)(s1)
190 # CHECK-ASM-AND-OBJ: lb s0, 156(s1)
191 # CHECK-ASM: encoding: [0x03,0x84,0xc4,0x09]
192 lb s0, (0xff-99)(s1)
194 # CHECK-ASM-AND-OBJ: sb a0, 2047(a2)
195 # CHECK-ASM: encoding: [0xa3,0x0f,0xa6,0x7e]
196 sb a0, 2047(a2)
197 # CHECK-ASM-AND-OBJ: sh t3, -2048(t5)
198 # CHECK-ASM: encoding: [0x23,0x10,0xcf,0x81]
199 sh t3, -2048(t5)
200 # CHECK-ASM-AND-OBJ: sh t3, -2048(t5)
201 # CHECK-ASM: encoding: [0x23,0x10,0xcf,0x81]
202 sh t3, ~2047(t5)
203 # CHECK-ASM-AND-OBJ: sh t3, 0(t5)
204 # CHECK-ASM: encoding: [0x23,0x10,0xcf,0x01]
205 sh t3, !1(t5)
206 # CHECK-ASM-AND-OBJ: sh t3, -2048(t5)
207 # CHECK-ASM: encoding: [0x23,0x10,0xcf,0x81]
208 sh t3, %lo(2048)(t5)
209 # CHECK-ASM-AND-OBJ: sw ra, 999(zero)
210 # CHECK-ASM: encoding: [0xa3,0x23,0x10,0x3e]
211 sw ra, 999(zero)
212 # CHECK-ASM-AND-OBJ: sw a0, 30(t0)
213 # CHECK-ASM: encoding: [0x23,0xaf,0xa2,0x00]
214 sw a0, CONST(t0)
215 # CHECK-ASM-AND-OBJ: sw s0, 0(s1)
216 # CHECK-ASM: encoding: [0x23,0xa0,0x84,0x00]
217 sw s0, (0)(s1)
218 # CHECK-ASM-AND-OBJ: sw s0, 156(s1)
219 # CHECK-ASM: encoding: [0x23,0xae,0x84,0x08]
220 sw s0, (0xff-99)(s1)
222 # CHECK-ASM-AND-OBJ: addi ra, sp, 2
223 # CHECK-ASM: encoding: [0x93,0x00,0x21,0x00]
224 addi ra, sp, 2
225 # CHECK-ASM: addi ra, sp, %lo(foo)
226 # CHECK-ASM: encoding: [0x93,0x00,0bAAAA0001,A]
227 # CHECK-OBJ: addi ra, sp, 0
228 # CHECK-OBJ: R_RISCV_LO12
229 addi ra, sp, %lo(foo)
230 # CHECK-ASM-AND-OBJ: addi ra, sp, 30
231 # CHECK-ASM: encoding: [0x93,0x00,0xe1,0x01]
232 addi ra, sp, CONST
233 # CHECK-ASM-AND-OBJ: addi ra, sp, 0
234 # CHECK-ASM: encoding: [0x93,0x00,0x01,0x00]
235 addi ra, sp, (0)
236 # CHECK-ASM-AND-OBJ: addi ra, sp, 156
237 # CHECK-ASM: encoding: [0x93,0x00,0xc1,0x09]
238 addi ra, sp, (0xff-99)
239 # CHECK-ASM-AND-OBJ: slti a0, a2, -20
240 # CHECK-ASM: encoding: [0x13,0x25,0xc6,0xfe]
241 slti a0, a2, -20
242 # CHECK-ASM-AND-OBJ: sltiu s2, s3, 80
243 # CHECK-ASM: encoding: [0x13,0xb9,0x09,0x05]
244 sltiu s2, s3, 0x50
245 # CHECK-ASM-AND-OBJ: xori tp, t1, -99
246 # CHECK-ASM: encoding: [0x13,0x42,0xd3,0xf9]
247 xori tp, t1, -99
248 # CHECK-ASM-AND-OBJ: ori a0, a1, -2048
249 # CHECK-ASM: encoding: [0x13,0xe5,0x05,0x80]
250 ori a0, a1, -2048
251 # CHECK-ASM-AND-OBJ: ori a0, a1, -2048
252 # CHECK-ASM: encoding: [0x13,0xe5,0x05,0x80]
253 ori a0, a1, ~2047
254 # CHECK-ASM-AND-OBJ: ori a0, a1, 0
255 # CHECK-ASM: encoding: [0x13,0xe5,0x05,0x00]
256 ori a0, a1, !1
257 # CHECK-ASM-AND-OBJ: ori a0, a1, -2048
258 # CHECK-ASM: encoding: [0x13,0xe5,0x05,0x80]
259 ori a0, a1, %lo(2048)
260 # CHECK-ASM-AND-OBJ: andi ra, sp, 2047
261 # CHECK-ASM: encoding: [0x93,0x70,0xf1,0x7f]
262 andi ra, sp, 2047
263 # CHECK-ASM-AND-OBJ: andi ra, sp, 2047
264 # CHECK-ASM: encoding: [0x93,0x70,0xf1,0x7f]
265 andi x1, x2, 2047
267 # CHECK-ASM-AND-OBJ: slli t3, t3, 31
268 # CHECK-ASM: encoding: [0x13,0x1e,0xfe,0x01]
269 slli t3, t3, 31
270 # CHECK-ASM-AND-OBJ: srli a0, a4, 0
271 # CHECK-ASM: encoding: [0x13,0x55,0x07,0x00]
272 srli a0, a4, 0
273 # CHECK-ASM-AND-OBJ: srai a2, sp, 15
274 # CHECK-ASM: encoding: [0x13,0x56,0xf1,0x40]
275 srai a2, sp, 15
276 # CHECK-ASM-AND-OBJ: slli t3, t3, 30
277 # CHECK-ASM: encoding: [0x13,0x1e,0xee,0x01]
278 slli t3, t3, CONST
280 # CHECK-ASM-AND-OBJ: add ra, zero, zero
281 # CHECK-ASM: encoding: [0xb3,0x00,0x00,0x00]
282 add ra, zero, zero
283 # CHECK-ASM-AND-OBJ: add ra, zero, zero
284 # CHECK-ASM: encoding: [0xb3,0x00,0x00,0x00]
285 add x1, x0, x0
286 # CHECK-ASM-AND-OBJ: sub t0, t2, t1
287 # CHECK-ASM: encoding: [0xb3,0x82,0x63,0x40]
288 sub t0, t2, t1
289 # CHECK-ASM-AND-OBJ: sll a5, a4, a3
290 # CHECK-ASM: encoding: [0xb3,0x17,0xd7,0x00]
291 sll a5, a4, a3
292 # CHECK-ASM-AND-OBJ: slt s0, s0, s0
293 # CHECK-ASM: encoding: [0x33,0x24,0x84,0x00]
294 slt s0, s0, s0
295 # CHECK-ASM-AND-OBJ: sltu gp, a0, a1
296 # CHECK-ASM: encoding: [0xb3,0x31,0xb5,0x00]
297 sltu gp, a0, a1
298 # CHECK-ASM-AND-OBJ: xor s2, s2, s8
299 # CHECK-ASM: encoding: [0x33,0x49,0x89,0x01]
300 xor s2, s2, s8
301 # CHECK-ASM-AND-OBJ: xor s2, s2, s8
302 # CHECK-ASM: encoding: [0x33,0x49,0x89,0x01]
303 xor x18, x18, x24
304 # CHECK-ASM-AND-OBJ: srl a0, s0, t0
305 # CHECK-ASM: encoding: [0x33,0x55,0x54,0x00]
306 srl a0, s0, t0
307 # CHECK-ASM-AND-OBJ: sra t0, s2, zero
308 # CHECK-ASM: encoding: [0xb3,0x52,0x09,0x40]
309 sra t0, s2, zero
310 # CHECK-ASM-AND-OBJ: or s10, t1, ra
311 # CHECK-ASM: encoding: [0x33,0x6d,0x13,0x00]
312 or s10, t1, ra
313 # CHECK-ASM-AND-OBJ: and a0, s2, s3
314 # CHECK-ASM: encoding: [0x33,0x75,0x39,0x01]
315 and a0, s2, s3
317 # CHECK-ASM-AND-OBJ: fence iorw, iorw
318 # CHECK-ASM: encoding: [0x0f,0x00,0xf0,0x0f]
319 fence iorw, iorw
320 # CHECK-ASM-AND-OBJ: fence io, rw
321 # CHECK-ASM: encoding: [0x0f,0x00,0x30,0x0c]
322 fence io, rw
323 # CHECK-ASM-AND-OBJ: fence r, w
324 # CHECK-ASM: encoding: [0x0f,0x00,0x10,0x02]
325 fence r,w
326 # CHECK-ASM-AND-OBJ: fence w, ir
327 # CHECK-ASM: encoding: [0x0f,0x00,0xa0,0x01]
328 fence w,ir
329 # CHECK-ASM-AND-OBJ: fence.tso
330 # CHECK-ASM: encoding: [0x0f,0x00,0x30,0x83]
331 fence.tso
333 # CHECK-ASM-AND-OBJ: fence.i
334 # CHECK-ASM: encoding: [0x0f,0x10,0x00,0x00]
335 fence.i
337 # CHECK-ASM-AND-OBJ: ecall
338 # CHECK-ASM: encoding: [0x73,0x00,0x00,0x00]
339 ecall
340 # CHECK-ASM-AND-OBJ: ebreak
341 # CHECK-ASM: encoding: [0x73,0x00,0x10,0x00]
342 ebreak
343 # CHECK-ASM-AND-OBJ: unimp
344 # CHECK-ASM: encoding: [0x73,0x10,0x00,0xc0]
345 unimp
347 .equ CONST, 16
349 # CHECK-ASM-AND-OBJ: csrrw t0, 4095, t1
350 # CHECK-ASM: encoding: [0xf3,0x12,0xf3,0xff]
351 csrrw t0, 0xfff, t1
352 # CHECK-ASM-AND-OBJ: csrrw s0, 4095, s1
353 # CHECK-ASM: encoding: [0x73,0x94,0xf4,0xff]
354 csrrw s0, ~(-4096), s1
355 # CHECK-ASM-AND-OBJ: csrrw s0, fflags, s1
356 # CHECK-ASM: encoding: [0x73,0x94,0x14,0x00]
357 csrrw s0, !0, s1
358 # CHECK-ASM-AND-OBJ: csrrs s0, cycle, zero
359 # CHECK-ASM: encoding: [0x73,0x24,0x00,0xc0]
360 csrrs s0, 0xc00, x0
361 # CHECK-ASM-AND-OBJ: csrrs s3, fflags, s5
362 # CHECK-ASM: encoding: [0xf3,0xa9,0x1a,0x00]
363 csrrs s3, 0x001, s5
364 # CHECK-ASM-AND-OBJ: csrrc sp, ustatus, ra
365 # CHECK-ASM: encoding: [0x73,0xb1,0x00,0x00]
366 csrrc sp, 0x000, ra
367 # CHECK-ASM-AND-OBJ: csrrwi a5, ustatus, 0
368 # CHECK-ASM: encoding: [0xf3,0x57,0x00,0x00]
369 csrrwi a5, 0x000, 0
370 # CHECK-ASM-AND-OBJ: csrrsi t2, 4095, 31
371 # CHECK-ASM: encoding: [0xf3,0xe3,0xff,0xff]
372 csrrsi t2, 0xfff, 31
373 # CHECK-ASM-AND-OBJ: csrrci t1, sscratch, 5
374 # CHECK-ASM: encoding: [0x73,0xf3,0x02,0x14]
375 csrrci t1, 0x140, 5