1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=riscv64 -verify-machineinstrs < %s \
3 ; RUN: | FileCheck %s -check-prefixes=CHECK,RV64I
4 ; RUN: llc -mtriple=riscv64 -mattr=+zbb -verify-machineinstrs < %s \
5 ; RUN: | FileCheck %s -check-prefixes=CHECK,RV64ZBB-ZBKB
6 ; RUN: llc -mtriple=riscv64 -mattr=+zbkb -verify-machineinstrs < %s \
7 ; RUN: | FileCheck %s -check-prefixes=CHECK,RV64ZBB-ZBKB
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 ; RV64I-LABEL: xnor_i32:
76 ; RV64I-NEXT: xor a0, a0, a1
77 ; RV64I-NEXT: not a0, a0
80 ; RV64ZBB-ZBKB-LABEL: xnor_i32:
81 ; RV64ZBB-ZBKB: # %bb.0:
82 ; RV64ZBB-ZBKB-NEXT: xnor a0, a0, a1
83 ; RV64ZBB-ZBKB-NEXT: ret
85 %xor = xor i32 %neg, %b
89 define i64 @xnor_i64(i64 %a, i64 %b) nounwind {
90 ; RV64I-LABEL: xnor_i64:
92 ; RV64I-NEXT: xor a0, a0, a1
93 ; RV64I-NEXT: not a0, a0
96 ; RV64ZBB-ZBKB-LABEL: xnor_i64:
97 ; RV64ZBB-ZBKB: # %bb.0:
98 ; RV64ZBB-ZBKB-NEXT: xnor a0, a0, a1
99 ; RV64ZBB-ZBKB-NEXT: ret
100 %neg = xor i64 %a, -1
101 %xor = xor i64 %neg, %b
105 declare i32 @llvm.fshl.i32(i32, i32, i32)
107 define signext i32 @rol_i32(i32 signext %a, i32 signext %b) nounwind {
108 ; RV64I-LABEL: rol_i32:
110 ; RV64I-NEXT: sllw a2, a0, a1
111 ; RV64I-NEXT: negw a1, a1
112 ; RV64I-NEXT: srlw a0, a0, a1
113 ; RV64I-NEXT: or a0, a2, a0
116 ; RV64ZBB-ZBKB-LABEL: rol_i32:
117 ; RV64ZBB-ZBKB: # %bb.0:
118 ; RV64ZBB-ZBKB-NEXT: rolw a0, a0, a1
119 ; RV64ZBB-ZBKB-NEXT: ret
120 %1 = tail call i32 @llvm.fshl.i32(i32 %a, i32 %a, i32 %b)
124 ; Similar to rol_i32, but doesn't sign extend the result.
125 define void @rol_i32_nosext(i32 signext %a, i32 signext %b, ptr %x) nounwind {
126 ; RV64I-LABEL: rol_i32_nosext:
128 ; RV64I-NEXT: sllw a3, a0, a1
129 ; RV64I-NEXT: negw a1, a1
130 ; RV64I-NEXT: srlw a0, a0, a1
131 ; RV64I-NEXT: or a0, a3, a0
132 ; RV64I-NEXT: sw a0, 0(a2)
135 ; RV64ZBB-ZBKB-LABEL: rol_i32_nosext:
136 ; RV64ZBB-ZBKB: # %bb.0:
137 ; RV64ZBB-ZBKB-NEXT: rolw a0, a0, a1
138 ; RV64ZBB-ZBKB-NEXT: sw a0, 0(a2)
139 ; RV64ZBB-ZBKB-NEXT: ret
140 %1 = tail call i32 @llvm.fshl.i32(i32 %a, i32 %a, i32 %b)
145 define signext i32 @rol_i32_neg_constant_rhs(i32 signext %a) nounwind {
146 ; RV64I-LABEL: rol_i32_neg_constant_rhs:
148 ; RV64I-NEXT: li a1, -2
149 ; RV64I-NEXT: sllw a2, a1, a0
150 ; RV64I-NEXT: negw a0, a0
151 ; RV64I-NEXT: srlw a0, a1, a0
152 ; RV64I-NEXT: or a0, a2, a0
155 ; RV64ZBB-ZBKB-LABEL: rol_i32_neg_constant_rhs:
156 ; RV64ZBB-ZBKB: # %bb.0:
157 ; RV64ZBB-ZBKB-NEXT: li a1, -2
158 ; RV64ZBB-ZBKB-NEXT: rolw a0, a1, a0
159 ; RV64ZBB-ZBKB-NEXT: ret
160 %1 = tail call i32 @llvm.fshl.i32(i32 -2, i32 -2, i32 %a)
164 declare i64 @llvm.fshl.i64(i64, i64, i64)
166 define i64 @rol_i64(i64 %a, i64 %b) nounwind {
167 ; RV64I-LABEL: rol_i64:
169 ; RV64I-NEXT: sll a2, a0, a1
170 ; RV64I-NEXT: negw a1, a1
171 ; RV64I-NEXT: srl a0, a0, a1
172 ; RV64I-NEXT: or a0, a2, a0
175 ; RV64ZBB-ZBKB-LABEL: rol_i64:
176 ; RV64ZBB-ZBKB: # %bb.0:
177 ; RV64ZBB-ZBKB-NEXT: rol a0, a0, a1
178 ; RV64ZBB-ZBKB-NEXT: ret
179 %or = tail call i64 @llvm.fshl.i64(i64 %a, i64 %a, i64 %b)
183 declare i32 @llvm.fshr.i32(i32, i32, i32)
185 define signext i32 @ror_i32(i32 signext %a, i32 signext %b) nounwind {
186 ; RV64I-LABEL: ror_i32:
188 ; RV64I-NEXT: srlw a2, a0, a1
189 ; RV64I-NEXT: negw a1, a1
190 ; RV64I-NEXT: sllw a0, a0, a1
191 ; RV64I-NEXT: or a0, a2, a0
194 ; RV64ZBB-ZBKB-LABEL: ror_i32:
195 ; RV64ZBB-ZBKB: # %bb.0:
196 ; RV64ZBB-ZBKB-NEXT: rorw a0, a0, a1
197 ; RV64ZBB-ZBKB-NEXT: ret
198 %1 = tail call i32 @llvm.fshr.i32(i32 %a, i32 %a, i32 %b)
202 ; Similar to ror_i32, but doesn't sign extend the result.
203 define void @ror_i32_nosext(i32 signext %a, i32 signext %b, ptr %x) nounwind {
204 ; RV64I-LABEL: ror_i32_nosext:
206 ; RV64I-NEXT: srlw a3, a0, a1
207 ; RV64I-NEXT: negw a1, a1
208 ; RV64I-NEXT: sllw a0, a0, a1
209 ; RV64I-NEXT: or a0, a3, 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: li a1, -2
227 ; RV64I-NEXT: srlw a2, a1, a0
228 ; RV64I-NEXT: negw a0, a0
229 ; RV64I-NEXT: sllw a0, a1, a0
230 ; RV64I-NEXT: or a0, a2, a0
233 ; RV64ZBB-ZBKB-LABEL: ror_i32_neg_constant_rhs:
234 ; RV64ZBB-ZBKB: # %bb.0:
235 ; RV64ZBB-ZBKB-NEXT: li a1, -2
236 ; RV64ZBB-ZBKB-NEXT: rorw a0, a1, a0
237 ; RV64ZBB-ZBKB-NEXT: ret
238 %1 = tail call i32 @llvm.fshr.i32(i32 -2, i32 -2, i32 %a)
242 declare i64 @llvm.fshr.i64(i64, i64, i64)
244 define i64 @ror_i64(i64 %a, i64 %b) nounwind {
245 ; RV64I-LABEL: ror_i64:
247 ; RV64I-NEXT: srl a2, a0, a1
248 ; RV64I-NEXT: negw a1, a1
249 ; RV64I-NEXT: sll a0, a0, a1
250 ; RV64I-NEXT: or a0, a2, a0
253 ; RV64ZBB-ZBKB-LABEL: ror_i64:
254 ; RV64ZBB-ZBKB: # %bb.0:
255 ; RV64ZBB-ZBKB-NEXT: ror a0, a0, a1
256 ; RV64ZBB-ZBKB-NEXT: ret
257 %or = tail call i64 @llvm.fshr.i64(i64 %a, i64 %a, i64 %b)
261 define signext i32 @rori_i32_fshl(i32 signext %a) nounwind {
262 ; RV64I-LABEL: rori_i32_fshl:
264 ; RV64I-NEXT: srliw a1, a0, 1
265 ; RV64I-NEXT: slliw a0, a0, 31
266 ; RV64I-NEXT: or a0, a0, a1
269 ; RV64ZBB-ZBKB-LABEL: rori_i32_fshl:
270 ; RV64ZBB-ZBKB: # %bb.0:
271 ; RV64ZBB-ZBKB-NEXT: roriw a0, a0, 1
272 ; RV64ZBB-ZBKB-NEXT: ret
273 %1 = tail call i32 @llvm.fshl.i32(i32 %a, i32 %a, i32 31)
277 ; Similar to rori_i32_fshl, but doesn't sign extend the result.
278 define void @rori_i32_fshl_nosext(i32 signext %a, ptr %x) nounwind {
279 ; RV64I-LABEL: rori_i32_fshl_nosext:
281 ; RV64I-NEXT: srliw a2, a0, 1
282 ; RV64I-NEXT: slli a0, a0, 31
283 ; RV64I-NEXT: or a0, a0, a2
284 ; RV64I-NEXT: sw a0, 0(a1)
287 ; RV64ZBB-ZBKB-LABEL: rori_i32_fshl_nosext:
288 ; RV64ZBB-ZBKB: # %bb.0:
289 ; RV64ZBB-ZBKB-NEXT: roriw a0, a0, 1
290 ; RV64ZBB-ZBKB-NEXT: sw a0, 0(a1)
291 ; RV64ZBB-ZBKB-NEXT: ret
292 %1 = tail call i32 @llvm.fshl.i32(i32 %a, i32 %a, i32 31)
297 define signext i32 @rori_i32_fshr(i32 signext %a) nounwind {
298 ; RV64I-LABEL: rori_i32_fshr:
300 ; RV64I-NEXT: slliw a1, a0, 1
301 ; RV64I-NEXT: srliw a0, a0, 31
302 ; RV64I-NEXT: or a0, a0, a1
305 ; RV64ZBB-ZBKB-LABEL: rori_i32_fshr:
306 ; RV64ZBB-ZBKB: # %bb.0:
307 ; RV64ZBB-ZBKB-NEXT: roriw a0, a0, 31
308 ; RV64ZBB-ZBKB-NEXT: ret
309 %1 = tail call i32 @llvm.fshr.i32(i32 %a, i32 %a, i32 31)
313 ; Similar to rori_i32_fshr, but doesn't sign extend the result.
314 define void @rori_i32_fshr_nosext(i32 signext %a, ptr %x) nounwind {
315 ; RV64I-LABEL: rori_i32_fshr_nosext:
317 ; RV64I-NEXT: slli a2, a0, 1
318 ; RV64I-NEXT: srliw a0, a0, 31
319 ; RV64I-NEXT: or a0, a0, a2
320 ; RV64I-NEXT: sw a0, 0(a1)
323 ; RV64ZBB-ZBKB-LABEL: rori_i32_fshr_nosext:
324 ; RV64ZBB-ZBKB: # %bb.0:
325 ; RV64ZBB-ZBKB-NEXT: roriw a0, a0, 31
326 ; RV64ZBB-ZBKB-NEXT: sw a0, 0(a1)
327 ; RV64ZBB-ZBKB-NEXT: ret
328 %1 = tail call i32 @llvm.fshr.i32(i32 %a, i32 %a, i32 31)
333 ; This test is similar to the type legalized version of the fshl/fshr tests, but
334 ; instead of having the same input to both shifts it has different inputs. Make
335 ; sure we don't match it as a roriw.
336 define signext i32 @not_rori_i32(i32 signext %x, i32 signext %y) nounwind {
337 ; CHECK-LABEL: not_rori_i32:
339 ; CHECK-NEXT: slliw a0, a0, 31
340 ; CHECK-NEXT: srliw a1, a1, 1
341 ; CHECK-NEXT: or a0, a0, a1
349 ; This is similar to the type legalized roriw pattern, but the and mask is more
350 ; than 32 bits so the lshr doesn't shift zeroes into the lower 32 bits. Make
351 ; sure we don't match it to roriw.
352 define i64 @roriw_bug(i64 %x) nounwind {
353 ; CHECK-LABEL: roriw_bug:
355 ; CHECK-NEXT: slli a1, a0, 31
356 ; CHECK-NEXT: andi a2, a0, -2
357 ; CHECK-NEXT: srli a0, a0, 1
358 ; CHECK-NEXT: or a0, a1, a0
359 ; CHECK-NEXT: sext.w a0, a0
360 ; CHECK-NEXT: xor a0, a2, a0
363 %b = and i64 %x, 18446744073709551614
368 %g = xor i64 %b, %f ; to increase the use count on %b to disable SimplifyDemandedBits.
372 define i64 @rori_i64_fshl(i64 %a) nounwind {
373 ; RV64I-LABEL: rori_i64_fshl:
375 ; RV64I-NEXT: srli a1, a0, 1
376 ; RV64I-NEXT: slli a0, a0, 63
377 ; RV64I-NEXT: or a0, a0, a1
380 ; RV64ZBB-ZBKB-LABEL: rori_i64_fshl:
381 ; RV64ZBB-ZBKB: # %bb.0:
382 ; RV64ZBB-ZBKB-NEXT: rori a0, a0, 1
383 ; RV64ZBB-ZBKB-NEXT: ret
384 %1 = tail call i64 @llvm.fshl.i64(i64 %a, i64 %a, i64 63)
388 define i64 @rori_i64_fshr(i64 %a) nounwind {
389 ; RV64I-LABEL: rori_i64_fshr:
391 ; RV64I-NEXT: slli a1, a0, 1
392 ; RV64I-NEXT: srli a0, a0, 63
393 ; RV64I-NEXT: or a0, a0, a1
396 ; RV64ZBB-ZBKB-LABEL: rori_i64_fshr:
397 ; RV64ZBB-ZBKB: # %bb.0:
398 ; RV64ZBB-ZBKB-NEXT: rori a0, a0, 63
399 ; RV64ZBB-ZBKB-NEXT: ret
400 %1 = tail call i64 @llvm.fshr.i64(i64 %a, i64 %a, i64 63)
404 define signext i32 @not_shl_one_i32(i32 signext %x) {
405 ; RV64I-LABEL: not_shl_one_i32:
407 ; RV64I-NEXT: li a1, 1
408 ; RV64I-NEXT: sllw a0, a1, a0
409 ; RV64I-NEXT: not a0, a0
412 ; RV64ZBB-ZBKB-LABEL: not_shl_one_i32:
413 ; RV64ZBB-ZBKB: # %bb.0:
414 ; RV64ZBB-ZBKB-NEXT: li a1, -2
415 ; RV64ZBB-ZBKB-NEXT: rolw a0, a1, a0
416 ; RV64ZBB-ZBKB-NEXT: ret
422 define i64 @not_shl_one_i64(i64 %x) {
423 ; RV64I-LABEL: not_shl_one_i64:
425 ; RV64I-NEXT: li a1, 1
426 ; RV64I-NEXT: sll a0, a1, a0
427 ; RV64I-NEXT: not a0, a0
430 ; RV64ZBB-ZBKB-LABEL: not_shl_one_i64:
431 ; RV64ZBB-ZBKB: # %bb.0:
432 ; RV64ZBB-ZBKB-NEXT: li a1, -2
433 ; RV64ZBB-ZBKB-NEXT: rol a0, a1, a0
434 ; RV64ZBB-ZBKB-NEXT: ret
440 define i8 @srli_i8(i8 %a) nounwind {
441 ; CHECK-LABEL: srli_i8:
443 ; CHECK-NEXT: slli a0, a0, 56
444 ; CHECK-NEXT: srli a0, a0, 62
450 ; We could use sext.b+srai, but slli+srai offers more opportunities for
451 ; comppressed instructions.
452 define i8 @srai_i8(i8 %a) nounwind {
453 ; CHECK-LABEL: srai_i8:
455 ; CHECK-NEXT: slli a0, a0, 56
456 ; CHECK-NEXT: srai a0, a0, 61
462 ; We could use zext.h+srli, but slli+srli offers more opportunities for
463 ; comppressed instructions.
464 define i16 @srli_i16(i16 %a) nounwind {
465 ; CHECK-LABEL: srli_i16:
467 ; CHECK-NEXT: slli a0, a0, 48
468 ; CHECK-NEXT: srli a0, a0, 54
474 ; We could use sext.h+srai, but slli+srai offers more opportunities for
475 ; comppressed instructions.
476 define i16 @srai_i16(i16 %a) nounwind {
477 ; CHECK-LABEL: srai_i16:
479 ; CHECK-NEXT: slli a0, a0, 48
480 ; CHECK-NEXT: srai a0, a0, 57
486 define i1 @andn_seqz_i32(i32 signext %a, i32 signext %b) nounwind {
487 ; RV64I-LABEL: andn_seqz_i32:
489 ; RV64I-NEXT: and a0, a0, a1
490 ; RV64I-NEXT: xor a0, a0, a1
491 ; RV64I-NEXT: seqz a0, a0
494 ; RV64ZBB-ZBKB-LABEL: andn_seqz_i32:
495 ; RV64ZBB-ZBKB: # %bb.0:
496 ; RV64ZBB-ZBKB-NEXT: andn a0, a1, a0
497 ; RV64ZBB-ZBKB-NEXT: seqz a0, a0
498 ; RV64ZBB-ZBKB-NEXT: ret
499 %and = and i32 %a, %b
500 %cmpeq = icmp eq i32 %and, %b
504 define i1 @andn_seqz_i64(i64 %a, i64 %b) nounwind {
505 ; RV64I-LABEL: andn_seqz_i64:
507 ; RV64I-NEXT: and a0, a0, a1
508 ; RV64I-NEXT: xor a0, a0, a1
509 ; RV64I-NEXT: seqz a0, a0
512 ; RV64ZBB-ZBKB-LABEL: andn_seqz_i64:
513 ; RV64ZBB-ZBKB: # %bb.0:
514 ; RV64ZBB-ZBKB-NEXT: andn a0, a1, a0
515 ; RV64ZBB-ZBKB-NEXT: seqz a0, a0
516 ; RV64ZBB-ZBKB-NEXT: ret
517 %and = and i64 %a, %b
518 %cmpeq = icmp eq i64 %and, %b
522 define i1 @andn_snez_i32(i32 signext %a, i32 signext %b) nounwind {
523 ; RV64I-LABEL: andn_snez_i32:
525 ; RV64I-NEXT: and a0, a0, a1
526 ; RV64I-NEXT: xor a0, a0, a1
527 ; RV64I-NEXT: snez a0, a0
530 ; RV64ZBB-ZBKB-LABEL: andn_snez_i32:
531 ; RV64ZBB-ZBKB: # %bb.0:
532 ; RV64ZBB-ZBKB-NEXT: andn a0, a1, a0
533 ; RV64ZBB-ZBKB-NEXT: snez a0, a0
534 ; RV64ZBB-ZBKB-NEXT: ret
535 %and = and i32 %a, %b
536 %cmpeq = icmp ne i32 %and, %b
540 define i1 @andn_snez_i64(i64 %a, i64 %b) nounwind {
541 ; RV64I-LABEL: andn_snez_i64:
543 ; RV64I-NEXT: and a0, a0, a1
544 ; RV64I-NEXT: xor a0, a0, a1
545 ; RV64I-NEXT: snez a0, a0
548 ; RV64ZBB-ZBKB-LABEL: andn_snez_i64:
549 ; RV64ZBB-ZBKB: # %bb.0:
550 ; RV64ZBB-ZBKB-NEXT: andn a0, a1, a0
551 ; RV64ZBB-ZBKB-NEXT: snez a0, a0
552 ; RV64ZBB-ZBKB-NEXT: ret
553 %and = and i64 %a, %b
554 %cmpeq = icmp ne i64 %and, %b