1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instcombine -S | FileCheck %s
4 declare i32 @llvm.fshl.i32(i32, i32, i32)
5 declare i33 @llvm.fshr.i33(i33, i33, i33)
6 declare <2 x i32> @llvm.fshr.v2i32(<2 x i32>, <2 x i32>, <2 x i32>)
7 declare <2 x i31> @llvm.fshl.v2i31(<2 x i31>, <2 x i31>, <2 x i31>)
9 ; If the shift mask doesn't include any demanded bits, the funnel shift can be eliminated.
11 define i32 @fshl_mask_simplify1(i32 %x, i32 %y, i32 %sh) {
12 ; CHECK-LABEL: @fshl_mask_simplify1(
13 ; CHECK-NEXT: ret i32 [[X:%.*]]
15 %maskedsh = and i32 %sh, 32
16 %r = call i32 @llvm.fshl.i32(i32 %x, i32 %y, i32 %maskedsh)
20 define <2 x i32> @fshr_mask_simplify2(<2 x i32> %x, <2 x i32> %y, <2 x i32> %sh) {
21 ; CHECK-LABEL: @fshr_mask_simplify2(
22 ; CHECK-NEXT: ret <2 x i32> [[Y:%.*]]
24 %maskedsh = and <2 x i32> %sh, <i32 64, i32 64>
25 %r = call <2 x i32> @llvm.fshr.v2i32(<2 x i32> %x, <2 x i32> %y, <2 x i32> %maskedsh)
31 define i32 @fshl_mask_simplify3(i32 %x, i32 %y, i32 %sh) {
32 ; CHECK-LABEL: @fshl_mask_simplify3(
33 ; CHECK-NEXT: [[MASKEDSH:%.*]] = and i32 [[SH:%.*]], 16
34 ; CHECK-NEXT: [[R:%.*]] = call i32 @llvm.fshl.i32(i32 [[X:%.*]], i32 [[Y:%.*]], i32 [[MASKEDSH]])
35 ; CHECK-NEXT: ret i32 [[R]]
37 %maskedsh = and i32 %sh, 16
38 %r = call i32 @llvm.fshl.i32(i32 %x, i32 %y, i32 %maskedsh)
42 ; Check again with weird bitwidths - the analysis is invalid with non-power-of-2.
44 define i33 @fshr_mask_simplify1(i33 %x, i33 %y, i33 %sh) {
45 ; CHECK-LABEL: @fshr_mask_simplify1(
46 ; CHECK-NEXT: [[MASKEDSH:%.*]] = and i33 [[SH:%.*]], 64
47 ; CHECK-NEXT: [[R:%.*]] = call i33 @llvm.fshr.i33(i33 [[X:%.*]], i33 [[Y:%.*]], i33 [[MASKEDSH]])
48 ; CHECK-NEXT: ret i33 [[R]]
50 %maskedsh = and i33 %sh, 64
51 %r = call i33 @llvm.fshr.i33(i33 %x, i33 %y, i33 %maskedsh)
55 ; Check again with weird bitwidths - the analysis is invalid with non-power-of-2.
57 define <2 x i31> @fshl_mask_simplify2(<2 x i31> %x, <2 x i31> %y, <2 x i31> %sh) {
58 ; CHECK-LABEL: @fshl_mask_simplify2(
59 ; CHECK-NEXT: [[MASKEDSH:%.*]] = and <2 x i31> [[SH:%.*]], <i31 32, i31 32>
60 ; CHECK-NEXT: [[R:%.*]] = call <2 x i31> @llvm.fshl.v2i31(<2 x i31> [[X:%.*]], <2 x i31> [[Y:%.*]], <2 x i31> [[MASKEDSH]])
61 ; CHECK-NEXT: ret <2 x i31> [[R]]
63 %maskedsh = and <2 x i31> %sh, <i31 32, i31 32>
64 %r = call <2 x i31> @llvm.fshl.v2i31(<2 x i31> %x, <2 x i31> %y, <2 x i31> %maskedsh)
68 ; Check again with weird bitwidths - the analysis is invalid with non-power-of-2.
70 define i33 @fshr_mask_simplify3(i33 %x, i33 %y, i33 %sh) {
71 ; CHECK-LABEL: @fshr_mask_simplify3(
72 ; CHECK-NEXT: [[MASKEDSH:%.*]] = and i33 [[SH:%.*]], 32
73 ; CHECK-NEXT: [[R:%.*]] = call i33 @llvm.fshr.i33(i33 [[X:%.*]], i33 [[Y:%.*]], i33 [[MASKEDSH]])
74 ; CHECK-NEXT: ret i33 [[R]]
76 %maskedsh = and i33 %sh, 32
77 %r = call i33 @llvm.fshr.i33(i33 %x, i33 %y, i33 %maskedsh)
81 ; This mask op is unnecessary.
83 define i32 @fshl_mask_not_required(i32 %x, i32 %y, i32 %sh) {
84 ; CHECK-LABEL: @fshl_mask_not_required(
85 ; CHECK-NEXT: [[R:%.*]] = call i32 @llvm.fshl.i32(i32 [[X:%.*]], i32 [[Y:%.*]], i32 [[SH:%.*]])
86 ; CHECK-NEXT: ret i32 [[R]]
88 %maskedsh = and i32 %sh, 31
89 %r = call i32 @llvm.fshl.i32(i32 %x, i32 %y, i32 %maskedsh)
93 ; This mask op can be reduced.
95 define i32 @fshl_mask_reduce_constant(i32 %x, i32 %y, i32 %sh) {
96 ; CHECK-LABEL: @fshl_mask_reduce_constant(
97 ; CHECK-NEXT: [[MASKEDSH:%.*]] = and i32 [[SH:%.*]], 1
98 ; CHECK-NEXT: [[R:%.*]] = call i32 @llvm.fshl.i32(i32 [[X:%.*]], i32 [[Y:%.*]], i32 [[MASKEDSH]])
99 ; CHECK-NEXT: ret i32 [[R]]
101 %maskedsh = and i32 %sh, 33
102 %r = call i32 @llvm.fshl.i32(i32 %x, i32 %y, i32 %maskedsh)
106 ; But this mask op is required.
108 define i32 @fshl_mask_negative(i32 %x, i32 %y, i32 %sh) {
109 ; CHECK-LABEL: @fshl_mask_negative(
110 ; CHECK-NEXT: [[MASKEDSH:%.*]] = and i32 [[SH:%.*]], 15
111 ; CHECK-NEXT: [[R:%.*]] = call i32 @llvm.fshl.i32(i32 [[X:%.*]], i32 [[Y:%.*]], i32 [[MASKEDSH]])
112 ; CHECK-NEXT: ret i32 [[R]]
114 %maskedsh = and i32 %sh, 15
115 %r = call i32 @llvm.fshl.i32(i32 %x, i32 %y, i32 %maskedsh)
119 ; The transform is not limited to mask ops.
121 define <2 x i32> @fshr_set_but_not_demanded_vec(<2 x i32> %x, <2 x i32> %y, <2 x i32> %sh) {
122 ; CHECK-LABEL: @fshr_set_but_not_demanded_vec(
123 ; CHECK-NEXT: [[R:%.*]] = call <2 x i32> @llvm.fshr.v2i32(<2 x i32> [[X:%.*]], <2 x i32> [[Y:%.*]], <2 x i32> [[SH:%.*]])
124 ; CHECK-NEXT: ret <2 x i32> [[R]]
126 %bogusbits = or <2 x i32> %sh, <i32 32, i32 32>
127 %r = call <2 x i32> @llvm.fshr.v2i32(<2 x i32> %x, <2 x i32> %y, <2 x i32> %bogusbits)
131 ; Check again with weird bitwidths - the analysis is invalid with non-power-of-2.
133 define <2 x i31> @fshl_set_but_not_demanded_vec(<2 x i31> %x, <2 x i31> %y, <2 x i31> %sh) {
134 ; CHECK-LABEL: @fshl_set_but_not_demanded_vec(
135 ; CHECK-NEXT: [[BOGUSBITS:%.*]] = or <2 x i31> [[SH:%.*]], <i31 32, i31 32>
136 ; CHECK-NEXT: [[R:%.*]] = call <2 x i31> @llvm.fshl.v2i31(<2 x i31> [[X:%.*]], <2 x i31> [[Y:%.*]], <2 x i31> [[BOGUSBITS]])
137 ; CHECK-NEXT: ret <2 x i31> [[R]]
139 %bogusbits = or <2 x i31> %sh, <i31 32, i31 32>
140 %r = call <2 x i31> @llvm.fshl.v2i31(<2 x i31> %x, <2 x i31> %y, <2 x i31> %bogusbits)
144 ; Simplify one undef or zero operand and constant shift amount.
146 define i32 @fshl_op0_undef(i32 %x) {
147 ; CHECK-LABEL: @fshl_op0_undef(
148 ; CHECK-NEXT: [[R:%.*]] = lshr i32 [[X:%.*]], 25
149 ; CHECK-NEXT: ret i32 [[R]]
151 %r = call i32 @llvm.fshl.i32(i32 undef, i32 %x, i32 7)
155 define i32 @fshl_op0_zero(i32 %x) {
156 ; CHECK-LABEL: @fshl_op0_zero(
157 ; CHECK-NEXT: [[R:%.*]] = lshr i32 [[X:%.*]], 25
158 ; CHECK-NEXT: ret i32 [[R]]
160 %r = call i32 @llvm.fshl.i32(i32 0, i32 %x, i32 7)
164 define i33 @fshr_op0_undef(i33 %x) {
165 ; CHECK-LABEL: @fshr_op0_undef(
166 ; CHECK-NEXT: [[R:%.*]] = lshr i33 [[X:%.*]], 7
167 ; CHECK-NEXT: ret i33 [[R]]
169 %r = call i33 @llvm.fshr.i33(i33 undef, i33 %x, i33 7)
173 define i33 @fshr_op0_zero(i33 %x) {
174 ; CHECK-LABEL: @fshr_op0_zero(
175 ; CHECK-NEXT: [[R:%.*]] = lshr i33 [[X:%.*]], 7
176 ; CHECK-NEXT: ret i33 [[R]]
178 %r = call i33 @llvm.fshr.i33(i33 0, i33 %x, i33 7)
182 define i32 @fshl_op1_undef(i32 %x) {
183 ; CHECK-LABEL: @fshl_op1_undef(
184 ; CHECK-NEXT: [[R:%.*]] = shl i32 [[X:%.*]], 7
185 ; CHECK-NEXT: ret i32 [[R]]
187 %r = call i32 @llvm.fshl.i32(i32 %x, i32 undef, i32 7)
191 define i32 @fshl_op1_zero(i32 %x) {
192 ; CHECK-LABEL: @fshl_op1_zero(
193 ; CHECK-NEXT: [[R:%.*]] = shl i32 [[X:%.*]], 7
194 ; CHECK-NEXT: ret i32 [[R]]
196 %r = call i32 @llvm.fshl.i32(i32 %x, i32 0, i32 7)
200 define i33 @fshr_op1_undef(i33 %x) {
201 ; CHECK-LABEL: @fshr_op1_undef(
202 ; CHECK-NEXT: [[R:%.*]] = shl i33 [[X:%.*]], 26
203 ; CHECK-NEXT: ret i33 [[R]]
205 %r = call i33 @llvm.fshr.i33(i33 %x, i33 undef, i33 7)
209 define i33 @fshr_op1_zero(i33 %x) {
210 ; CHECK-LABEL: @fshr_op1_zero(
211 ; CHECK-NEXT: [[R:%.*]] = shl i33 [[X:%.*]], 26
212 ; CHECK-NEXT: ret i33 [[R]]
214 %r = call i33 @llvm.fshr.i33(i33 %x, i33 0, i33 7)
218 define <2 x i31> @fshl_op0_zero_splat_vec(<2 x i31> %x) {
219 ; CHECK-LABEL: @fshl_op0_zero_splat_vec(
220 ; CHECK-NEXT: [[R:%.*]] = lshr <2 x i31> [[X:%.*]], <i31 24, i31 24>
221 ; CHECK-NEXT: ret <2 x i31> [[R]]
223 %r = call <2 x i31> @llvm.fshl.v2i31(<2 x i31> zeroinitializer, <2 x i31> %x, <2 x i31> <i31 7, i31 7>)
227 define <2 x i31> @fshl_op1_undef_splat_vec(<2 x i31> %x) {
228 ; CHECK-LABEL: @fshl_op1_undef_splat_vec(
229 ; CHECK-NEXT: [[R:%.*]] = shl <2 x i31> [[X:%.*]], <i31 7, i31 7>
230 ; CHECK-NEXT: ret <2 x i31> [[R]]
232 %r = call <2 x i31> @llvm.fshl.v2i31(<2 x i31> %x, <2 x i31> undef, <2 x i31> <i31 7, i31 7>)
236 define <2 x i32> @fshr_op0_undef_splat_vec(<2 x i32> %x) {
237 ; CHECK-LABEL: @fshr_op0_undef_splat_vec(
238 ; CHECK-NEXT: [[R:%.*]] = lshr <2 x i32> [[X:%.*]], <i32 7, i32 7>
239 ; CHECK-NEXT: ret <2 x i32> [[R]]
241 %r = call <2 x i32> @llvm.fshr.v2i32(<2 x i32> undef, <2 x i32> %x, <2 x i32> <i32 7, i32 7>)
245 define <2 x i32> @fshr_op1_zero_splat_vec(<2 x i32> %x) {
246 ; CHECK-LABEL: @fshr_op1_zero_splat_vec(
247 ; CHECK-NEXT: [[R:%.*]] = shl <2 x i32> [[X:%.*]], <i32 25, i32 25>
248 ; CHECK-NEXT: ret <2 x i32> [[R]]
250 %r = call <2 x i32> @llvm.fshr.v2i32(<2 x i32> %x, <2 x i32> zeroinitializer, <2 x i32> <i32 7, i32 7>)
254 define <2 x i31> @fshl_op0_zero_vec(<2 x i31> %x) {
255 ; CHECK-LABEL: @fshl_op0_zero_vec(
256 ; CHECK-NEXT: [[R:%.*]] = lshr <2 x i31> [[X:%.*]], <i31 30, i31 29>
257 ; CHECK-NEXT: ret <2 x i31> [[R]]
259 %r = call <2 x i31> @llvm.fshl.v2i31(<2 x i31> zeroinitializer, <2 x i31> %x, <2 x i31> <i31 -1, i31 33>)
263 define <2 x i31> @fshl_op1_undef_vec(<2 x i31> %x) {
264 ; CHECK-LABEL: @fshl_op1_undef_vec(
265 ; CHECK-NEXT: [[R:%.*]] = shl <2 x i31> [[X:%.*]], <i31 1, i31 2>
266 ; CHECK-NEXT: ret <2 x i31> [[R]]
268 %r = call <2 x i31> @llvm.fshl.v2i31(<2 x i31> %x, <2 x i31> undef, <2 x i31> <i31 -1, i31 33>)
272 define <2 x i32> @fshr_op0_undef_vec(<2 x i32> %x) {
273 ; CHECK-LABEL: @fshr_op0_undef_vec(
274 ; CHECK-NEXT: [[R:%.*]] = lshr <2 x i32> [[X:%.*]], <i32 31, i32 1>
275 ; CHECK-NEXT: ret <2 x i32> [[R]]
277 %r = call <2 x i32> @llvm.fshr.v2i32(<2 x i32> undef, <2 x i32> %x, <2 x i32> <i32 -1, i32 33>)
281 define <2 x i32> @fshr_op1_zero_vec(<2 x i32> %x) {
282 ; CHECK-LABEL: @fshr_op1_zero_vec(
283 ; CHECK-NEXT: [[R:%.*]] = shl <2 x i32> [[X:%.*]], <i32 1, i32 31>
284 ; CHECK-NEXT: ret <2 x i32> [[R]]
286 %r = call <2 x i32> @llvm.fshr.v2i32(<2 x i32> %x, <2 x i32> zeroinitializer, <2 x i32> <i32 -1, i32 33>)
290 ; Only demand bits from one of the operands.
292 define i32 @fshl_only_op0_demanded(i32 %x, i32 %y) {
293 ; CHECK-LABEL: @fshl_only_op0_demanded(
294 ; CHECK-NEXT: [[Z:%.*]] = shl i32 [[X:%.*]], 7
295 ; CHECK-NEXT: [[R:%.*]] = and i32 [[Z]], 128
296 ; CHECK-NEXT: ret i32 [[R]]
298 %z = call i32 @llvm.fshl.i32(i32 %x, i32 %y, i32 7)
303 define i32 @fshl_only_op1_demanded(i32 %x, i32 %y) {
304 ; CHECK-LABEL: @fshl_only_op1_demanded(
305 ; CHECK-NEXT: [[Z:%.*]] = lshr i32 [[Y:%.*]], 25
306 ; CHECK-NEXT: [[R:%.*]] = and i32 [[Z]], 63
307 ; CHECK-NEXT: ret i32 [[R]]
309 %z = call i32 @llvm.fshl.i32(i32 %x, i32 %y, i32 7)
314 define i33 @fshr_only_op1_demanded(i33 %x, i33 %y) {
315 ; CHECK-LABEL: @fshr_only_op1_demanded(
316 ; CHECK-NEXT: [[Z:%.*]] = lshr i33 [[Y:%.*]], 7
317 ; CHECK-NEXT: [[R:%.*]] = and i33 [[Z]], 12392
318 ; CHECK-NEXT: ret i33 [[R]]
320 %z = call i33 @llvm.fshr.i33(i33 %x, i33 %y, i33 7)
321 %r = and i33 %z, 12392
325 define i33 @fshr_only_op0_demanded(i33 %x, i33 %y) {
326 ; CHECK-LABEL: @fshr_only_op0_demanded(
327 ; CHECK-NEXT: [[TMP1:%.*]] = lshr i33 [[X:%.*]], 4
328 ; CHECK-NEXT: [[R:%.*]] = and i33 [[TMP1]], 7
329 ; CHECK-NEXT: ret i33 [[R]]
331 %z = call i33 @llvm.fshr.i33(i33 %x, i33 %y, i33 7)
336 define <2 x i31> @fshl_only_op1_demanded_vec_splat(<2 x i31> %x, <2 x i31> %y) {
337 ; CHECK-LABEL: @fshl_only_op1_demanded_vec_splat(
338 ; CHECK-NEXT: [[Z:%.*]] = lshr <2 x i31> [[Y:%.*]], <i31 24, i31 24>
339 ; CHECK-NEXT: [[R:%.*]] = and <2 x i31> [[Z]], <i31 63, i31 31>
340 ; CHECK-NEXT: ret <2 x i31> [[R]]
342 %z = call <2 x i31> @llvm.fshl.v2i31(<2 x i31> %x, <2 x i31> %y, <2 x i31> <i31 7, i31 7>)
343 %r = and <2 x i31> %z, <i31 63, i31 31>
347 define i32 @fshl_constant_shift_amount_modulo_bitwidth(i32 %x, i32 %y) {
348 ; CHECK-LABEL: @fshl_constant_shift_amount_modulo_bitwidth(
349 ; CHECK-NEXT: [[R:%.*]] = call i32 @llvm.fshl.i32(i32 [[X:%.*]], i32 [[Y:%.*]], i32 1)
350 ; CHECK-NEXT: ret i32 [[R]]
352 %r = call i32 @llvm.fshl.i32(i32 %x, i32 %y, i32 33)
356 define i33 @fshr_constant_shift_amount_modulo_bitwidth(i33 %x, i33 %y) {
357 ; CHECK-LABEL: @fshr_constant_shift_amount_modulo_bitwidth(
358 ; CHECK-NEXT: [[R:%.*]] = call i33 @llvm.fshl.i33(i33 [[X:%.*]], i33 [[Y:%.*]], i33 32)
359 ; CHECK-NEXT: ret i33 [[R]]
361 %r = call i33 @llvm.fshr.i33(i33 %x, i33 %y, i33 34)
365 @external_global = external global i8
367 define i33 @fshr_constant_shift_amount_modulo_bitwidth_constexpr(i33 %x, i33 %y) {
368 ; CHECK-LABEL: @fshr_constant_shift_amount_modulo_bitwidth_constexpr(
369 ; CHECK-NEXT: [[R:%.*]] = call i33 @llvm.fshr.i33(i33 [[X:%.*]], i33 [[Y:%.*]], i33 ptrtoint (i8* @external_global to i33))
370 ; CHECK-NEXT: ret i33 [[R]]
372 %shamt = ptrtoint i8* @external_global to i33
373 %r = call i33 @llvm.fshr.i33(i33 %x, i33 %y, i33 %shamt)
377 define <2 x i32> @fshr_constant_shift_amount_modulo_bitwidth_vec(<2 x i32> %x, <2 x i32> %y) {
378 ; CHECK-LABEL: @fshr_constant_shift_amount_modulo_bitwidth_vec(
379 ; CHECK-NEXT: [[R:%.*]] = call <2 x i32> @llvm.fshl.v2i32(<2 x i32> [[X:%.*]], <2 x i32> [[Y:%.*]], <2 x i32> <i32 30, i32 1>)
380 ; CHECK-NEXT: ret <2 x i32> [[R]]
382 %r = call <2 x i32> @llvm.fshr.v2i32(<2 x i32> %x, <2 x i32> %y, <2 x i32> <i32 34, i32 -1>)
386 define <2 x i31> @fshl_constant_shift_amount_modulo_bitwidth_vec(<2 x i31> %x, <2 x i31> %y) {
387 ; CHECK-LABEL: @fshl_constant_shift_amount_modulo_bitwidth_vec(
388 ; CHECK-NEXT: [[R:%.*]] = call <2 x i31> @llvm.fshl.v2i31(<2 x i31> [[X:%.*]], <2 x i31> [[Y:%.*]], <2 x i31> <i31 3, i31 1>)
389 ; CHECK-NEXT: ret <2 x i31> [[R]]
391 %r = call <2 x i31> @llvm.fshl.v2i31(<2 x i31> %x, <2 x i31> %y, <2 x i31> <i31 34, i31 -1>)
395 define <2 x i31> @fshl_constant_shift_amount_modulo_bitwidth_vec_const_expr(<2 x i31> %x, <2 x i31> %y) {
396 ; CHECK-LABEL: @fshl_constant_shift_amount_modulo_bitwidth_vec_const_expr(
397 ; CHECK-NEXT: [[R:%.*]] = call <2 x i31> @llvm.fshl.v2i31(<2 x i31> [[X:%.*]], <2 x i31> [[Y:%.*]], <2 x i31> <i31 34, i31 ptrtoint (i8* @external_global to i31)>)
398 ; CHECK-NEXT: ret <2 x i31> [[R]]
400 %shamt = ptrtoint i8* @external_global to i31
401 %r = call <2 x i31> @llvm.fshl.v2i31(<2 x i31> %x, <2 x i31> %y, <2 x i31> <i31 34, i31 ptrtoint (i8* @external_global to i31)>)
405 ; The shift modulo bitwidth is the same for all vector elements.
407 define <2 x i31> @fshl_only_op1_demanded_vec_nonsplat(<2 x i31> %x, <2 x i31> %y) {
408 ; CHECK-LABEL: @fshl_only_op1_demanded_vec_nonsplat(
409 ; CHECK-NEXT: [[Z:%.*]] = lshr <2 x i31> [[Y:%.*]], <i31 24, i31 24>
410 ; CHECK-NEXT: [[R:%.*]] = and <2 x i31> [[Z]], <i31 63, i31 31>
411 ; CHECK-NEXT: ret <2 x i31> [[R]]
413 %z = call <2 x i31> @llvm.fshl.v2i31(<2 x i31> %x, <2 x i31> %y, <2 x i31> <i31 7, i31 38>)
414 %r = and <2 x i31> %z, <i31 63, i31 31>
418 define i32 @rotl_constant_shift_amount(i32 %x) {
419 ; CHECK-LABEL: @rotl_constant_shift_amount(
420 ; CHECK-NEXT: [[R:%.*]] = call i32 @llvm.fshl.i32(i32 [[X:%.*]], i32 [[X]], i32 1)
421 ; CHECK-NEXT: ret i32 [[R]]
423 %r = call i32 @llvm.fshl.i32(i32 %x, i32 %x, i32 33)
427 define <2 x i31> @rotl_constant_shift_amount_vec(<2 x i31> %x) {
428 ; CHECK-LABEL: @rotl_constant_shift_amount_vec(
429 ; CHECK-NEXT: [[R:%.*]] = call <2 x i31> @llvm.fshl.v2i31(<2 x i31> [[X:%.*]], <2 x i31> [[X]], <2 x i31> <i31 1, i31 1>)
430 ; CHECK-NEXT: ret <2 x i31> [[R]]
432 %r = call <2 x i31> @llvm.fshl.v2i31(<2 x i31> %x, <2 x i31> %x, <2 x i31> <i31 32, i31 -1>)
436 define i33 @rotr_constant_shift_amount(i33 %x) {
437 ; CHECK-LABEL: @rotr_constant_shift_amount(
438 ; CHECK-NEXT: [[R:%.*]] = call i33 @llvm.fshl.i33(i33 [[X:%.*]], i33 [[X]], i33 32)
439 ; CHECK-NEXT: ret i33 [[R]]
441 %r = call i33 @llvm.fshr.i33(i33 %x, i33 %x, i33 34)
445 define <2 x i32> @rotr_constant_shift_amount_vec(<2 x i32> %x) {
446 ; CHECK-LABEL: @rotr_constant_shift_amount_vec(
447 ; CHECK-NEXT: [[R:%.*]] = call <2 x i32> @llvm.fshl.v2i32(<2 x i32> [[X:%.*]], <2 x i32> [[X]], <2 x i32> <i32 31, i32 1>)
448 ; CHECK-NEXT: ret <2 x i32> [[R]]
450 %r = call <2 x i32> @llvm.fshr.v2i32(<2 x i32> %x, <2 x i32> %x, <2 x i32> <i32 33, i32 -1>)
454 ; Demand bits from both operands -- cannot simplify.
456 define i32 @fshl_both_ops_demanded(i32 %x, i32 %y) {
457 ; CHECK-LABEL: @fshl_both_ops_demanded(
458 ; CHECK-NEXT: [[Z:%.*]] = call i32 @llvm.fshl.i32(i32 [[X:%.*]], i32 [[Y:%.*]], i32 7)
459 ; CHECK-NEXT: [[R:%.*]] = and i32 [[Z]], 192
460 ; CHECK-NEXT: ret i32 [[R]]
462 %z = call i32 @llvm.fshl.i32(i32 %x, i32 %y, i32 7)
467 define i33 @fshr_both_ops_demanded(i33 %x, i33 %y) {
468 ; CHECK-LABEL: @fshr_both_ops_demanded(
469 ; CHECK-NEXT: [[Z:%.*]] = call i33 @llvm.fshl.i33(i33 [[X:%.*]], i33 [[Y:%.*]], i33 7)
470 ; CHECK-NEXT: [[R:%.*]] = and i33 [[Z]], 192
471 ; CHECK-NEXT: ret i33 [[R]]
473 %z = call i33 @llvm.fshr.i33(i33 %x, i33 %y, i33 26)
478 ; Both operands are demanded, but there are known bits.
480 define i32 @fshl_known_bits(i32 %x, i32 %y) {
481 ; CHECK-LABEL: @fshl_known_bits(
482 ; CHECK-NEXT: ret i32 128
484 %x2 = or i32 %x, 1 ; lo bit set
485 %y2 = lshr i32 %y, 1 ; hi bit clear
486 %z = call i32 @llvm.fshl.i32(i32 %x2, i32 %y2, i32 7)
491 define i33 @fshr_known_bits(i33 %x, i33 %y) {
492 ; CHECK-LABEL: @fshr_known_bits(
493 ; CHECK-NEXT: ret i33 128
495 %x2 = or i33 %x, 1 ; lo bit set
496 %y2 = lshr i33 %y, 1 ; hi bit set
497 %z = call i33 @llvm.fshr.i33(i33 %x2, i33 %y2, i33 26)
502 ; This case fails to simplify due to multiple uses.
504 define i33 @fshr_multi_use(i33 %a) {
505 ; CHECK-LABEL: @fshr_multi_use(
506 ; CHECK-NEXT: [[B:%.*]] = call i33 @llvm.fshl.i33(i33 [[A:%.*]], i33 [[A]], i33 32)
507 ; CHECK-NEXT: [[C:%.*]] = lshr i33 [[B]], 23
508 ; CHECK-NEXT: [[D:%.*]] = xor i33 [[C]], [[B]]
509 ; CHECK-NEXT: [[E:%.*]] = and i33 [[D]], 31
510 ; CHECK-NEXT: ret i33 [[E]]
512 %b = tail call i33 @llvm.fshr.i33(i33 %a, i33 %a, i33 1)
519 ; This demonstrates the same simplification working if the fshr intrinsic
520 ; is expanded into shifts and or.
522 define i33 @expanded_fshr_multi_use(i33 %a) {
523 ; CHECK-LABEL: @expanded_fshr_multi_use(
524 ; CHECK-NEXT: [[TMP:%.*]] = lshr i33 [[A:%.*]], 1
525 ; CHECK-NEXT: [[C:%.*]] = lshr i33 [[A]], 24
526 ; CHECK-NEXT: [[D:%.*]] = xor i33 [[C]], [[TMP]]
527 ; CHECK-NEXT: [[E:%.*]] = and i33 [[D]], 31
528 ; CHECK-NEXT: ret i33 [[E]]
530 %tmp = lshr i33 %a, 1
531 %tmp2 = shl i33 %a, 32
532 %b = or i33 %tmp, %tmp2
539 declare i16 @llvm.fshl.i16(i16, i16, i16)
540 declare i16 @llvm.fshr.i16(i16, i16, i16)
541 declare <3 x i16> @llvm.fshl.v3i16(<3 x i16>, <3 x i16>, <3 x i16>)
543 ; Special-case: rotate a 16-bit value left/right by 8-bits is bswap.
545 define i16 @fshl_bswap(i16 %x) {
546 ; CHECK-LABEL: @fshl_bswap(
547 ; CHECK-NEXT: [[R:%.*]] = call i16 @llvm.bswap.i16(i16 [[X:%.*]])
548 ; CHECK-NEXT: ret i16 [[R]]
550 %r = call i16 @llvm.fshl.i16(i16 %x, i16 %x, i16 8)
554 define i16 @fshr_bswap(i16 %x) {
555 ; CHECK-LABEL: @fshr_bswap(
556 ; CHECK-NEXT: [[R:%.*]] = call i16 @llvm.bswap.i16(i16 [[X:%.*]])
557 ; CHECK-NEXT: ret i16 [[R]]
559 %r = call i16 @llvm.fshr.i16(i16 %x, i16 %x, i16 8)
563 define <3 x i16> @fshl_bswap_vector(<3 x i16> %x) {
564 ; CHECK-LABEL: @fshl_bswap_vector(
565 ; CHECK-NEXT: [[R:%.*]] = call <3 x i16> @llvm.bswap.v3i16(<3 x i16> [[X:%.*]])
566 ; CHECK-NEXT: ret <3 x i16> [[R]]
568 %r = call <3 x i16> @llvm.fshl.v3i16(<3 x i16> %x, <3 x i16> %x, <3 x i16> <i16 8, i16 8, i16 8>)
574 define i16 @fshl_bswap_wrong_op(i16 %x, i16 %y) {
575 ; CHECK-LABEL: @fshl_bswap_wrong_op(
576 ; CHECK-NEXT: [[R:%.*]] = call i16 @llvm.fshl.i16(i16 [[X:%.*]], i16 [[Y:%.*]], i16 8)
577 ; CHECK-NEXT: ret i16 [[R]]
579 %r = call i16 @llvm.fshl.i16(i16 %x, i16 %y, i16 8)
585 define i16 @fshr_bswap_wrong_amount(i16 %x) {
586 ; CHECK-LABEL: @fshr_bswap_wrong_amount(
587 ; CHECK-NEXT: [[R:%.*]] = call i16 @llvm.fshl.i16(i16 [[X:%.*]], i16 [[X]], i16 12)
588 ; CHECK-NEXT: ret i16 [[R]]
590 %r = call i16 @llvm.fshr.i16(i16 %x, i16 %x, i16 4)
596 define i32 @fshl_bswap_wrong_width(i32 %x) {
597 ; CHECK-LABEL: @fshl_bswap_wrong_width(
598 ; CHECK-NEXT: [[R:%.*]] = call i32 @llvm.fshl.i32(i32 [[X:%.*]], i32 [[X]], i32 8)
599 ; CHECK-NEXT: ret i32 [[R]]
601 %r = call i32 @llvm.fshl.i32(i32 %x, i32 %x, i32 8)
605 define i32 @fshl_mask_args_same1(i32 %a) {
606 ; CHECK-LABEL: @fshl_mask_args_same1(
607 ; CHECK-NEXT: [[TMP2:%.*]] = lshr i32 [[A:%.*]], 16
608 ; CHECK-NEXT: ret i32 [[TMP2]]
610 %tmp1 = and i32 %a, 4294901760 ; 0xffff0000
611 %tmp2 = call i32 @llvm.fshl.i32(i32 %tmp1, i32 %tmp1, i32 16)
615 define i32 @fshl_mask_args_same2(i32 %a) {
616 ; CHECK-LABEL: @fshl_mask_args_same2(
617 ; CHECK-NEXT: [[TMP1:%.*]] = shl i32 [[A:%.*]], 8
618 ; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], 65280
619 ; CHECK-NEXT: ret i32 [[TMP2]]
621 %tmp1 = and i32 %a, 255
622 %tmp2 = call i32 @llvm.fshl.i32(i32 %tmp1, i32 %tmp1, i32 8)
626 define i32 @fshl_mask_args_same3(i32 %a) {
627 ; CHECK-LABEL: @fshl_mask_args_same3(
628 ; CHECK-NEXT: [[TMP2:%.*]] = shl i32 [[A:%.*]], 24
629 ; CHECK-NEXT: ret i32 [[TMP2]]
631 %tmp1 = and i32 %a, 255
632 %tmp2 = call i32 @llvm.fshl.i32(i32 %tmp1, i32 %tmp1, i32 24)
636 define i32 @fshl_mask_args_different(i32 %a) {
637 ; CHECK-LABEL: @fshl_mask_args_different(
638 ; CHECK-NEXT: [[TMP1:%.*]] = lshr i32 [[A:%.*]], 15
639 ; CHECK-NEXT: [[TMP3:%.*]] = and i32 [[TMP1]], 130560
640 ; CHECK-NEXT: ret i32 [[TMP3]]
642 %tmp2 = and i32 %a, 4294901760 ; 0xfffff00f
643 %tmp1 = and i32 %a, 4278190080 ; 0xff00f00f
644 %tmp3 = call i32 @llvm.fshl.i32(i32 %tmp2, i32 %tmp1, i32 17)
648 define <2 x i31> @fshr_mask_args_same_vector(<2 x i31> %a) {
649 ; CHECK-LABEL: @fshr_mask_args_same_vector(
650 ; CHECK-NEXT: [[TMP3:%.*]] = shl <2 x i31> [[A:%.*]], <i31 10, i31 10>
651 ; CHECK-NEXT: ret <2 x i31> [[TMP3]]
653 %tmp1 = and <2 x i31> %a, <i31 1000, i31 1000>
654 %tmp2 = and <2 x i31> %a, <i31 6442450943, i31 6442450943>
655 %tmp3 = call <2 x i31> @llvm.fshl.v2i31(<2 x i31> %tmp2, <2 x i31> %tmp1, <2 x i31> <i31 10, i31 10>)
659 define <2 x i32> @fshr_mask_args_same_vector2(<2 x i32> %a, <2 x i32> %b) {
660 ; CHECK-LABEL: @fshr_mask_args_same_vector2(
661 ; CHECK-NEXT: [[TMP1:%.*]] = and <2 x i32> [[A:%.*]], <i32 1000000, i32 100000>
662 ; CHECK-NEXT: [[TMP3:%.*]] = lshr exact <2 x i32> [[TMP1]], <i32 3, i32 3>
663 ; CHECK-NEXT: ret <2 x i32> [[TMP3]]
665 %tmp1 = and <2 x i32> %a, <i32 1000000, i32 100000>
666 %tmp2 = and <2 x i32> %a, <i32 6442450943, i32 6442450943>
667 %tmp3 = call <2 x i32> @llvm.fshr.v2i32(<2 x i32> %tmp1, <2 x i32> %tmp1, <2 x i32> <i32 3, i32 3>)
671 define <2 x i31> @fshr_mask_args_same_vector3_different_but_still_prunable(<2 x i31> %a) {
672 ; CHECK-LABEL: @fshr_mask_args_same_vector3_different_but_still_prunable(
673 ; CHECK-NEXT: [[TMP1:%.*]] = and <2 x i31> [[A:%.*]], <i31 1000, i31 1000>
674 ; CHECK-NEXT: [[TMP3:%.*]] = call <2 x i31> @llvm.fshl.v2i31(<2 x i31> [[A]], <2 x i31> [[TMP1]], <2 x i31> <i31 10, i31 3>)
675 ; CHECK-NEXT: ret <2 x i31> [[TMP3]]
677 %tmp1 = and <2 x i31> %a, <i31 1000, i31 1000>
678 %tmp2 = and <2 x i31> %a, <i31 6442450943, i31 6442450943>
679 %tmp3 = call <2 x i31> @llvm.fshl.v2i31(<2 x i31> %tmp2, <2 x i31> %tmp1, <2 x i31> <i31 10, i31 3>)