1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=riscv64 -global-isel -verify-machineinstrs < %s \
3 ; RUN: | FileCheck %s -check-prefixes=CHECK,RV64I
4 ; RUN: llc -mtriple=riscv64 -global-isel -mattr=+zbb -verify-machineinstrs < %s \
5 ; RUN: | FileCheck %s -check-prefixes=CHECK,RV64ZBB-ZBKB,RV64ZBB
6 ; RUN: llc -mtriple=riscv64 -global-isel -mattr=+zbkb -verify-machineinstrs < %s \
7 ; RUN: | 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 ; RV64I-LABEL: xnor_i32:
76 ; RV64I-NEXT: not a0, a0
77 ; RV64I-NEXT: xor a0, a0, a1
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: not a0, a0
93 ; RV64I-NEXT: xor a0, a0, a1
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: neg a2, a1
111 ; RV64I-NEXT: sllw a1, a0, a1
112 ; RV64I-NEXT: srlw a0, a0, a2
113 ; RV64I-NEXT: or a0, a1, 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: neg a3, a1
129 ; RV64I-NEXT: sllw a1, a0, a1
130 ; RV64I-NEXT: srlw a0, a0, a3
131 ; RV64I-NEXT: or a0, a1, 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: neg a2, a0
150 ; RV64I-NEXT: sllw a0, a1, a0
151 ; RV64I-NEXT: srlw a1, a1, a2
152 ; RV64I-NEXT: or a0, a0, a1
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: neg a2, a1
170 ; RV64I-NEXT: sll a1, a0, a1
171 ; RV64I-NEXT: srl a0, a0, a2
172 ; RV64I-NEXT: or a0, a1, 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: neg a2, a1
189 ; RV64I-NEXT: srlw a1, a0, a1
190 ; RV64I-NEXT: sllw a0, a0, a2
191 ; RV64I-NEXT: or a0, a1, 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: neg a3, a1
207 ; RV64I-NEXT: srlw a1, a0, a1
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: li a1, -2
227 ; RV64I-NEXT: neg a2, a0
228 ; RV64I-NEXT: srlw a0, a1, a0
229 ; RV64I-NEXT: sllw a1, a1, a2
230 ; RV64I-NEXT: or a0, a0, a1
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: neg a2, a1
248 ; RV64I-NEXT: srl a1, a0, a1
249 ; RV64I-NEXT: sll a0, a0, a2
250 ; RV64I-NEXT: or a0, a1, 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: slliw a1, a0, 31
265 ; RV64I-NEXT: srliw a0, a0, 1
266 ; RV64I-NEXT: or a0, a1, a0
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: slli a2, a0, 31
282 ; RV64I-NEXT: srliw a0, a0, 1
283 ; RV64I-NEXT: or a0, a2, a0
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: srliw a1, a0, 31
301 ; RV64I-NEXT: slliw a0, a0, 1
302 ; RV64I-NEXT: or a0, a1, a0
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: srliw a2, a0, 31
318 ; RV64I-NEXT: slli a0, a0, 1
319 ; RV64I-NEXT: or a0, a2, a0
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: andi a1, a0, -2
356 ; CHECK-NEXT: srli a2, a1, 1
357 ; CHECK-NEXT: slli a0, a0, 63
358 ; CHECK-NEXT: slli a2, a2, 32
359 ; CHECK-NEXT: or a0, a0, a2
360 ; CHECK-NEXT: srai a0, a0, 32
361 ; CHECK-NEXT: xor a0, a1, 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: slli a1, a0, 63
377 ; RV64I-NEXT: srli a0, a0, 1
378 ; RV64I-NEXT: or a0, a1, a0
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: srli a1, a0, 63
393 ; RV64I-NEXT: slli a0, a0, 1
394 ; RV64I-NEXT: or a0, a1, a0
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 i8 @srli_i8(i8 %a) nounwind {
406 ; CHECK-LABEL: srli_i8:
408 ; CHECK-NEXT: andi a0, a0, 255
409 ; CHECK-NEXT: srli a0, a0, 6
415 ; FIXME: We should use slli+srai with Zbb for better compression.
416 define i8 @srai_i8(i8 %a) nounwind {
417 ; RV64I-LABEL: srai_i8:
419 ; RV64I-NEXT: slli a0, a0, 56
420 ; RV64I-NEXT: srai a0, a0, 61
423 ; RV64ZBB-LABEL: srai_i8:
425 ; RV64ZBB-NEXT: sext.b a0, a0
426 ; RV64ZBB-NEXT: srai a0, a0, 5
429 ; RV64ZBKB-LABEL: srai_i8:
431 ; RV64ZBKB-NEXT: slli a0, a0, 56
432 ; RV64ZBKB-NEXT: srai a0, a0, 61
438 ; FIXME: We should use slli+srli.
439 define i16 @srli_i16(i16 %a) nounwind {
440 ; RV64I-LABEL: srli_i16:
442 ; RV64I-NEXT: slli a0, a0, 48
443 ; RV64I-NEXT: srli a0, a0, 48
444 ; RV64I-NEXT: srli a0, a0, 6
447 ; RV64ZBB-ZBKB-LABEL: srli_i16:
448 ; RV64ZBB-ZBKB: # %bb.0:
449 ; RV64ZBB-ZBKB-NEXT: zext.h a0, a0
450 ; RV64ZBB-ZBKB-NEXT: srli a0, a0, 6
451 ; RV64ZBB-ZBKB-NEXT: ret
456 ; FIXME: We should use slli+srai with Zbb for better compression.
457 define i16 @srai_i16(i16 %a) nounwind {
458 ; RV64I-LABEL: srai_i16:
460 ; RV64I-NEXT: slli a0, a0, 48
461 ; RV64I-NEXT: srai a0, a0, 57
464 ; RV64ZBB-LABEL: srai_i16:
466 ; RV64ZBB-NEXT: sext.h a0, a0
467 ; RV64ZBB-NEXT: srai a0, a0, 9
470 ; RV64ZBKB-LABEL: srai_i16:
472 ; RV64ZBKB-NEXT: slli a0, a0, 48
473 ; RV64ZBKB-NEXT: srai a0, a0, 57