Skip to content

Commit 2b8753b

Browse files
committed
[RISCV][test] Add tests for most significant bit extraction
1 parent 13cd725 commit 2b8753b

File tree

1 file changed

+116
-0
lines changed

1 file changed

+116
-0
lines changed

llvm/test/CodeGen/RISCV/bittest.ll

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3507,3 +3507,119 @@ define void @bit_64_1_nz_branch_i64(i64 %0) {
35073507
5:
35083508
ret void
35093509
}
3510+
3511+
define i32 @bittest_31_andeq0_i64(i64 %x) {
3512+
; RV32I-LABEL: bittest_31_andeq0_i64:
3513+
; RV32I: # %bb.0:
3514+
; RV32I-NEXT: lui a1, 524288
3515+
; RV32I-NEXT: and a0, a0, a1
3516+
; RV32I-NEXT: seqz a0, a0
3517+
; RV32I-NEXT: ret
3518+
;
3519+
; RV64I-LABEL: bittest_31_andeq0_i64:
3520+
; RV64I: # %bb.0:
3521+
; RV64I-NEXT: srliw a0, a0, 31
3522+
; RV64I-NEXT: slli a0, a0, 31
3523+
; RV64I-NEXT: seqz a0, a0
3524+
; RV64I-NEXT: ret
3525+
;
3526+
; ZBS-LABEL: bittest_31_andeq0_i64:
3527+
; ZBS: # %bb.0:
3528+
; ZBS-NEXT: not a0, a0
3529+
; ZBS-NEXT: bexti a0, a0, 31
3530+
; ZBS-NEXT: ret
3531+
;
3532+
; XTHEADBS-LABEL: bittest_31_andeq0_i64:
3533+
; XTHEADBS: # %bb.0:
3534+
; XTHEADBS-NEXT: not a0, a0
3535+
; XTHEADBS-NEXT: th.tst a0, a0, 31
3536+
; XTHEADBS-NEXT: ret
3537+
%and = and i64 %x, 2147483648
3538+
%cmp = icmp eq i64 %and, 0
3539+
%conv = zext i1 %cmp to i32
3540+
ret i32 %conv
3541+
}
3542+
3543+
define i32 @bittest_63_andeq0_i64(i64 %x) {
3544+
; RV32I-LABEL: bittest_63_andeq0_i64:
3545+
; RV32I: # %bb.0:
3546+
; RV32I-NEXT: lui a0, 524288
3547+
; RV32I-NEXT: and a0, a1, a0
3548+
; RV32I-NEXT: seqz a0, a0
3549+
; RV32I-NEXT: ret
3550+
;
3551+
; RV64I-LABEL: bittest_63_andeq0_i64:
3552+
; RV64I: # %bb.0:
3553+
; RV64I-NEXT: srli a0, a0, 63
3554+
; RV64I-NEXT: slli a0, a0, 63
3555+
; RV64I-NEXT: seqz a0, a0
3556+
; RV64I-NEXT: ret
3557+
;
3558+
; RV32ZBS-LABEL: bittest_63_andeq0_i64:
3559+
; RV32ZBS: # %bb.0:
3560+
; RV32ZBS-NEXT: not a0, a1
3561+
; RV32ZBS-NEXT: bexti a0, a0, 31
3562+
; RV32ZBS-NEXT: ret
3563+
;
3564+
; RV64ZBS-LABEL: bittest_63_andeq0_i64:
3565+
; RV64ZBS: # %bb.0:
3566+
; RV64ZBS-NEXT: not a0, a0
3567+
; RV64ZBS-NEXT: bexti a0, a0, 63
3568+
; RV64ZBS-NEXT: ret
3569+
;
3570+
; RV32XTHEADBS-LABEL: bittest_63_andeq0_i64:
3571+
; RV32XTHEADBS: # %bb.0:
3572+
; RV32XTHEADBS-NEXT: not a0, a1
3573+
; RV32XTHEADBS-NEXT: th.tst a0, a0, 31
3574+
; RV32XTHEADBS-NEXT: ret
3575+
;
3576+
; RV64XTHEADBS-LABEL: bittest_63_andeq0_i64:
3577+
; RV64XTHEADBS: # %bb.0:
3578+
; RV64XTHEADBS-NEXT: not a0, a0
3579+
; RV64XTHEADBS-NEXT: th.tst a0, a0, 63
3580+
; RV64XTHEADBS-NEXT: ret
3581+
%and = and i64 %x, 9223372036854775808
3582+
%cmp = icmp eq i64 %and, 0
3583+
%conv = zext i1 %cmp to i32
3584+
ret i32 %conv
3585+
}
3586+
3587+
define i32 @bittest_31_slt0_i32(i32 %x, i1 %y) {
3588+
; RV32-LABEL: bittest_31_slt0_i32:
3589+
; RV32: # %bb.0:
3590+
; RV32-NEXT: slti a0, a0, 0
3591+
; RV32-NEXT: and a0, a0, a1
3592+
; RV32-NEXT: ret
3593+
;
3594+
; RV64-LABEL: bittest_31_slt0_i32:
3595+
; RV64: # %bb.0:
3596+
; RV64-NEXT: sext.w a0, a0
3597+
; RV64-NEXT: slti a0, a0, 0
3598+
; RV64-NEXT: and a0, a0, a1
3599+
; RV64-NEXT: ret
3600+
%cmp = icmp slt i32 %x, 0
3601+
%and = and i1 %cmp, %y
3602+
%ext = zext i1 %and to i32
3603+
ret i32 %ext
3604+
}
3605+
3606+
define i32 @bittest_63_slt0_i64(i32 %x, i1 %y) {
3607+
; RV32-LABEL: bittest_63_slt0_i64:
3608+
; RV32: # %bb.0:
3609+
; RV32-NEXT: srai a0, a0, 31
3610+
; RV32-NEXT: slti a0, a0, 0
3611+
; RV32-NEXT: and a0, a0, a1
3612+
; RV32-NEXT: ret
3613+
;
3614+
; RV64-LABEL: bittest_63_slt0_i64:
3615+
; RV64: # %bb.0:
3616+
; RV64-NEXT: sext.w a0, a0
3617+
; RV64-NEXT: slti a0, a0, 0
3618+
; RV64-NEXT: and a0, a0, a1
3619+
; RV64-NEXT: ret
3620+
%ext = sext i32 %x to i64
3621+
%cmp = icmp slt i64 %ext, 0
3622+
%and = and i1 %cmp, %y
3623+
%cond = zext i1 %and to i32
3624+
ret i32 %cond
3625+
}

0 commit comments

Comments
 (0)