@@ -454,6 +454,81 @@ define i32 @zext_or_masked_bit_test_uses(i32 %a, i32 %b, i32 %x) {
454
454
ret i32 %z
455
455
}
456
456
457
+ define i16 @zext_masked_bit_zero_to_smaller_bitwidth (i32 %a , i32 %b ) {
458
+ ; CHECK-LABEL: @zext_masked_bit_zero_to_smaller_bitwidth(
459
+ ; CHECK-NEXT: [[SHL:%.*]] = shl nuw i32 1, [[B:%.*]]
460
+ ; CHECK-NEXT: [[AND:%.*]] = and i32 [[SHL]], [[A:%.*]]
461
+ ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[AND]], 0
462
+ ; CHECK-NEXT: [[Z:%.*]] = zext i1 [[CMP]] to i16
463
+ ; CHECK-NEXT: ret i16 [[Z]]
464
+ ;
465
+ %shl = shl i32 1 , %b
466
+ %and = and i32 %shl , %a
467
+ %cmp = icmp eq i32 %and , 0
468
+ %z = zext i1 %cmp to i16
469
+ ret i16 %z
470
+ }
471
+
472
+ define <4 x i16 > @zext_masked_bit_zero_to_smaller_bitwidth_v4i32 (<4 x i32 > %a , <4 x i32 > %b ) {
473
+ ; CHECK-LABEL: @zext_masked_bit_zero_to_smaller_bitwidth_v4i32(
474
+ ; CHECK-NEXT: [[SHL:%.*]] = shl nuw <4 x i32> <i32 1, i32 1, i32 1, i32 1>, [[B:%.*]]
475
+ ; CHECK-NEXT: [[AND:%.*]] = and <4 x i32> [[SHL]], [[A:%.*]]
476
+ ; CHECK-NEXT: [[CMP:%.*]] = icmp eq <4 x i32> [[AND]], zeroinitializer
477
+ ; CHECK-NEXT: [[Z:%.*]] = zext <4 x i1> [[CMP]] to <4 x i16>
478
+ ; CHECK-NEXT: ret <4 x i16> [[Z]]
479
+ ;
480
+ %shl = shl <4 x i32 > <i32 1 , i32 1 , i32 1 , i32 1 >, %b
481
+ %and = and <4 x i32 > %shl , %a
482
+ %cmp = icmp eq <4 x i32 > %and , <i32 0 , i32 0 , i32 0 , i32 0 >
483
+ %z = zext <4 x i1 > %cmp to <4 x i16 >
484
+ ret <4 x i16 > %z
485
+ }
486
+
487
+ define i16 @zext_masked_bit_nonzero_to_smaller_bitwidth (i32 %a , i32 %b ) {
488
+ ; CHECK-LABEL: @zext_masked_bit_nonzero_to_smaller_bitwidth(
489
+ ; CHECK-NEXT: [[SHL:%.*]] = shl nuw i32 1, [[B:%.*]]
490
+ ; CHECK-NEXT: [[AND:%.*]] = and i32 [[SHL]], [[A:%.*]]
491
+ ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[AND]], 0
492
+ ; CHECK-NEXT: [[Z:%.*]] = zext i1 [[CMP]] to i16
493
+ ; CHECK-NEXT: ret i16 [[Z]]
494
+ ;
495
+ %shl = shl i32 1 , %b
496
+ %and = and i32 %shl , %a
497
+ %cmp = icmp ne i32 %and , 0
498
+ %z = zext i1 %cmp to i16
499
+ ret i16 %z
500
+ }
501
+
502
+ define i64 @zext_masked_bit_zero_to_larger_bitwidth (i32 %a , i32 %b ) {
503
+ ; CHECK-LABEL: @zext_masked_bit_zero_to_larger_bitwidth(
504
+ ; CHECK-NEXT: [[SHL:%.*]] = shl nuw i32 1, [[B:%.*]]
505
+ ; CHECK-NEXT: [[AND:%.*]] = and i32 [[SHL]], [[A:%.*]]
506
+ ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[AND]], 0
507
+ ; CHECK-NEXT: [[Z:%.*]] = zext i1 [[CMP]] to i64
508
+ ; CHECK-NEXT: ret i64 [[Z]]
509
+ ;
510
+ %shl = shl i32 1 , %b
511
+ %and = and i32 %shl , %a
512
+ %cmp = icmp eq i32 %and , 0
513
+ %z = zext i1 %cmp to i64
514
+ ret i64 %z
515
+ }
516
+
517
+ define <4 x i64 > @zext_masked_bit_zero_to_larger_bitwidth_v4i32 (<4 x i32 > %a , <4 x i32 > %b ) {
518
+ ; CHECK-LABEL: @zext_masked_bit_zero_to_larger_bitwidth_v4i32(
519
+ ; CHECK-NEXT: [[SHL:%.*]] = shl nuw <4 x i32> <i32 1, i32 1, i32 1, i32 1>, [[B:%.*]]
520
+ ; CHECK-NEXT: [[AND:%.*]] = and <4 x i32> [[SHL]], [[A:%.*]]
521
+ ; CHECK-NEXT: [[CMP:%.*]] = icmp eq <4 x i32> [[AND]], zeroinitializer
522
+ ; CHECK-NEXT: [[Z:%.*]] = zext <4 x i1> [[CMP]] to <4 x i64>
523
+ ; CHECK-NEXT: ret <4 x i64> [[Z]]
524
+ ;
525
+ %shl = shl <4 x i32 > <i32 1 , i32 1 , i32 1 , i32 1 >, %b
526
+ %and = and <4 x i32 > %shl , %a
527
+ %cmp = icmp eq <4 x i32 > %and , <i32 0 , i32 0 , i32 0 , i32 0 >
528
+ %z = zext <4 x i1 > %cmp to <4 x i64 >
529
+ ret <4 x i64 > %z
530
+ }
531
+
457
532
define i32 @notneg_zext_wider (i8 %x ) {
458
533
; CHECK-LABEL: @notneg_zext_wider(
459
534
; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[X:%.*]], -1
0 commit comments