1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=riscv32 -verify-machineinstrs < %s \
3 ; RUN: | FileCheck %s -check-prefixes=CHECK,NOZBS,RV32,RV32I
4 ; RUN: llc -mtriple=riscv64 -verify-machineinstrs < %s \
5 ; RUN: | FileCheck %s -check-prefixes=CHECK,NOZBS,RV64,RV64I
6 ; RUN: llc -mtriple=riscv32 -mattr=+zbs -verify-machineinstrs < %s \
7 ; RUN: | FileCheck %s -check-prefixes=CHECK,ZBS,RV32,RV32ZBS
8 ; RUN: llc -mtriple=riscv64 -mattr=+zbs -verify-machineinstrs < %s \
9 ; RUN: | FileCheck %s -check-prefixes=CHECK,ZBS,RV64,RV64ZBS
11 define signext i32 @bittest_7_i32(i32 signext %a) nounwind {
12 ; CHECK-LABEL: bittest_7_i32:
14 ; CHECK-NEXT: andi a0, a0, 128
15 ; CHECK-NEXT: seqz a0, a0
18 %not = xor i32 %shr, -1
19 %and = and i32 %not, 1
23 define signext i32 @bittest_10_i32(i32 signext %a) nounwind {
24 ; CHECK-LABEL: bittest_10_i32:
26 ; CHECK-NEXT: andi a0, a0, 1024
27 ; CHECK-NEXT: seqz a0, a0
29 %shr = lshr i32 %a, 10
30 %not = xor i32 %shr, -1
31 %and = and i32 %not, 1
35 define signext i32 @bittest_11_i32(i32 signext %a) nounwind {
36 ; NOZBS-LABEL: bittest_11_i32:
38 ; NOZBS-NEXT: srli a0, a0, 11
39 ; NOZBS-NEXT: not a0, a0
40 ; NOZBS-NEXT: andi a0, a0, 1
43 ; ZBS-LABEL: bittest_11_i32:
45 ; ZBS-NEXT: bexti a0, a0, 11
46 ; ZBS-NEXT: xori a0, a0, 1
48 %shr = lshr i32 %a, 11
49 %not = xor i32 %shr, -1
50 %and = and i32 %not, 1
54 define signext i32 @bittest_31_i32(i32 signext %a) nounwind {
55 ; RV32-LABEL: bittest_31_i32:
57 ; RV32-NEXT: not a0, a0
58 ; RV32-NEXT: srli a0, a0, 31
61 ; RV64-LABEL: bittest_31_i32:
63 ; RV64-NEXT: not a0, a0
64 ; RV64-NEXT: srliw a0, a0, 31
66 %shr = lshr i32 %a, 31
67 %not = xor i32 %shr, -1
68 %and = and i32 %not, 1
72 define i64 @bittest_7_i64(i64 %a) nounwind {
73 ; RV32-LABEL: bittest_7_i64:
75 ; RV32-NEXT: andi a0, a0, 128
76 ; RV32-NEXT: seqz a0, a0
80 ; RV64-LABEL: bittest_7_i64:
82 ; RV64-NEXT: andi a0, a0, 128
83 ; RV64-NEXT: seqz a0, a0
86 %not = xor i64 %shr, -1
87 %and = and i64 %not, 1
91 define i64 @bittest_10_i64(i64 %a) nounwind {
92 ; RV32-LABEL: bittest_10_i64:
94 ; RV32-NEXT: andi a0, a0, 1024
95 ; RV32-NEXT: seqz a0, a0
99 ; RV64-LABEL: bittest_10_i64:
101 ; RV64-NEXT: andi a0, a0, 1024
102 ; RV64-NEXT: seqz a0, a0
104 %shr = lshr i64 %a, 10
105 %not = xor i64 %shr, -1
106 %and = and i64 %not, 1
110 define i64 @bittest_11_i64(i64 %a) nounwind {
111 ; RV32I-LABEL: bittest_11_i64:
113 ; RV32I-NEXT: srli a0, a0, 11
114 ; RV32I-NEXT: not a0, a0
115 ; RV32I-NEXT: andi a0, a0, 1
116 ; RV32I-NEXT: li a1, 0
119 ; RV64I-LABEL: bittest_11_i64:
121 ; RV64I-NEXT: srli a0, a0, 11
122 ; RV64I-NEXT: not a0, a0
123 ; RV64I-NEXT: andi a0, a0, 1
126 ; RV32ZBS-LABEL: bittest_11_i64:
128 ; RV32ZBS-NEXT: bexti a0, a0, 11
129 ; RV32ZBS-NEXT: xori a0, a0, 1
130 ; RV32ZBS-NEXT: li a1, 0
133 ; RV64ZBS-LABEL: bittest_11_i64:
135 ; RV64ZBS-NEXT: bexti a0, a0, 11
136 ; RV64ZBS-NEXT: xori a0, a0, 1
138 %shr = lshr i64 %a, 11
139 %not = xor i64 %shr, -1
140 %and = and i64 %not, 1
144 define i64 @bittest_31_i64(i64 %a) nounwind {
145 ; RV32-LABEL: bittest_31_i64:
147 ; RV32-NEXT: not a0, a0
148 ; RV32-NEXT: srli a0, a0, 31
149 ; RV32-NEXT: li a1, 0
152 ; RV64I-LABEL: bittest_31_i64:
154 ; RV64I-NEXT: srli a0, a0, 31
155 ; RV64I-NEXT: not a0, a0
156 ; RV64I-NEXT: andi a0, a0, 1
159 ; RV64ZBS-LABEL: bittest_31_i64:
161 ; RV64ZBS-NEXT: bexti a0, a0, 31
162 ; RV64ZBS-NEXT: xori a0, a0, 1
164 %shr = lshr i64 %a, 31
165 %not = xor i64 %shr, -1
166 %and = and i64 %not, 1
170 define i64 @bittest_32_i64(i64 %a) nounwind {
171 ; RV32-LABEL: bittest_32_i64:
173 ; RV32-NEXT: not a0, a1
174 ; RV32-NEXT: andi a0, a0, 1
175 ; RV32-NEXT: li a1, 0
178 ; RV64I-LABEL: bittest_32_i64:
180 ; RV64I-NEXT: srli a0, a0, 32
181 ; RV64I-NEXT: not a0, a0
182 ; RV64I-NEXT: andi a0, a0, 1
185 ; RV64ZBS-LABEL: bittest_32_i64:
187 ; RV64ZBS-NEXT: bexti a0, a0, 32
188 ; RV64ZBS-NEXT: xori a0, a0, 1
190 %shr = lshr i64 %a, 32
191 %not = xor i64 %shr, -1
192 %and = and i64 %not, 1
196 define i64 @bittest_63_i64(i64 %a) nounwind {
197 ; RV32-LABEL: bittest_63_i64:
199 ; RV32-NEXT: not a0, a1
200 ; RV32-NEXT: srli a0, a0, 31
201 ; RV32-NEXT: li a1, 0
204 ; RV64-LABEL: bittest_63_i64:
206 ; RV64-NEXT: not a0, a0
207 ; RV64-NEXT: srli a0, a0, 63
209 %shr = lshr i64 %a, 63
210 %not = xor i64 %shr, -1
211 %and = and i64 %not, 1
215 ; Make sure we use (andi (srl X, Y), 1) or bext.
216 define i1 @bittest_constant_by_var_shr_i32(i32 signext %b) nounwind {
217 ; RV32I-LABEL: bittest_constant_by_var_shr_i32:
219 ; RV32I-NEXT: lui a1, 301408
220 ; RV32I-NEXT: addi a1, a1, 722
221 ; RV32I-NEXT: srl a0, a1, a0
222 ; RV32I-NEXT: andi a0, a0, 1
225 ; RV64I-LABEL: bittest_constant_by_var_shr_i32:
227 ; RV64I-NEXT: lui a1, 301408
228 ; RV64I-NEXT: addiw a1, a1, 722
229 ; RV64I-NEXT: srlw a0, a1, a0
230 ; RV64I-NEXT: andi a0, a0, 1
233 ; RV32ZBS-LABEL: bittest_constant_by_var_shr_i32:
235 ; RV32ZBS-NEXT: lui a1, 301408
236 ; RV32ZBS-NEXT: addi a1, a1, 722
237 ; RV32ZBS-NEXT: bext a0, a1, a0
240 ; RV64ZBS-LABEL: bittest_constant_by_var_shr_i32:
242 ; RV64ZBS-NEXT: lui a1, 301408
243 ; RV64ZBS-NEXT: addiw a1, a1, 722
244 ; RV64ZBS-NEXT: bext a0, a1, a0
246 %shl = lshr i32 1234567890, %b
247 %and = and i32 %shl, 1
248 %cmp = icmp ne i32 %and, 0
252 ; Make sure we use (andi (srl X, Y), 1) or bext.
253 define i1 @bittest_constant_by_var_shl_i32(i32 signext %b) nounwind {
254 ; RV32I-LABEL: bittest_constant_by_var_shl_i32:
256 ; RV32I-NEXT: lui a1, 301408
257 ; RV32I-NEXT: addi a1, a1, 722
258 ; RV32I-NEXT: srl a0, a1, a0
259 ; RV32I-NEXT: andi a0, a0, 1
262 ; RV64I-LABEL: bittest_constant_by_var_shl_i32:
264 ; RV64I-NEXT: lui a1, 301408
265 ; RV64I-NEXT: addiw a1, a1, 722
266 ; RV64I-NEXT: srlw a0, a1, a0
267 ; RV64I-NEXT: andi a0, a0, 1
270 ; RV32ZBS-LABEL: bittest_constant_by_var_shl_i32:
272 ; RV32ZBS-NEXT: lui a1, 301408
273 ; RV32ZBS-NEXT: addi a1, a1, 722
274 ; RV32ZBS-NEXT: bext a0, a1, a0
277 ; RV64ZBS-LABEL: bittest_constant_by_var_shl_i32:
279 ; RV64ZBS-NEXT: lui a1, 301408
280 ; RV64ZBS-NEXT: addiw a1, a1, 722
281 ; RV64ZBS-NEXT: bext a0, a1, a0
284 %and = and i32 %shl, 1234567890
285 %cmp = icmp ne i32 %and, 0
289 ; Make sure we use (andi (srl X, Y), 1) or bext.
290 define i1 @bittest_constant_by_var_shr_i64(i64 %b) nounwind {
291 ; RV32-LABEL: bittest_constant_by_var_shr_i64:
293 ; RV32-NEXT: addi a1, a0, -32
294 ; RV32-NEXT: bltz a1, .LBB12_2
295 ; RV32-NEXT: # %bb.1:
296 ; RV32-NEXT: andi a0, zero, 1
298 ; RV32-NEXT: .LBB12_2:
299 ; RV32-NEXT: lui a1, 301408
300 ; RV32-NEXT: addi a1, a1, 722
301 ; RV32-NEXT: srl a0, a1, a0
302 ; RV32-NEXT: andi a0, a0, 1
305 ; RV64I-LABEL: bittest_constant_by_var_shr_i64:
307 ; RV64I-NEXT: lui a1, 301408
308 ; RV64I-NEXT: addiw a1, a1, 722
309 ; RV64I-NEXT: srl a0, a1, a0
310 ; RV64I-NEXT: andi a0, a0, 1
313 ; RV64ZBS-LABEL: bittest_constant_by_var_shr_i64:
315 ; RV64ZBS-NEXT: lui a1, 301408
316 ; RV64ZBS-NEXT: addiw a1, a1, 722
317 ; RV64ZBS-NEXT: bext a0, a1, a0
319 %shl = lshr i64 1234567890, %b
320 %and = and i64 %shl, 1
321 %cmp = icmp ne i64 %and, 0
325 ; Make sure we use (andi (srl X, Y), 1) or bext.
326 define i1 @bittest_constant_by_var_shl_i64(i64 %b) nounwind {
327 ; RV32-LABEL: bittest_constant_by_var_shl_i64:
329 ; RV32-NEXT: addi a1, a0, -32
330 ; RV32-NEXT: bltz a1, .LBB13_2
331 ; RV32-NEXT: # %bb.1:
332 ; RV32-NEXT: andi a0, zero, 1
334 ; RV32-NEXT: .LBB13_2:
335 ; RV32-NEXT: lui a1, 301408
336 ; RV32-NEXT: addi a1, a1, 722
337 ; RV32-NEXT: srl a0, a1, a0
338 ; RV32-NEXT: andi a0, a0, 1
341 ; RV64I-LABEL: bittest_constant_by_var_shl_i64:
343 ; RV64I-NEXT: lui a1, 301408
344 ; RV64I-NEXT: addiw a1, a1, 722
345 ; RV64I-NEXT: srl a0, a1, a0
346 ; RV64I-NEXT: andi a0, a0, 1
349 ; RV64ZBS-LABEL: bittest_constant_by_var_shl_i64:
351 ; RV64ZBS-NEXT: lui a1, 301408
352 ; RV64ZBS-NEXT: addiw a1, a1, 722
353 ; RV64ZBS-NEXT: bext a0, a1, a0
356 %and = and i64 %shl, 1234567890
357 %cmp = icmp ne i64 %and, 0
361 ; We want to use (andi (srl X, Y), 1) or bext before the beqz.
362 define void @bittest_switch(i32 signext %0) {
363 ; RV32I-LABEL: bittest_switch:
365 ; RV32I-NEXT: li a1, 31
366 ; RV32I-NEXT: bltu a1, a0, .LBB14_3
367 ; RV32I-NEXT: # %bb.1:
368 ; RV32I-NEXT: lui a1, 524291
369 ; RV32I-NEXT: addi a1, a1, 768
370 ; RV32I-NEXT: srl a0, a1, a0
371 ; RV32I-NEXT: andi a0, a0, 1
372 ; RV32I-NEXT: beqz a0, .LBB14_3
373 ; RV32I-NEXT: # %bb.2:
374 ; RV32I-NEXT: tail bar@plt
375 ; RV32I-NEXT: .LBB14_3:
378 ; RV64I-LABEL: bittest_switch:
380 ; RV64I-NEXT: li a1, 31
381 ; RV64I-NEXT: bltu a1, a0, .LBB14_3
382 ; RV64I-NEXT: # %bb.1:
383 ; RV64I-NEXT: lui a1, 2048
384 ; RV64I-NEXT: addiw a1, a1, 51
385 ; RV64I-NEXT: slli a1, a1, 8
386 ; RV64I-NEXT: srl a0, a1, a0
387 ; RV64I-NEXT: andi a0, a0, 1
388 ; RV64I-NEXT: beqz a0, .LBB14_3
389 ; RV64I-NEXT: # %bb.2:
390 ; RV64I-NEXT: tail bar@plt
391 ; RV64I-NEXT: .LBB14_3:
394 ; RV32ZBS-LABEL: bittest_switch:
396 ; RV32ZBS-NEXT: li a1, 31
397 ; RV32ZBS-NEXT: bltu a1, a0, .LBB14_3
398 ; RV32ZBS-NEXT: # %bb.1:
399 ; RV32ZBS-NEXT: lui a1, 524291
400 ; RV32ZBS-NEXT: addi a1, a1, 768
401 ; RV32ZBS-NEXT: bext a0, a1, a0
402 ; RV32ZBS-NEXT: beqz a0, .LBB14_3
403 ; RV32ZBS-NEXT: # %bb.2:
404 ; RV32ZBS-NEXT: tail bar@plt
405 ; RV32ZBS-NEXT: .LBB14_3:
408 ; RV64ZBS-LABEL: bittest_switch:
410 ; RV64ZBS-NEXT: li a1, 31
411 ; RV64ZBS-NEXT: bltu a1, a0, .LBB14_3
412 ; RV64ZBS-NEXT: # %bb.1:
413 ; RV64ZBS-NEXT: lui a1, 2048
414 ; RV64ZBS-NEXT: addiw a1, a1, 51
415 ; RV64ZBS-NEXT: slli a1, a1, 8
416 ; RV64ZBS-NEXT: bext a0, a1, a0
417 ; RV64ZBS-NEXT: beqz a0, .LBB14_3
418 ; RV64ZBS-NEXT: # %bb.2:
419 ; RV64ZBS-NEXT: tail bar@plt
420 ; RV64ZBS-NEXT: .LBB14_3:
422 switch i32 %0, label %3 [
431 tail call void @bar()