@@ -454,6 +454,116 @@ 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
+ ; Negative test
488
+ define i16 @zext_masked_bit_zero_to_smaller_bitwidth_multi_use_shl (i32 %a , i32 %b ) {
489
+ ; CHECK-LABEL: @zext_masked_bit_zero_to_smaller_bitwidth_multi_use_shl(
490
+ ; CHECK-NEXT: [[SHL:%.*]] = shl nuw i32 1, [[B:%.*]]
491
+ ; CHECK-NEXT: [[AND:%.*]] = and i32 [[SHL]], [[A:%.*]]
492
+ ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[AND]], 0
493
+ ; CHECK-NEXT: [[Z:%.*]] = zext i1 [[CMP]] to i16
494
+ ; CHECK-NEXT: call void @use32(i32 [[SHL]])
495
+ ; CHECK-NEXT: ret i16 [[Z]]
496
+ ;
497
+ %shl = shl i32 1 , %b
498
+ %and = and i32 %shl , %a
499
+ %cmp = icmp eq i32 %and , 0
500
+ %z = zext i1 %cmp to i16
501
+ call void @use32 (i32 %shl )
502
+ ret i16 %z
503
+ }
504
+
505
+ define i16 @zext_masked_bit_nonzero_to_smaller_bitwidth (i32 %a , i32 %b ) {
506
+ ; CHECK-LABEL: @zext_masked_bit_nonzero_to_smaller_bitwidth(
507
+ ; CHECK-NEXT: [[SHL:%.*]] = shl nuw i32 1, [[B:%.*]]
508
+ ; CHECK-NEXT: [[AND:%.*]] = and i32 [[SHL]], [[A:%.*]]
509
+ ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[AND]], 0
510
+ ; CHECK-NEXT: [[Z:%.*]] = zext i1 [[CMP]] to i16
511
+ ; CHECK-NEXT: ret i16 [[Z]]
512
+ ;
513
+ %shl = shl i32 1 , %b
514
+ %and = and i32 %shl , %a
515
+ %cmp = icmp ne i32 %and , 0
516
+ %z = zext i1 %cmp to i16
517
+ ret i16 %z
518
+ }
519
+
520
+ define i16 @zext_masked_bit_nonzero_to_smaller_bitwidth_multi_use_shl (i32 %a , i32 %b ) {
521
+ ; CHECK-LABEL: @zext_masked_bit_nonzero_to_smaller_bitwidth_multi_use_shl(
522
+ ; CHECK-NEXT: [[SHL:%.*]] = shl nuw i32 1, [[B:%.*]]
523
+ ; CHECK-NEXT: [[AND:%.*]] = and i32 [[SHL]], [[A:%.*]]
524
+ ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[AND]], 0
525
+ ; CHECK-NEXT: [[Z:%.*]] = zext i1 [[CMP]] to i16
526
+ ; CHECK-NEXT: call void @use32(i32 [[SHL]])
527
+ ; CHECK-NEXT: ret i16 [[Z]]
528
+ ;
529
+ %shl = shl i32 1 , %b
530
+ %and = and i32 %shl , %a
531
+ %cmp = icmp ne i32 %and , 0
532
+ %z = zext i1 %cmp to i16
533
+ call void @use32 (i32 %shl )
534
+ ret i16 %z
535
+ }
536
+
537
+ define i64 @zext_masked_bit_zero_to_larger_bitwidth (i32 %a , i32 %b ) {
538
+ ; CHECK-LABEL: @zext_masked_bit_zero_to_larger_bitwidth(
539
+ ; CHECK-NEXT: [[SHL:%.*]] = shl nuw i32 1, [[B:%.*]]
540
+ ; CHECK-NEXT: [[AND:%.*]] = and i32 [[SHL]], [[A:%.*]]
541
+ ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[AND]], 0
542
+ ; CHECK-NEXT: [[Z:%.*]] = zext i1 [[CMP]] to i64
543
+ ; CHECK-NEXT: ret i64 [[Z]]
544
+ ;
545
+ %shl = shl i32 1 , %b
546
+ %and = and i32 %shl , %a
547
+ %cmp = icmp eq i32 %and , 0
548
+ %z = zext i1 %cmp to i64
549
+ ret i64 %z
550
+ }
551
+
552
+ define <4 x i64 > @zext_masked_bit_zero_to_larger_bitwidth_v4i32 (<4 x i32 > %a , <4 x i32 > %b ) {
553
+ ; CHECK-LABEL: @zext_masked_bit_zero_to_larger_bitwidth_v4i32(
554
+ ; CHECK-NEXT: [[SHL:%.*]] = shl nuw <4 x i32> <i32 1, i32 1, i32 1, i32 1>, [[B:%.*]]
555
+ ; CHECK-NEXT: [[AND:%.*]] = and <4 x i32> [[SHL]], [[A:%.*]]
556
+ ; CHECK-NEXT: [[CMP:%.*]] = icmp eq <4 x i32> [[AND]], zeroinitializer
557
+ ; CHECK-NEXT: [[Z:%.*]] = zext <4 x i1> [[CMP]] to <4 x i64>
558
+ ; CHECK-NEXT: ret <4 x i64> [[Z]]
559
+ ;
560
+ %shl = shl <4 x i32 > <i32 1 , i32 1 , i32 1 , i32 1 >, %b
561
+ %and = and <4 x i32 > %shl , %a
562
+ %cmp = icmp eq <4 x i32 > %and , <i32 0 , i32 0 , i32 0 , i32 0 >
563
+ %z = zext <4 x i1 > %cmp to <4 x i64 >
564
+ ret <4 x i64 > %z
565
+ }
566
+
457
567
define i32 @notneg_zext_wider (i8 %x ) {
458
568
; CHECK-LABEL: @notneg_zext_wider(
459
569
; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[X:%.*]], -1
0 commit comments