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
7 ; This test checks that unnecessary masking of shift amount operands is
8 ; eliminated during instruction selection. The test needs to ensure that the
9 ; masking is not removed if it may affect the shift amount.
11 define i32 @sll_redundant_mask(i32 %a, i32 %b) nounwind {
12 ; RV32I-LABEL: sll_redundant_mask:
14 ; RV32I-NEXT: sll a0, a0, a1
17 ; RV64I-LABEL: sll_redundant_mask:
19 ; RV64I-NEXT: sllw a0, a0, a1
26 define i32 @sll_non_redundant_mask(i32 %a, i32 %b) nounwind {
27 ; RV32I-LABEL: sll_non_redundant_mask:
29 ; RV32I-NEXT: andi a1, a1, 15
30 ; RV32I-NEXT: sll a0, a0, a1
33 ; RV64I-LABEL: sll_non_redundant_mask:
35 ; RV64I-NEXT: andi a1, a1, 15
36 ; RV64I-NEXT: sllw a0, a0, a1
43 define i32 @srl_redundant_mask(i32 %a, i32 %b) nounwind {
44 ; RV32I-LABEL: srl_redundant_mask:
46 ; RV32I-NEXT: srl a0, a0, a1
49 ; RV64I-LABEL: srl_redundant_mask:
51 ; RV64I-NEXT: srlw a0, a0, a1
58 define i32 @srl_non_redundant_mask(i32 %a, i32 %b) nounwind {
59 ; RV32I-LABEL: srl_non_redundant_mask:
61 ; RV32I-NEXT: andi a1, a1, 7
62 ; RV32I-NEXT: srl a0, a0, a1
65 ; RV64I-LABEL: srl_non_redundant_mask:
67 ; RV64I-NEXT: andi a1, a1, 7
68 ; RV64I-NEXT: srlw a0, a0, a1
75 define i32 @sra_redundant_mask(i32 %a, i32 %b) nounwind {
76 ; RV32I-LABEL: sra_redundant_mask:
78 ; RV32I-NEXT: sra a0, a0, a1
81 ; RV64I-LABEL: sra_redundant_mask:
83 ; RV64I-NEXT: sraw a0, a0, a1
85 %1 = and i32 %b, 65535
90 define i32 @sra_non_redundant_mask(i32 %a, i32 %b) nounwind {
91 ; RV32I-LABEL: sra_non_redundant_mask:
93 ; RV32I-NEXT: andi a1, a1, 32
94 ; RV32I-NEXT: sra a0, a0, a1
97 ; RV64I-LABEL: sra_non_redundant_mask:
99 ; RV64I-NEXT: sraw a0, a0, zero
106 define i32 @sll_redundant_mask_zeros(i32 %a, i32 %b) nounwind {
107 ; RV32I-LABEL: sll_redundant_mask_zeros:
109 ; RV32I-NEXT: slli a1, a1, 1
110 ; RV32I-NEXT: sll a0, a0, a1
113 ; RV64I-LABEL: sll_redundant_mask_zeros:
115 ; RV64I-NEXT: slli a1, a1, 1
116 ; RV64I-NEXT: sllw a0, a0, a1
124 define i32 @srl_redundant_mask_zeros(i32 %a, i32 %b) nounwind {
125 ; RV32I-LABEL: srl_redundant_mask_zeros:
127 ; RV32I-NEXT: slli a1, a1, 2
128 ; RV32I-NEXT: srl a0, a0, a1
131 ; RV64I-LABEL: srl_redundant_mask_zeros:
133 ; RV64I-NEXT: slli a1, a1, 2
134 ; RV64I-NEXT: srlw a0, a0, a1
142 define i32 @sra_redundant_mask_zeros(i32 %a, i32 %b) nounwind {
143 ; RV32I-LABEL: sra_redundant_mask_zeros:
145 ; RV32I-NEXT: slli a1, a1, 3
146 ; RV32I-NEXT: sra a0, a0, a1
149 ; RV64I-LABEL: sra_redundant_mask_zeros:
151 ; RV64I-NEXT: slli a1, a1, 3
152 ; RV64I-NEXT: sraw a0, a0, a1
160 define i64 @sll_redundant_mask_zeros_i64(i64 %a, i64 %b) nounwind {
161 ; RV32I-LABEL: sll_redundant_mask_zeros_i64:
163 ; RV32I-NEXT: slli a2, a2, 2
164 ; RV32I-NEXT: andi a4, a2, 60
165 ; RV32I-NEXT: addi a3, a4, -32
166 ; RV32I-NEXT: bltz a3, .LBB9_2
167 ; RV32I-NEXT: # %bb.1:
168 ; RV32I-NEXT: sll a1, a0, a4
169 ; RV32I-NEXT: j .LBB9_3
170 ; RV32I-NEXT: .LBB9_2:
171 ; RV32I-NEXT: sll a1, a1, a2
172 ; RV32I-NEXT: srli a5, a0, 1
173 ; RV32I-NEXT: not a4, a4
174 ; RV32I-NEXT: srl a4, a5, a4
175 ; RV32I-NEXT: or a1, a1, a4
176 ; RV32I-NEXT: .LBB9_3:
177 ; RV32I-NEXT: sll a0, a0, a2
178 ; RV32I-NEXT: srai a3, a3, 31
179 ; RV32I-NEXT: and a0, a3, a0
182 ; RV64I-LABEL: sll_redundant_mask_zeros_i64:
184 ; RV64I-NEXT: slli a1, a1, 2
185 ; RV64I-NEXT: sll a0, a0, a1
193 define i64 @srl_redundant_mask_zeros_i64(i64 %a, i64 %b) nounwind {
194 ; RV32I-LABEL: srl_redundant_mask_zeros_i64:
196 ; RV32I-NEXT: slli a2, a2, 3
197 ; RV32I-NEXT: andi a4, a2, 56
198 ; RV32I-NEXT: addi a3, a4, -32
199 ; RV32I-NEXT: bltz a3, .LBB10_2
200 ; RV32I-NEXT: # %bb.1:
201 ; RV32I-NEXT: srl a0, a1, a4
202 ; RV32I-NEXT: j .LBB10_3
203 ; RV32I-NEXT: .LBB10_2:
204 ; RV32I-NEXT: srl a0, a0, a2
205 ; RV32I-NEXT: slli a5, a1, 1
206 ; RV32I-NEXT: not a4, a4
207 ; RV32I-NEXT: sll a4, a5, a4
208 ; RV32I-NEXT: or a0, a0, a4
209 ; RV32I-NEXT: .LBB10_3:
210 ; RV32I-NEXT: srl a1, a1, a2
211 ; RV32I-NEXT: srai a3, a3, 31
212 ; RV32I-NEXT: and a1, a3, a1
215 ; RV64I-LABEL: srl_redundant_mask_zeros_i64:
217 ; RV64I-NEXT: slli a1, a1, 3
218 ; RV64I-NEXT: srl a0, a0, a1
226 define i64 @sra_redundant_mask_zeros_i64(i64 %a, i64 %b) nounwind {
227 ; RV32I-LABEL: sra_redundant_mask_zeros_i64:
229 ; RV32I-NEXT: slli a2, a2, 4
230 ; RV32I-NEXT: andi a3, a2, 48
231 ; RV32I-NEXT: addi a4, a3, -32
232 ; RV32I-NEXT: bltz a4, .LBB11_2
233 ; RV32I-NEXT: # %bb.1:
234 ; RV32I-NEXT: sra a0, a1, a3
235 ; RV32I-NEXT: srai a1, a1, 31
237 ; RV32I-NEXT: .LBB11_2:
238 ; RV32I-NEXT: srl a0, a0, a2
239 ; RV32I-NEXT: slli a4, a1, 1
240 ; RV32I-NEXT: not a3, a3
241 ; RV32I-NEXT: sll a3, a4, a3
242 ; RV32I-NEXT: or a0, a0, a3
243 ; RV32I-NEXT: sra a1, a1, a2
246 ; RV64I-LABEL: sra_redundant_mask_zeros_i64:
248 ; RV64I-NEXT: slli a1, a1, 4
249 ; RV64I-NEXT: sra a0, a0, a1