1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc --mtriple=loongarch32 -mattr=+d < %s | FileCheck %s --check-prefix=LA32
3 ; RUN: llc --mtriple=loongarch64 -mattr=+d < %s | FileCheck %s --check-prefix=LA64
5 ;; This test checks that unnecessary masking of shift amount operands is
6 ;; eliminated during instruction selection. The test needs to ensure that the
7 ;; masking is not removed if it may affect the shift amount.
9 define i32 @sll_redundant_mask(i32 %a, i32 %b) {
10 ; LA32-LABEL: sll_redundant_mask:
12 ; LA32-NEXT: sll.w $a0, $a0, $a1
15 ; LA64-LABEL: sll_redundant_mask:
17 ; LA64-NEXT: sll.w $a0, $a0, $a1
24 define i32 @sll_non_redundant_mask(i32 %a, i32 %b) {
25 ; LA32-LABEL: sll_non_redundant_mask:
27 ; LA32-NEXT: andi $a1, $a1, 15
28 ; LA32-NEXT: sll.w $a0, $a0, $a1
31 ; LA64-LABEL: sll_non_redundant_mask:
33 ; LA64-NEXT: andi $a1, $a1, 15
34 ; LA64-NEXT: sll.w $a0, $a0, $a1
41 define i32 @srl_redundant_mask(i32 %a, i32 %b) {
42 ; LA32-LABEL: srl_redundant_mask:
44 ; LA32-NEXT: srl.w $a0, $a0, $a1
47 ; LA64-LABEL: srl_redundant_mask:
49 ; LA64-NEXT: srl.w $a0, $a0, $a1
56 define i32 @srl_non_redundant_mask(i32 %a, i32 %b) {
57 ; LA32-LABEL: srl_non_redundant_mask:
59 ; LA32-NEXT: andi $a1, $a1, 7
60 ; LA32-NEXT: srl.w $a0, $a0, $a1
63 ; LA64-LABEL: srl_non_redundant_mask:
65 ; LA64-NEXT: andi $a1, $a1, 7
66 ; LA64-NEXT: srl.w $a0, $a0, $a1
73 define i32 @sra_redundant_mask(i32 %a, i32 %b) {
74 ; LA32-LABEL: sra_redundant_mask:
76 ; LA32-NEXT: sra.w $a0, $a0, $a1
79 ; LA64-LABEL: sra_redundant_mask:
81 ; LA64-NEXT: sra.w $a0, $a0, $a1
83 %1 = and i32 %b, 65535
88 define i32 @sra_non_redundant_mask(i32 %a, i32 %b) {
89 ; LA32-LABEL: sra_non_redundant_mask:
91 ; LA32-NEXT: andi $a1, $a1, 32
92 ; LA32-NEXT: sra.w $a0, $a0, $a1
95 ; LA64-LABEL: sra_non_redundant_mask:
97 ; LA64-NEXT: andi $a1, $a1, 32
98 ; LA64-NEXT: sra.w $a0, $a0, $a1
105 define i32 @sll_redundant_mask_zeros(i32 %a, i32 %b) {
106 ; LA32-LABEL: sll_redundant_mask_zeros:
108 ; LA32-NEXT: slli.w $a1, $a1, 1
109 ; LA32-NEXT: sll.w $a0, $a0, $a1
112 ; LA64-LABEL: sll_redundant_mask_zeros:
114 ; LA64-NEXT: slli.d $a1, $a1, 1
115 ; LA64-NEXT: sll.w $a0, $a0, $a1
123 define i32 @srl_redundant_mask_zeros(i32 %a, i32 %b) {
124 ; LA32-LABEL: srl_redundant_mask_zeros:
126 ; LA32-NEXT: slli.w $a1, $a1, 2
127 ; LA32-NEXT: srl.w $a0, $a0, $a1
130 ; LA64-LABEL: srl_redundant_mask_zeros:
132 ; LA64-NEXT: slli.d $a1, $a1, 2
133 ; LA64-NEXT: srl.w $a0, $a0, $a1
141 define i32 @sra_redundant_mask_zeros(i32 %a, i32 %b) {
142 ; LA32-LABEL: sra_redundant_mask_zeros:
144 ; LA32-NEXT: slli.w $a1, $a1, 3
145 ; LA32-NEXT: sra.w $a0, $a0, $a1
148 ; LA64-LABEL: sra_redundant_mask_zeros:
150 ; LA64-NEXT: slli.d $a1, $a1, 3
151 ; LA64-NEXT: sra.w $a0, $a0, $a1
159 define i64 @sll_redundant_mask_zeros_i64(i64 %a, i64 %b) {
160 ; LA32-LABEL: sll_redundant_mask_zeros_i64:
162 ; LA32-NEXT: slli.w $a2, $a2, 2
163 ; LA32-NEXT: sll.w $a1, $a1, $a2
164 ; LA32-NEXT: srli.w $a3, $a0, 1
165 ; LA32-NEXT: andi $a4, $a2, 60
166 ; LA32-NEXT: xori $a5, $a4, 31
167 ; LA32-NEXT: srl.w $a3, $a3, $a5
168 ; LA32-NEXT: or $a1, $a1, $a3
169 ; LA32-NEXT: addi.w $a3, $a4, -32
170 ; LA32-NEXT: slti $a4, $a3, 0
171 ; LA32-NEXT: maskeqz $a1, $a1, $a4
172 ; LA32-NEXT: sll.w $a5, $a0, $a3
173 ; LA32-NEXT: masknez $a4, $a5, $a4
174 ; LA32-NEXT: or $a1, $a1, $a4
175 ; LA32-NEXT: sll.w $a0, $a0, $a2
176 ; LA32-NEXT: srai.w $a2, $a3, 31
177 ; LA32-NEXT: and $a0, $a2, $a0
180 ; LA64-LABEL: sll_redundant_mask_zeros_i64:
182 ; LA64-NEXT: slli.d $a1, $a1, 2
183 ; LA64-NEXT: sll.d $a0, $a0, $a1
191 define i64 @srl_redundant_mask_zeros_i64(i64 %a, i64 %b) {
192 ; LA32-LABEL: srl_redundant_mask_zeros_i64:
194 ; LA32-NEXT: slli.w $a2, $a2, 3
195 ; LA32-NEXT: srl.w $a0, $a0, $a2
196 ; LA32-NEXT: slli.w $a3, $a1, 1
197 ; LA32-NEXT: andi $a4, $a2, 56
198 ; LA32-NEXT: xori $a5, $a4, 31
199 ; LA32-NEXT: sll.w $a3, $a3, $a5
200 ; LA32-NEXT: or $a0, $a0, $a3
201 ; LA32-NEXT: addi.w $a3, $a4, -32
202 ; LA32-NEXT: slti $a4, $a3, 0
203 ; LA32-NEXT: maskeqz $a0, $a0, $a4
204 ; LA32-NEXT: srl.w $a5, $a1, $a3
205 ; LA32-NEXT: masknez $a4, $a5, $a4
206 ; LA32-NEXT: or $a0, $a0, $a4
207 ; LA32-NEXT: srl.w $a1, $a1, $a2
208 ; LA32-NEXT: srai.w $a2, $a3, 31
209 ; LA32-NEXT: and $a1, $a2, $a1
212 ; LA64-LABEL: srl_redundant_mask_zeros_i64:
214 ; LA64-NEXT: slli.d $a1, $a1, 3
215 ; LA64-NEXT: srl.d $a0, $a0, $a1
223 define i64 @sra_redundant_mask_zeros_i64(i64 %a, i64 %b) {
224 ; LA32-LABEL: sra_redundant_mask_zeros_i64:
226 ; LA32-NEXT: srai.w $a3, $a1, 31
227 ; LA32-NEXT: slli.w $a4, $a2, 4
228 ; LA32-NEXT: andi $a5, $a4, 48
229 ; LA32-NEXT: addi.w $a6, $a5, -32
230 ; LA32-NEXT: slti $a7, $a6, 0
231 ; LA32-NEXT: masknez $a2, $a3, $a7
232 ; LA32-NEXT: sra.w $a3, $a1, $a4
233 ; LA32-NEXT: maskeqz $a3, $a3, $a7
234 ; LA32-NEXT: or $a2, $a3, $a2
235 ; LA32-NEXT: srl.w $a0, $a0, $a4
236 ; LA32-NEXT: slli.w $a3, $a1, 1
237 ; LA32-NEXT: xori $a4, $a5, 31
238 ; LA32-NEXT: sll.w $a3, $a3, $a4
239 ; LA32-NEXT: or $a0, $a0, $a3
240 ; LA32-NEXT: maskeqz $a0, $a0, $a7
241 ; LA32-NEXT: sra.w $a1, $a1, $a6
242 ; LA32-NEXT: masknez $a1, $a1, $a7
243 ; LA32-NEXT: or $a0, $a0, $a1
244 ; LA32-NEXT: move $a1, $a2
247 ; LA64-LABEL: sra_redundant_mask_zeros_i64:
249 ; LA64-NEXT: slli.d $a1, $a1, 4
250 ; LA64-NEXT: sra.d $a0, $a0, $a1