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-prefix=RV32I
4 ; RUN: llc -mtriple=riscv64 -verify-machineinstrs < %s \
5 ; RUN: | FileCheck %s -check-prefix=RV64I
8 define i32 @from_cmpeq(i32 %xx, i32 %y) {
9 ; RV32I-LABEL: from_cmpeq:
11 ; RV32I-NEXT: addi a0, a0, -9
12 ; RV32I-NEXT: seqz a0, a0
13 ; RV32I-NEXT: and a0, a0, a1
16 ; RV64I-LABEL: from_cmpeq:
18 ; RV64I-NEXT: sext.w a0, a0
19 ; RV64I-NEXT: addi a0, a0, -9
20 ; RV64I-NEXT: seqz a0, a0
21 ; RV64I-NEXT: and a0, a0, a1
23 %x = icmp eq i32 %xx, 9
24 %masked = and i32 %y, 1
26 %r = select i1 %x, i32 %masked, i32 0
30 define i32 @from_cmpeq_fail_bad_andmask(i32 %xx, i32 %y) {
31 ; RV32I-LABEL: from_cmpeq_fail_bad_andmask:
33 ; RV32I-NEXT: addi a0, a0, -9
34 ; RV32I-NEXT: snez a0, a0
35 ; RV32I-NEXT: addi a0, a0, -1
36 ; RV32I-NEXT: and a0, a1, a0
37 ; RV32I-NEXT: andi a0, a0, 3
40 ; RV64I-LABEL: from_cmpeq_fail_bad_andmask:
42 ; RV64I-NEXT: sext.w a0, a0
43 ; RV64I-NEXT: addi a0, a0, -9
44 ; RV64I-NEXT: snez a0, a0
45 ; RV64I-NEXT: addi a0, a0, -1
46 ; RV64I-NEXT: and a0, a1, a0
47 ; RV64I-NEXT: andi a0, a0, 3
49 %x = icmp eq i32 %xx, 9
50 %masked = and i32 %y, 3
51 %r = select i1 %x, i32 %masked, i32 0
55 define i32 @from_i1(i1 %x, i32 %y) {
56 ; RV32I-LABEL: from_i1:
58 ; RV32I-NEXT: and a0, a0, a1
59 ; RV32I-NEXT: andi a0, a0, 1
62 ; RV64I-LABEL: from_i1:
64 ; RV64I-NEXT: and a0, a0, a1
65 ; RV64I-NEXT: andi a0, a0, 1
67 %masked = and i32 %y, 1
68 %r = select i1 %x, i32 %masked, i32 0
72 define i32 @from_trunc_i8(i8 %xx, i32 %y) {
73 ; RV32I-LABEL: from_trunc_i8:
75 ; RV32I-NEXT: and a0, a0, a1
76 ; RV32I-NEXT: andi a0, a0, 1
79 ; RV64I-LABEL: from_trunc_i8:
81 ; RV64I-NEXT: and a0, a0, a1
82 ; RV64I-NEXT: andi a0, a0, 1
84 %masked = and i32 %y, 1
85 %x = trunc i8 %xx to i1
86 %r = select i1 %x, i32 %masked, i32 0
90 define i32 @from_trunc_i64(i64 %xx, i32 %y) {
91 ; RV32I-LABEL: from_trunc_i64:
93 ; RV32I-NEXT: and a0, a0, a2
94 ; RV32I-NEXT: andi a0, a0, 1
97 ; RV64I-LABEL: from_trunc_i64:
99 ; RV64I-NEXT: and a0, a0, a1
100 ; RV64I-NEXT: andi a0, a0, 1
102 %masked = and i32 %y, 1
103 %x = trunc i64 %xx to i1
104 %r = select i1 %x, i32 %masked, i32 0
108 define i32 @from_i1_fail_bad_select0(i1 %x, i32 %y) {
109 ; RV32I-LABEL: from_i1_fail_bad_select0:
111 ; RV32I-NEXT: andi a0, a0, 1
112 ; RV32I-NEXT: bnez a0, .LBB5_2
113 ; RV32I-NEXT: # %bb.1:
114 ; RV32I-NEXT: li a0, 1
116 ; RV32I-NEXT: .LBB5_2:
117 ; RV32I-NEXT: andi a0, a1, 1
120 ; RV64I-LABEL: from_i1_fail_bad_select0:
122 ; RV64I-NEXT: andi a0, a0, 1
123 ; RV64I-NEXT: bnez a0, .LBB5_2
124 ; RV64I-NEXT: # %bb.1:
125 ; RV64I-NEXT: li a0, 1
127 ; RV64I-NEXT: .LBB5_2:
128 ; RV64I-NEXT: andi a0, a1, 1
130 %masked = and i32 %y, 1
131 %r = select i1 %x, i32 %masked, i32 1
135 define i32 @from_i1_fail_bad_select1(i1 %x, i32 %y) {
136 ; RV32I-LABEL: from_i1_fail_bad_select1:
138 ; RV32I-NEXT: addi a0, a0, -1
139 ; RV32I-NEXT: and a0, a1, a0
140 ; RV32I-NEXT: andi a0, a0, 1
143 ; RV64I-LABEL: from_i1_fail_bad_select1:
145 ; RV64I-NEXT: addi a0, a0, -1
146 ; RV64I-NEXT: and a0, a1, a0
147 ; RV64I-NEXT: andi a0, a0, 1
149 %masked = and i32 %y, 1
150 %r = select i1 %x, i32 0, i32 %masked