1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=riscv64 -verify-machineinstrs < %s \
3 ; RUN: -riscv-experimental-rv64-legal-i32 | FileCheck %s -check-prefixes=CHECK,RV64I
4 ; RUN: llc -mtriple=riscv64 -mattr=+zbb -verify-machineinstrs < %s \
5 ; RUN: -riscv-experimental-rv64-legal-i32 | FileCheck %s -check-prefixes=CHECK,RV64ZBB-ZBKB,RV64ZBB
6 ; RUN: llc -mtriple=riscv64 -mattr=+zbkb -verify-machineinstrs < %s \
7 ; RUN: -riscv-experimental-rv64-legal-i32 | FileCheck %s -check-prefixes=CHECK,RV64ZBB-ZBKB,RV64ZBKB
9 define signext i32 @andn_i32(i32 signext %a, i32 signext %b) nounwind {
10 ; RV64I-LABEL: andn_i32:
12 ; RV64I-NEXT: not a1, a1
13 ; RV64I-NEXT: and a0, a1, a0
16 ; RV64ZBB-ZBKB-LABEL: andn_i32:
17 ; RV64ZBB-ZBKB: # %bb.0:
18 ; RV64ZBB-ZBKB-NEXT: andn a0, a0, a1
19 ; RV64ZBB-ZBKB-NEXT: ret
21 %and = and i32 %neg, %a
25 define i64 @andn_i64(i64 %a, i64 %b) nounwind {
26 ; RV64I-LABEL: andn_i64:
28 ; RV64I-NEXT: not a1, a1
29 ; RV64I-NEXT: and a0, a1, a0
32 ; RV64ZBB-ZBKB-LABEL: andn_i64:
33 ; RV64ZBB-ZBKB: # %bb.0:
34 ; RV64ZBB-ZBKB-NEXT: andn a0, a0, a1
35 ; RV64ZBB-ZBKB-NEXT: ret
37 %and = and i64 %neg, %a
41 define signext i32 @orn_i32(i32 signext %a, i32 signext %b) nounwind {
42 ; RV64I-LABEL: orn_i32:
44 ; RV64I-NEXT: not a1, a1
45 ; RV64I-NEXT: or a0, a1, a0
48 ; RV64ZBB-ZBKB-LABEL: orn_i32:
49 ; RV64ZBB-ZBKB: # %bb.0:
50 ; RV64ZBB-ZBKB-NEXT: orn a0, a0, a1
51 ; RV64ZBB-ZBKB-NEXT: ret
57 define i64 @orn_i64(i64 %a, i64 %b) nounwind {
58 ; RV64I-LABEL: orn_i64:
60 ; RV64I-NEXT: not a1, a1
61 ; RV64I-NEXT: or a0, a1, a0
64 ; RV64ZBB-ZBKB-LABEL: orn_i64:
65 ; RV64ZBB-ZBKB: # %bb.0:
66 ; RV64ZBB-ZBKB-NEXT: orn a0, a0, a1
67 ; RV64ZBB-ZBKB-NEXT: ret
73 define signext i32 @xnor_i32(i32 signext %a, i32 signext %b) nounwind {
74 ; CHECK-LABEL: xnor_i32:
76 ; CHECK-NEXT: xor a0, a0, a1
77 ; CHECK-NEXT: not a0, a0
80 %xor = xor i32 %neg, %b
84 define i64 @xnor_i64(i64 %a, i64 %b) nounwind {
85 ; RV64I-LABEL: xnor_i64:
87 ; RV64I-NEXT: xor a0, a0, a1
88 ; RV64I-NEXT: not a0, a0
91 ; RV64ZBB-ZBKB-LABEL: xnor_i64:
92 ; RV64ZBB-ZBKB: # %bb.0:
93 ; RV64ZBB-ZBKB-NEXT: xnor a0, a0, a1
94 ; RV64ZBB-ZBKB-NEXT: ret
96 %xor = xor i64 %neg, %b
100 declare i32 @llvm.fshl.i32(i32, i32, i32)
102 define signext i32 @rol_i32(i32 signext %a, i32 signext %b) nounwind {
103 ; RV64I-LABEL: rol_i32:
105 ; RV64I-NEXT: andi a2, a1, -1
106 ; RV64I-NEXT: sllw a1, a0, a1
107 ; RV64I-NEXT: negw a2, a2
108 ; RV64I-NEXT: srlw a0, a0, a2
109 ; RV64I-NEXT: or a0, a1, a0
112 ; RV64ZBB-ZBKB-LABEL: rol_i32:
113 ; RV64ZBB-ZBKB: # %bb.0:
114 ; RV64ZBB-ZBKB-NEXT: rolw a0, a0, a1
115 ; RV64ZBB-ZBKB-NEXT: ret
116 %1 = tail call i32 @llvm.fshl.i32(i32 %a, i32 %a, i32 %b)
120 ; Similar to rol_i32, but doesn't sign extend the result.
121 define void @rol_i32_nosext(i32 signext %a, i32 signext %b, ptr %x) nounwind {
122 ; RV64I-LABEL: rol_i32_nosext:
124 ; RV64I-NEXT: andi a3, a1, -1
125 ; RV64I-NEXT: sllw a1, a0, a1
126 ; RV64I-NEXT: negw a3, a3
127 ; RV64I-NEXT: srlw a0, a0, a3
128 ; RV64I-NEXT: or a0, a1, a0
129 ; RV64I-NEXT: sw a0, 0(a2)
132 ; RV64ZBB-ZBKB-LABEL: rol_i32_nosext:
133 ; RV64ZBB-ZBKB: # %bb.0:
134 ; RV64ZBB-ZBKB-NEXT: rolw a0, a0, a1
135 ; RV64ZBB-ZBKB-NEXT: sw a0, 0(a2)
136 ; RV64ZBB-ZBKB-NEXT: ret
137 %1 = tail call i32 @llvm.fshl.i32(i32 %a, i32 %a, i32 %b)
142 define signext i32 @rol_i32_neg_constant_rhs(i32 signext %a) nounwind {
143 ; RV64I-LABEL: rol_i32_neg_constant_rhs:
145 ; RV64I-NEXT: andi a1, a0, -1
146 ; RV64I-NEXT: li a2, -2
147 ; RV64I-NEXT: sllw a0, a2, a0
148 ; RV64I-NEXT: negw a1, a1
149 ; RV64I-NEXT: srlw a1, a2, a1
150 ; RV64I-NEXT: or a0, a0, a1
153 ; RV64ZBB-ZBKB-LABEL: rol_i32_neg_constant_rhs:
154 ; RV64ZBB-ZBKB: # %bb.0:
155 ; RV64ZBB-ZBKB-NEXT: li a1, -2
156 ; RV64ZBB-ZBKB-NEXT: rolw a0, a1, a0
157 ; RV64ZBB-ZBKB-NEXT: ret
158 %1 = tail call i32 @llvm.fshl.i32(i32 -2, i32 -2, i32 %a)
162 declare i64 @llvm.fshl.i64(i64, i64, i64)
164 define i64 @rol_i64(i64 %a, i64 %b) nounwind {
165 ; RV64I-LABEL: rol_i64:
167 ; RV64I-NEXT: sll a2, a0, a1
168 ; RV64I-NEXT: negw a1, a1
169 ; RV64I-NEXT: srl a0, a0, a1
170 ; RV64I-NEXT: or a0, a2, a0
173 ; RV64ZBB-ZBKB-LABEL: rol_i64:
174 ; RV64ZBB-ZBKB: # %bb.0:
175 ; RV64ZBB-ZBKB-NEXT: rol a0, a0, a1
176 ; RV64ZBB-ZBKB-NEXT: ret
177 %or = tail call i64 @llvm.fshl.i64(i64 %a, i64 %a, i64 %b)
181 declare i32 @llvm.fshr.i32(i32, i32, i32)
183 define signext i32 @ror_i32(i32 signext %a, i32 signext %b) nounwind {
184 ; RV64I-LABEL: ror_i32:
186 ; RV64I-NEXT: andi a2, a1, -1
187 ; RV64I-NEXT: srlw a1, a0, a1
188 ; RV64I-NEXT: negw a2, a2
189 ; RV64I-NEXT: sllw a0, a0, a2
190 ; RV64I-NEXT: or a0, a1, a0
193 ; RV64ZBB-ZBKB-LABEL: ror_i32:
194 ; RV64ZBB-ZBKB: # %bb.0:
195 ; RV64ZBB-ZBKB-NEXT: rorw a0, a0, a1
196 ; RV64ZBB-ZBKB-NEXT: ret
197 %1 = tail call i32 @llvm.fshr.i32(i32 %a, i32 %a, i32 %b)
201 ; Similar to ror_i32, but doesn't sign extend the result.
202 define void @ror_i32_nosext(i32 signext %a, i32 signext %b, ptr %x) nounwind {
203 ; RV64I-LABEL: ror_i32_nosext:
205 ; RV64I-NEXT: andi a3, a1, -1
206 ; RV64I-NEXT: srlw a1, a0, a1
207 ; RV64I-NEXT: negw a3, a3
208 ; RV64I-NEXT: sllw a0, a0, a3
209 ; RV64I-NEXT: or a0, a1, a0
210 ; RV64I-NEXT: sw a0, 0(a2)
213 ; RV64ZBB-ZBKB-LABEL: ror_i32_nosext:
214 ; RV64ZBB-ZBKB: # %bb.0:
215 ; RV64ZBB-ZBKB-NEXT: rorw a0, a0, a1
216 ; RV64ZBB-ZBKB-NEXT: sw a0, 0(a2)
217 ; RV64ZBB-ZBKB-NEXT: ret
218 %1 = tail call i32 @llvm.fshr.i32(i32 %a, i32 %a, i32 %b)
223 define signext i32 @ror_i32_neg_constant_rhs(i32 signext %a) nounwind {
224 ; RV64I-LABEL: ror_i32_neg_constant_rhs:
226 ; RV64I-NEXT: andi a1, a0, -1
227 ; RV64I-NEXT: li a2, -2
228 ; RV64I-NEXT: srlw a0, a2, a0
229 ; RV64I-NEXT: negw a1, a1
230 ; RV64I-NEXT: sllw a1, a2, a1
231 ; RV64I-NEXT: or a0, a0, a1
234 ; RV64ZBB-ZBKB-LABEL: ror_i32_neg_constant_rhs:
235 ; RV64ZBB-ZBKB: # %bb.0:
236 ; RV64ZBB-ZBKB-NEXT: li a1, -2
237 ; RV64ZBB-ZBKB-NEXT: rorw a0, a1, a0
238 ; RV64ZBB-ZBKB-NEXT: ret
239 %1 = tail call i32 @llvm.fshr.i32(i32 -2, i32 -2, i32 %a)
243 declare i64 @llvm.fshr.i64(i64, i64, i64)
245 define i64 @ror_i64(i64 %a, i64 %b) nounwind {
246 ; RV64I-LABEL: ror_i64:
248 ; RV64I-NEXT: srl a2, a0, a1
249 ; RV64I-NEXT: negw a1, a1
250 ; RV64I-NEXT: sll a0, a0, a1
251 ; RV64I-NEXT: or a0, a2, a0
254 ; RV64ZBB-ZBKB-LABEL: ror_i64:
255 ; RV64ZBB-ZBKB: # %bb.0:
256 ; RV64ZBB-ZBKB-NEXT: ror a0, a0, a1
257 ; RV64ZBB-ZBKB-NEXT: ret
258 %or = tail call i64 @llvm.fshr.i64(i64 %a, i64 %a, i64 %b)
262 define signext i32 @rori_i32_fshl(i32 signext %a) nounwind {
263 ; RV64I-LABEL: rori_i32_fshl:
265 ; RV64I-NEXT: srliw a1, a0, 1
266 ; RV64I-NEXT: slliw a0, a0, 31
267 ; RV64I-NEXT: or a0, a0, a1
270 ; RV64ZBB-ZBKB-LABEL: rori_i32_fshl:
271 ; RV64ZBB-ZBKB: # %bb.0:
272 ; RV64ZBB-ZBKB-NEXT: roriw a0, a0, 1
273 ; RV64ZBB-ZBKB-NEXT: ret
274 %1 = tail call i32 @llvm.fshl.i32(i32 %a, i32 %a, i32 31)
278 ; Similar to rori_i32_fshl, but doesn't sign extend the result.
279 define void @rori_i32_fshl_nosext(i32 signext %a, ptr %x) nounwind {
280 ; RV64I-LABEL: rori_i32_fshl_nosext:
282 ; RV64I-NEXT: srliw a2, a0, 1
283 ; RV64I-NEXT: slli a0, a0, 31
284 ; RV64I-NEXT: or a0, a0, a2
285 ; RV64I-NEXT: sw a0, 0(a1)
288 ; RV64ZBB-ZBKB-LABEL: rori_i32_fshl_nosext:
289 ; RV64ZBB-ZBKB: # %bb.0:
290 ; RV64ZBB-ZBKB-NEXT: roriw a0, a0, 1
291 ; RV64ZBB-ZBKB-NEXT: sw a0, 0(a1)
292 ; RV64ZBB-ZBKB-NEXT: ret
293 %1 = tail call i32 @llvm.fshl.i32(i32 %a, i32 %a, i32 31)
298 define signext i32 @rori_i32_fshr(i32 signext %a) nounwind {
299 ; RV64I-LABEL: rori_i32_fshr:
301 ; RV64I-NEXT: slliw a1, a0, 1
302 ; RV64I-NEXT: srliw a0, a0, 31
303 ; RV64I-NEXT: or a0, a0, a1
306 ; RV64ZBB-ZBKB-LABEL: rori_i32_fshr:
307 ; RV64ZBB-ZBKB: # %bb.0:
308 ; RV64ZBB-ZBKB-NEXT: roriw a0, a0, 31
309 ; RV64ZBB-ZBKB-NEXT: ret
310 %1 = tail call i32 @llvm.fshr.i32(i32 %a, i32 %a, i32 31)
314 ; Similar to rori_i32_fshr, but doesn't sign extend the result.
315 define void @rori_i32_fshr_nosext(i32 signext %a, ptr %x) nounwind {
316 ; RV64I-LABEL: rori_i32_fshr_nosext:
318 ; RV64I-NEXT: slli a2, a0, 1
319 ; RV64I-NEXT: srliw a0, a0, 31
320 ; RV64I-NEXT: or a0, a0, a2
321 ; RV64I-NEXT: sw a0, 0(a1)
324 ; RV64ZBB-ZBKB-LABEL: rori_i32_fshr_nosext:
325 ; RV64ZBB-ZBKB: # %bb.0:
326 ; RV64ZBB-ZBKB-NEXT: roriw a0, a0, 31
327 ; RV64ZBB-ZBKB-NEXT: sw a0, 0(a1)
328 ; RV64ZBB-ZBKB-NEXT: ret
329 %1 = tail call i32 @llvm.fshr.i32(i32 %a, i32 %a, i32 31)
334 ; This test is similar to the type legalized version of the fshl/fshr tests, but
335 ; instead of having the same input to both shifts it has different inputs. Make
336 ; sure we don't match it as a roriw.
337 define signext i32 @not_rori_i32(i32 signext %x, i32 signext %y) nounwind {
338 ; CHECK-LABEL: not_rori_i32:
340 ; CHECK-NEXT: slliw a0, a0, 31
341 ; CHECK-NEXT: srliw a1, a1, 1
342 ; CHECK-NEXT: or a0, a0, a1
350 ; This is similar to the type legalized roriw pattern, but the and mask is more
351 ; than 32 bits so the lshr doesn't shift zeroes into the lower 32 bits. Make
352 ; sure we don't match it to roriw.
353 define i64 @roriw_bug(i64 %x) nounwind {
354 ; CHECK-LABEL: roriw_bug:
356 ; CHECK-NEXT: slli a1, a0, 31
357 ; CHECK-NEXT: andi a2, a0, -2
358 ; CHECK-NEXT: srli a0, a0, 1
359 ; CHECK-NEXT: or a0, a1, a0
360 ; CHECK-NEXT: sext.w a0, a0
361 ; CHECK-NEXT: xor a0, a2, a0
364 %b = and i64 %x, 18446744073709551614
369 %g = xor i64 %b, %f ; to increase the use count on %b to disable SimplifyDemandedBits.
373 define i64 @rori_i64_fshl(i64 %a) nounwind {
374 ; RV64I-LABEL: rori_i64_fshl:
376 ; RV64I-NEXT: srli a1, a0, 1
377 ; RV64I-NEXT: slli a0, a0, 63
378 ; RV64I-NEXT: or a0, a0, a1
381 ; RV64ZBB-ZBKB-LABEL: rori_i64_fshl:
382 ; RV64ZBB-ZBKB: # %bb.0:
383 ; RV64ZBB-ZBKB-NEXT: rori a0, a0, 1
384 ; RV64ZBB-ZBKB-NEXT: ret
385 %1 = tail call i64 @llvm.fshl.i64(i64 %a, i64 %a, i64 63)
389 define i64 @rori_i64_fshr(i64 %a) nounwind {
390 ; RV64I-LABEL: rori_i64_fshr:
392 ; RV64I-NEXT: slli a1, a0, 1
393 ; RV64I-NEXT: srli a0, a0, 63
394 ; RV64I-NEXT: or a0, a0, a1
397 ; RV64ZBB-ZBKB-LABEL: rori_i64_fshr:
398 ; RV64ZBB-ZBKB: # %bb.0:
399 ; RV64ZBB-ZBKB-NEXT: rori a0, a0, 63
400 ; RV64ZBB-ZBKB-NEXT: ret
401 %1 = tail call i64 @llvm.fshr.i64(i64 %a, i64 %a, i64 63)
405 define signext i32 @not_shl_one_i32(i32 signext %x) {
406 ; RV64I-LABEL: not_shl_one_i32:
408 ; RV64I-NEXT: li a1, 1
409 ; RV64I-NEXT: sllw a0, a1, a0
410 ; RV64I-NEXT: not a0, a0
413 ; RV64ZBB-ZBKB-LABEL: not_shl_one_i32:
414 ; RV64ZBB-ZBKB: # %bb.0:
415 ; RV64ZBB-ZBKB-NEXT: li a1, -2
416 ; RV64ZBB-ZBKB-NEXT: rolw a0, a1, a0
417 ; RV64ZBB-ZBKB-NEXT: ret
423 define i64 @not_shl_one_i64(i64 %x) {
424 ; RV64I-LABEL: not_shl_one_i64:
426 ; RV64I-NEXT: li a1, 1
427 ; RV64I-NEXT: sll a0, a1, a0
428 ; RV64I-NEXT: not a0, a0
431 ; RV64ZBB-ZBKB-LABEL: not_shl_one_i64:
432 ; RV64ZBB-ZBKB: # %bb.0:
433 ; RV64ZBB-ZBKB-NEXT: li a1, -2
434 ; RV64ZBB-ZBKB-NEXT: rol a0, a1, a0
435 ; RV64ZBB-ZBKB-NEXT: ret
441 define i8 @srli_i8(i8 %a) nounwind {
442 ; CHECK-LABEL: srli_i8:
444 ; CHECK-NEXT: slli a0, a0, 56
445 ; CHECK-NEXT: srli a0, a0, 62
451 ; We could use sext.b+srai, but slli+srai offers more opportunities for
452 ; comppressed instructions.
453 define i8 @srai_i8(i8 %a) nounwind {
454 ; RV64I-LABEL: srai_i8:
456 ; RV64I-NEXT: slli a0, a0, 24
457 ; RV64I-NEXT: sraiw a0, a0, 29
460 ; RV64ZBB-LABEL: srai_i8:
462 ; RV64ZBB-NEXT: slli a0, a0, 56
463 ; RV64ZBB-NEXT: srai a0, a0, 61
466 ; RV64ZBKB-LABEL: srai_i8:
468 ; RV64ZBKB-NEXT: slli a0, a0, 24
469 ; RV64ZBKB-NEXT: sraiw a0, a0, 29
475 ; We could use zext.h+srli, but slli+srli offers more opportunities for
476 ; comppressed instructions.
477 define i16 @srli_i16(i16 %a) nounwind {
478 ; CHECK-LABEL: srli_i16:
480 ; CHECK-NEXT: slli a0, a0, 48
481 ; CHECK-NEXT: srli a0, a0, 54
487 ; We could use sext.h+srai, but slli+srai offers more opportunities for
488 ; comppressed instructions.
489 define i16 @srai_i16(i16 %a) nounwind {
490 ; RV64I-LABEL: srai_i16:
492 ; RV64I-NEXT: slli a0, a0, 16
493 ; RV64I-NEXT: sraiw a0, a0, 25
496 ; RV64ZBB-LABEL: srai_i16:
498 ; RV64ZBB-NEXT: slli a0, a0, 48
499 ; RV64ZBB-NEXT: srai a0, a0, 57
502 ; RV64ZBKB-LABEL: srai_i16:
504 ; RV64ZBKB-NEXT: slli a0, a0, 16
505 ; RV64ZBKB-NEXT: sraiw a0, a0, 25
511 define i1 @andn_seqz_i32(i32 signext %a, i32 signext %b) nounwind {
512 ; RV64I-LABEL: andn_seqz_i32:
514 ; RV64I-NEXT: and a0, a0, a1
515 ; RV64I-NEXT: xor a0, a0, a1
516 ; RV64I-NEXT: seqz a0, a0
519 ; RV64ZBB-ZBKB-LABEL: andn_seqz_i32:
520 ; RV64ZBB-ZBKB: # %bb.0:
521 ; RV64ZBB-ZBKB-NEXT: andn a0, a1, a0
522 ; RV64ZBB-ZBKB-NEXT: seqz a0, a0
523 ; RV64ZBB-ZBKB-NEXT: ret
524 %and = and i32 %a, %b
525 %cmpeq = icmp eq i32 %and, %b
529 define i1 @andn_seqz_i64(i64 %a, i64 %b) nounwind {
530 ; RV64I-LABEL: andn_seqz_i64:
532 ; RV64I-NEXT: and a0, a0, a1
533 ; RV64I-NEXT: xor a0, a0, a1
534 ; RV64I-NEXT: seqz a0, a0
537 ; RV64ZBB-ZBKB-LABEL: andn_seqz_i64:
538 ; RV64ZBB-ZBKB: # %bb.0:
539 ; RV64ZBB-ZBKB-NEXT: andn a0, a1, a0
540 ; RV64ZBB-ZBKB-NEXT: seqz a0, a0
541 ; RV64ZBB-ZBKB-NEXT: ret
542 %and = and i64 %a, %b
543 %cmpeq = icmp eq i64 %and, %b
547 define i1 @andn_snez_i32(i32 signext %a, i32 signext %b) nounwind {
548 ; RV64I-LABEL: andn_snez_i32:
550 ; RV64I-NEXT: and a0, a0, a1
551 ; RV64I-NEXT: xor a0, a0, a1
552 ; RV64I-NEXT: snez a0, a0
555 ; RV64ZBB-ZBKB-LABEL: andn_snez_i32:
556 ; RV64ZBB-ZBKB: # %bb.0:
557 ; RV64ZBB-ZBKB-NEXT: andn a0, a1, a0
558 ; RV64ZBB-ZBKB-NEXT: snez a0, a0
559 ; RV64ZBB-ZBKB-NEXT: ret
560 %and = and i32 %a, %b
561 %cmpeq = icmp ne i32 %and, %b
565 define i1 @andn_snez_i64(i64 %a, i64 %b) nounwind {
566 ; RV64I-LABEL: andn_snez_i64:
568 ; RV64I-NEXT: and a0, a0, a1
569 ; RV64I-NEXT: xor a0, a0, a1
570 ; RV64I-NEXT: snez a0, a0
573 ; RV64ZBB-ZBKB-LABEL: andn_snez_i64:
574 ; RV64ZBB-ZBKB: # %bb.0:
575 ; RV64ZBB-ZBKB-NEXT: andn a0, a1, a0
576 ; RV64ZBB-ZBKB-NEXT: snez a0, a0
577 ; RV64ZBB-ZBKB-NEXT: ret
578 %and = and i64 %a, %b
579 %cmpeq = icmp ne i64 %and, %b