1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=riscv32 -verify-machineinstrs < %s \
3 ; RUN: | FileCheck -check-prefix=RV32I %s
4 ; RUN: llc -mtriple=riscv64 -verify-machineinstrs < %s \
5 ; RUN: | FileCheck -check-prefix=RV64I %s
7 ; InstCombine canonicalizes (c ? x | y : x) to (x | (c ? y : 0)) similar for
8 ; other binary operations using their identity value as the constant.
10 ; We can reverse this for and/or/xor. Allowing us to pull the binop into
11 ; the basic block we create when we expand select.
13 define signext i32 @and_select_all_ones_i32(i1 zeroext %c, i32 signext %x, i32 %y) {
14 ; RV32I-LABEL: and_select_all_ones_i32:
16 ; RV32I-NEXT: beqz a0, .LBB0_2
17 ; RV32I-NEXT: # %bb.1:
18 ; RV32I-NEXT: and a2, a2, a1
19 ; RV32I-NEXT: .LBB0_2:
20 ; RV32I-NEXT: mv a0, a2
23 ; RV64I-LABEL: and_select_all_ones_i32:
25 ; RV64I-NEXT: beqz a0, .LBB0_2
26 ; RV64I-NEXT: # %bb.1:
27 ; RV64I-NEXT: and a2, a2, a1
28 ; RV64I-NEXT: .LBB0_2:
29 ; RV64I-NEXT: sext.w a0, a2
31 %a = select i1 %c, i32 %x, i32 -1
36 define i64 @and_select_all_ones_i64(i1 zeroext %c, i64 %x, i64 %y) {
37 ; RV32I-LABEL: and_select_all_ones_i64:
39 ; RV32I-NEXT: bnez a0, .LBB1_2
40 ; RV32I-NEXT: # %bb.1:
41 ; RV32I-NEXT: and a3, a3, a1
42 ; RV32I-NEXT: and a4, a4, a2
43 ; RV32I-NEXT: .LBB1_2:
44 ; RV32I-NEXT: mv a0, a3
45 ; RV32I-NEXT: mv a1, a4
48 ; RV64I-LABEL: and_select_all_ones_i64:
50 ; RV64I-NEXT: bnez a0, .LBB1_2
51 ; RV64I-NEXT: # %bb.1:
52 ; RV64I-NEXT: and a2, a2, a1
53 ; RV64I-NEXT: .LBB1_2:
54 ; RV64I-NEXT: mv a0, a2
56 %a = select i1 %c, i64 -1, i64 %x
61 define signext i32 @or_select_all_zeros_i32(i1 zeroext %c, i32 signext %x, i32 signext %y) {
62 ; RV32I-LABEL: or_select_all_zeros_i32:
64 ; RV32I-NEXT: beqz a0, .LBB2_2
65 ; RV32I-NEXT: # %bb.1:
66 ; RV32I-NEXT: or a2, a2, a1
67 ; RV32I-NEXT: .LBB2_2:
68 ; RV32I-NEXT: mv a0, a2
71 ; RV64I-LABEL: or_select_all_zeros_i32:
73 ; RV64I-NEXT: beqz a0, .LBB2_2
74 ; RV64I-NEXT: # %bb.1:
75 ; RV64I-NEXT: or a2, a2, a1
76 ; RV64I-NEXT: .LBB2_2:
77 ; RV64I-NEXT: mv a0, a2
79 %a = select i1 %c, i32 %x, i32 0
84 define i64 @or_select_all_zeros_i64(i1 zeroext %c, i64 %x, i64 %y) {
85 ; RV32I-LABEL: or_select_all_zeros_i64:
87 ; RV32I-NEXT: bnez a0, .LBB3_2
88 ; RV32I-NEXT: # %bb.1:
89 ; RV32I-NEXT: or a3, a3, a1
90 ; RV32I-NEXT: or a4, a4, a2
91 ; RV32I-NEXT: .LBB3_2:
92 ; RV32I-NEXT: mv a0, a3
93 ; RV32I-NEXT: mv a1, a4
96 ; RV64I-LABEL: or_select_all_zeros_i64:
98 ; RV64I-NEXT: bnez a0, .LBB3_2
99 ; RV64I-NEXT: # %bb.1:
100 ; RV64I-NEXT: or a2, a2, a1
101 ; RV64I-NEXT: .LBB3_2:
102 ; RV64I-NEXT: mv a0, a2
104 %a = select i1 %c, i64 0, i64 %x
109 define signext i32 @xor_select_all_zeros_i32(i1 zeroext %c, i32 signext %x, i32 signext %y) {
110 ; RV32I-LABEL: xor_select_all_zeros_i32:
112 ; RV32I-NEXT: bnez a0, .LBB4_2
113 ; RV32I-NEXT: # %bb.1:
114 ; RV32I-NEXT: xor a2, a2, a1
115 ; RV32I-NEXT: .LBB4_2:
116 ; RV32I-NEXT: mv a0, a2
119 ; RV64I-LABEL: xor_select_all_zeros_i32:
121 ; RV64I-NEXT: bnez a0, .LBB4_2
122 ; RV64I-NEXT: # %bb.1:
123 ; RV64I-NEXT: xor a2, a2, a1
124 ; RV64I-NEXT: .LBB4_2:
125 ; RV64I-NEXT: mv a0, a2
127 %a = select i1 %c, i32 0, i32 %x
132 define i64 @xor_select_all_zeros_i64(i1 zeroext %c, i64 %x, i64 %y) {
133 ; RV32I-LABEL: xor_select_all_zeros_i64:
135 ; RV32I-NEXT: beqz a0, .LBB5_2
136 ; RV32I-NEXT: # %bb.1:
137 ; RV32I-NEXT: xor a3, a3, a1
138 ; RV32I-NEXT: xor a4, a4, a2
139 ; RV32I-NEXT: .LBB5_2:
140 ; RV32I-NEXT: mv a0, a3
141 ; RV32I-NEXT: mv a1, a4
144 ; RV64I-LABEL: xor_select_all_zeros_i64:
146 ; RV64I-NEXT: beqz a0, .LBB5_2
147 ; RV64I-NEXT: # %bb.1:
148 ; RV64I-NEXT: xor a2, a2, a1
149 ; RV64I-NEXT: .LBB5_2:
150 ; RV64I-NEXT: mv a0, a2
152 %a = select i1 %c, i64 %x, i64 0
157 define signext i32 @add_select_all_zeros_i32(i1 zeroext %c, i32 signext %x, i32 signext %y) {
158 ; RV32I-LABEL: add_select_all_zeros_i32:
160 ; RV32I-NEXT: bnez a0, .LBB6_2
161 ; RV32I-NEXT: # %bb.1:
162 ; RV32I-NEXT: add a2, a2, a1
163 ; RV32I-NEXT: .LBB6_2:
164 ; RV32I-NEXT: mv a0, a2
167 ; RV64I-LABEL: add_select_all_zeros_i32:
169 ; RV64I-NEXT: bnez a0, .LBB6_2
170 ; RV64I-NEXT: # %bb.1:
171 ; RV64I-NEXT: addw a2, a2, a1
172 ; RV64I-NEXT: .LBB6_2:
173 ; RV64I-NEXT: mv a0, a2
175 %a = select i1 %c, i32 0, i32 %x
180 define i64 @add_select_all_zeros_i64(i1 zeroext %c, i64 %x, i64 %y) {
181 ; RV32I-LABEL: add_select_all_zeros_i64:
183 ; RV32I-NEXT: beqz a0, .LBB7_2
184 ; RV32I-NEXT: # %bb.1:
185 ; RV32I-NEXT: add a0, a4, a2
186 ; RV32I-NEXT: add a1, a3, a1
187 ; RV32I-NEXT: sltu a2, a1, a3
188 ; RV32I-NEXT: add a4, a0, a2
189 ; RV32I-NEXT: mv a3, a1
190 ; RV32I-NEXT: .LBB7_2:
191 ; RV32I-NEXT: mv a0, a3
192 ; RV32I-NEXT: mv a1, a4
195 ; RV64I-LABEL: add_select_all_zeros_i64:
197 ; RV64I-NEXT: beqz a0, .LBB7_2
198 ; RV64I-NEXT: # %bb.1:
199 ; RV64I-NEXT: add a2, a2, a1
200 ; RV64I-NEXT: .LBB7_2:
201 ; RV64I-NEXT: mv a0, a2
203 %a = select i1 %c, i64 %x, i64 0
208 define signext i32 @sub_select_all_zeros_i32(i1 zeroext %c, i32 signext %x, i32 signext %y) {
209 ; RV32I-LABEL: sub_select_all_zeros_i32:
211 ; RV32I-NEXT: bnez a0, .LBB8_2
212 ; RV32I-NEXT: # %bb.1:
213 ; RV32I-NEXT: sub a2, a2, a1
214 ; RV32I-NEXT: .LBB8_2:
215 ; RV32I-NEXT: mv a0, a2
218 ; RV64I-LABEL: sub_select_all_zeros_i32:
220 ; RV64I-NEXT: bnez a0, .LBB8_2
221 ; RV64I-NEXT: # %bb.1:
222 ; RV64I-NEXT: subw a2, a2, a1
223 ; RV64I-NEXT: .LBB8_2:
224 ; RV64I-NEXT: mv a0, a2
226 %a = select i1 %c, i32 0, i32 %x
231 define i64 @sub_select_all_zeros_i64(i1 zeroext %c, i64 %x, i64 %y) {
232 ; RV32I-LABEL: sub_select_all_zeros_i64:
234 ; RV32I-NEXT: beqz a0, .LBB9_2
235 ; RV32I-NEXT: # %bb.1:
236 ; RV32I-NEXT: sltu a0, a3, a1
237 ; RV32I-NEXT: sub a2, a4, a2
238 ; RV32I-NEXT: sub a4, a2, a0
239 ; RV32I-NEXT: sub a3, a3, a1
240 ; RV32I-NEXT: .LBB9_2:
241 ; RV32I-NEXT: mv a0, a3
242 ; RV32I-NEXT: mv a1, a4
245 ; RV64I-LABEL: sub_select_all_zeros_i64:
247 ; RV64I-NEXT: beqz a0, .LBB9_2
248 ; RV64I-NEXT: # %bb.1:
249 ; RV64I-NEXT: sub a2, a2, a1
250 ; RV64I-NEXT: .LBB9_2:
251 ; RV64I-NEXT: mv a0, a2
253 %a = select i1 %c, i64 %x, i64 0