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