@@ -260,3 +260,163 @@ define <4 x i32> @or_zext_nneg(<4 x i16> %a, <4 x i16> %b) {
260260 %or = or <4 x i32 > %z1 , %z2
261261 ret <4 x i32 > %or
262262}
263+
264+ ; Test bitwise operations with integer-to-integer bitcast with one constant
265+ define <2 x i32 > @or_bitcast_v4i16_to_v2i32_constant (<4 x i16 > %a ) {
266+ ; CHECK-LABEL: @or_bitcast_v4i16_to_v2i32_constant(
267+ ; CHECK-NEXT: [[BC1:%.*]] = bitcast <4 x i16> [[A:%.*]] to <2 x i32>
268+ ; CHECK-NEXT: [[OR:%.*]] = or <2 x i32> [[BC1]], <i32 1000000, i32 2000000>
269+ ; CHECK-NEXT: ret <2 x i32> [[OR]]
270+ ;
271+ %bc1 = bitcast <4 x i16 > %a to <2 x i32 >
272+ %or = or <2 x i32 > %bc1 , <i32 1000000 , i32 2000000 >
273+ ret <2 x i32 > %or
274+ }
275+
276+ define <2 x i32 > @or_bitcast_v4i16_to_v2i32_constant_commuted (<4 x i16 > %a ) {
277+ ; CHECK-LABEL: @or_bitcast_v4i16_to_v2i32_constant_commuted(
278+ ; CHECK-NEXT: [[BC1:%.*]] = bitcast <4 x i16> [[A:%.*]] to <2 x i32>
279+ ; CHECK-NEXT: [[OR:%.*]] = or <2 x i32> <i32 1000000, i32 2000000>, [[BC1]]
280+ ; CHECK-NEXT: ret <2 x i32> [[OR]]
281+ ;
282+ %bc1 = bitcast <4 x i16 > %a to <2 x i32 >
283+ %or = or <2 x i32 > <i32 1000000 , i32 2000000 >, %bc1
284+ ret <2 x i32 > %or
285+ }
286+
287+ ; Test bitwise operations with truncate and one constant
288+ define <4 x i16 > @or_trunc_v4i32_to_v4i16_constant (<4 x i32 > %a ) {
289+ ; CHECK-LABEL: @or_trunc_v4i32_to_v4i16_constant(
290+ ; CHECK-NEXT: [[T1:%.*]] = trunc <4 x i32> [[A:%.*]] to <4 x i16>
291+ ; CHECK-NEXT: [[AND:%.*]] = or <4 x i16> [[T1]], <i16 1, i16 2, i16 3, i16 4>
292+ ; CHECK-NEXT: ret <4 x i16> [[AND]]
293+ ;
294+ %t1 = trunc <4 x i32 > %a to <4 x i16 >
295+ %or = or <4 x i16 > %t1 , <i16 1 , i16 2 , i16 3 , i16 4 >
296+ ret <4 x i16 > %or
297+ }
298+
299+ ; Test bitwise operations with zero extend and one constant
300+ define <4 x i32 > @or_zext_v4i16_to_v4i32_constant (<4 x i16 > %a ) {
301+ ; CHECK-LABEL: @or_zext_v4i16_to_v4i32_constant(
302+ ; CHECK-NEXT: [[Z1:%.*]] = zext <4 x i16> [[A:%.*]] to <4 x i32>
303+ ; CHECK-NEXT: [[AND:%.*]] = or <4 x i32> [[Z1]], <i32 1, i32 2, i32 3, i32 4>
304+ ; CHECK-NEXT: ret <4 x i32> [[AND]]
305+ ;
306+ %z1 = zext <4 x i16 > %a to <4 x i32 >
307+ %or = or <4 x i32 > %z1 , <i32 1 , i32 2 , i32 3 , i32 4 >
308+ ret <4 x i32 > %or
309+ }
310+
311+ define <4 x i32 > @or_zext_v4i8_to_v4i32_constant_with_loss (<4 x i8 > %a ) {
312+ ; CHECK-LABEL: @or_zext_v4i8_to_v4i32_constant_with_loss(
313+ ; CHECK-NEXT: [[Z1:%.*]] = zext <4 x i8> [[A:%.*]] to <4 x i32>
314+ ; CHECK-NEXT: [[OR:%.*]] = or <4 x i32> [[Z1]], <i32 1024, i32 129, i32 3, i32 4>
315+ ; CHECK-NEXT: ret <4 x i32> [[OR]]
316+ ;
317+ %z1 = zext <4 x i8 > %a to <4 x i32 >
318+ %or = or <4 x i32 > %z1 , <i32 1024 , i32 129 , i32 3 , i32 4 >
319+ ret <4 x i32 > %or
320+ }
321+
322+ ; Test bitwise operations with sign extend and one constant
323+ define <4 x i32 > @or_sext_v4i8_to_v4i32_positive_constant (<4 x i8 > %a ) {
324+ ; CHECK-LABEL: @or_sext_v4i8_to_v4i32_positive_constant(
325+ ; CHECK-NEXT: [[S1:%.*]] = sext <4 x i8> [[A:%.*]] to <4 x i32>
326+ ; CHECK-NEXT: [[OR:%.*]] = or <4 x i32> [[S1]], <i32 1, i32 2, i32 3, i32 4>
327+ ; CHECK-NEXT: ret <4 x i32> [[OR]]
328+ ;
329+ %s1 = sext <4 x i8 > %a to <4 x i32 >
330+ %or = or <4 x i32 > %s1 , <i32 1 , i32 2 , i32 3 , i32 4 >
331+ ret <4 x i32 > %or
332+ }
333+
334+ define <4 x i32 > @or_sext_v4i8_to_v4i32_minus_constant (<4 x i8 > %a ) {
335+ ; CHECK-LABEL: @or_sext_v4i8_to_v4i32_minus_constant(
336+ ; CHECK-NEXT: [[S1:%.*]] = sext <4 x i8> [[A:%.*]] to <4 x i32>
337+ ; CHECK-NEXT: [[OR:%.*]] = or <4 x i32> [[S1]], <i32 -1, i32 -2, i32 -3, i32 -4>
338+ ; CHECK-NEXT: ret <4 x i32> [[OR]]
339+ ;
340+ %s1 = sext <4 x i8 > %a to <4 x i32 >
341+ %or = or <4 x i32 > %s1 , <i32 -1 , i32 -2 , i32 -3 , i32 -4 >
342+ ret <4 x i32 > %or
343+ }
344+
345+ define <4 x i32 > @or_sext_v4i8_to_v4i32_constant_with_loss (<4 x i8 > %a ) {
346+ ; CHECK-LABEL: @or_sext_v4i8_to_v4i32_constant_with_loss(
347+ ; CHECK-NEXT: [[Z1:%.*]] = sext <4 x i8> [[A:%.*]] to <4 x i32>
348+ ; CHECK-NEXT: [[OR:%.*]] = or <4 x i32> [[Z1]], <i32 -10000, i32 2, i32 3, i32 4>
349+ ; CHECK-NEXT: ret <4 x i32> [[OR]]
350+ ;
351+ %z1 = sext <4 x i8 > %a to <4 x i32 >
352+ %or = or <4 x i32 > %z1 , <i32 -10000 , i32 2 , i32 3 , i32 4 >
353+ ret <4 x i32 > %or
354+ }
355+
356+ ; Test truncate with flag preservation and one constant
357+ define <4 x i16 > @and_trunc_nuw_nsw_constant (<4 x i32 > %a ) {
358+ ; CHECK-LABEL: @and_trunc_nuw_nsw_constant(
359+ ; CHECK-NEXT: [[T1:%.*]] = trunc nuw nsw <4 x i32> [[A:%.*]] to <4 x i16>
360+ ; CHECK-NEXT: [[AND:%.*]] = and <4 x i16> [[T1]], <i16 1, i16 2, i16 3, i16 4>
361+ ; CHECK-NEXT: ret <4 x i16> [[AND]]
362+ ;
363+ %t1 = trunc nuw nsw <4 x i32 > %a to <4 x i16 >
364+ %and = and <4 x i16 > %t1 , <i16 1 , i16 2 , i16 3 , i16 4 >
365+ ret <4 x i16 > %and
366+ }
367+
368+ define <4 x i8 > @and_trunc_nuw_nsw_minus_constant (<4 x i32 > %a ) {
369+ ; CHECK-LABEL: @and_trunc_nuw_nsw_minus_constant(
370+ ; CHECK-NEXT: [[T1:%.*]] = trunc nuw nsw <4 x i32> [[A:%.*]] to <4 x i8>
371+ ; CHECK-NEXT: [[AND:%.*]] = and <4 x i8> [[T1]], <i8 -16, i8 -15, i8 -14, i8 -13>
372+ ; CHECK-NEXT: ret <4 x i8> [[AND]]
373+ ;
374+ %t1 = trunc nuw nsw <4 x i32 > %a to <4 x i8 >
375+ %and = and <4 x i8 > %t1 , <i8 240 , i8 241 , i8 242 , i8 243 >
376+ ret <4 x i8 > %and
377+ }
378+
379+ define <4 x i8 > @and_trunc_nuw_nsw_multiconstant (<4 x i32 > %a ) {
380+ ; CHECK-LABEL: @and_trunc_nuw_nsw_multiconstant(
381+ ; CHECK-NEXT: [[T1:%.*]] = trunc nuw nsw <4 x i32> [[A:%.*]] to <4 x i8>
382+ ; CHECK-NEXT: [[AND:%.*]] = and <4 x i8> [[T1]], <i8 -16, i8 1, i8 -14, i8 3>
383+ ; CHECK-NEXT: ret <4 x i8> [[AND]]
384+ ;
385+ %t1 = trunc nuw nsw <4 x i32 > %a to <4 x i8 >
386+ %and = and <4 x i8 > %t1 , <i8 240 , i8 1 , i8 242 , i8 3 >
387+ ret <4 x i8 > %and
388+ }
389+
390+ ; Test sign extend with nneg flag and one constant
391+ define <4 x i32 > @or_zext_nneg_constant (<4 x i16 > %a ) {
392+ ; CHECK-LABEL: @or_zext_nneg_constant(
393+ ; CHECK-NEXT: [[Z1:%.*]] = zext nneg <4 x i16> [[A:%.*]] to <4 x i32>
394+ ; CHECK-NEXT: [[OR:%.*]] = or <4 x i32> [[Z1]], <i32 1, i32 2, i32 3, i32 4>
395+ ; CHECK-NEXT: ret <4 x i32> [[OR]]
396+ ;
397+ %z1 = zext nneg <4 x i16 > %a to <4 x i32 >
398+ %or = or <4 x i32 > %z1 , <i32 1 , i32 2 , i32 3 , i32 4 >
399+ ret <4 x i32 > %or
400+ }
401+
402+ define <4 x i32 > @or_zext_nneg_minus_constant (<4 x i8 > %a ) {
403+ ; CHECK-LABEL: @or_zext_nneg_minus_constant(
404+ ; CHECK-NEXT: [[Z1:%.*]] = zext nneg <4 x i8> [[A:%.*]] to <4 x i32>
405+ ; CHECK-NEXT: [[OR:%.*]] = or <4 x i32> [[Z1]], <i32 240, i32 241, i32 242, i32 243>
406+ ; CHECK-NEXT: ret <4 x i32> [[OR]]
407+ ;
408+ %z1 = zext nneg <4 x i8 > %a to <4 x i32 >
409+ %or = or <4 x i32 > %z1 , <i32 240 , i32 241 , i32 242 , i32 243 >
410+ ret <4 x i32 > %or
411+ }
412+
413+ define <4 x i32 > @or_zext_nneg_multiconstant (<4 x i8 > %a ) {
414+ ; CHECK-LABEL: @or_zext_nneg_multiconstant(
415+ ; CHECK-NEXT: [[Z1:%.*]] = zext nneg <4 x i8> [[A:%.*]] to <4 x i32>
416+ ; CHECK-NEXT: [[OR:%.*]] = or <4 x i32> [[Z1]], <i32 240, i32 1, i32 242, i32 3>
417+ ; CHECK-NEXT: ret <4 x i32> [[OR]]
418+ ;
419+ %z1 = zext nneg <4 x i8 > %a to <4 x i32 >
420+ %or = or <4 x i32 > %z1 , <i32 240 , i32 1 , i32 242 , i32 3 >
421+ ret <4 x i32 > %or
422+ }
0 commit comments