@@ -464,6 +464,122 @@ define i32 @shl_sub_lshr(i32 %x, i32 %c, i32 %y) {
464
464
ret i32 %lshr
465
465
}
466
466
467
+ define i32 @shl_sub_lshr_reverse (i32 %x , i32 %c , i32 %y ) {
468
+ ; CHECK-LABEL: @shl_sub_lshr_reverse(
469
+ ; CHECK-NEXT: [[SHL:%.*]] = shl nuw i32 [[X:%.*]], [[C:%.*]]
470
+ ; CHECK-NEXT: [[SUB:%.*]] = sub nuw nsw i32 [[Y:%.*]], [[SHL]]
471
+ ; CHECK-NEXT: [[LSHR:%.*]] = lshr exact i32 [[SUB]], [[C]]
472
+ ; CHECK-NEXT: ret i32 [[LSHR]]
473
+ ;
474
+ %shl = shl nuw i32 %x , %c
475
+ %sub = sub nuw nsw i32 %y , %shl
476
+ %lshr = lshr exact i32 %sub , %c
477
+ ret i32 %lshr
478
+ }
479
+
480
+ define i32 @shl_sub_lshr_reverse_no_nsw (i32 %x , i32 %c , i32 %y ) {
481
+ ; CHECK-LABEL: @shl_sub_lshr_reverse_no_nsw(
482
+ ; CHECK-NEXT: [[SHL:%.*]] = shl nuw i32 [[X:%.*]], [[C:%.*]]
483
+ ; CHECK-NEXT: [[SUB:%.*]] = sub nuw i32 [[Y:%.*]], [[SHL]]
484
+ ; CHECK-NEXT: [[LSHR:%.*]] = lshr exact i32 [[SUB]], [[C]]
485
+ ; CHECK-NEXT: ret i32 [[LSHR]]
486
+ ;
487
+ %shl = shl nuw i32 %x , %c
488
+ %sub = sub nuw i32 %y , %shl
489
+ %lshr = lshr exact i32 %sub , %c
490
+ ret i32 %lshr
491
+ }
492
+
493
+ define i32 @shl_sub_lshr_reverse_nsw_on_op1 (i32 %x , i32 %c , i32 %y ) {
494
+ ; CHECK-LABEL: @shl_sub_lshr_reverse_nsw_on_op1(
495
+ ; CHECK-NEXT: [[SHL:%.*]] = shl nuw nsw i32 [[X:%.*]], [[C:%.*]]
496
+ ; CHECK-NEXT: [[SUB:%.*]] = sub nuw i32 [[Y:%.*]], [[SHL]]
497
+ ; CHECK-NEXT: [[LSHR:%.*]] = lshr exact i32 [[SUB]], [[C]]
498
+ ; CHECK-NEXT: ret i32 [[LSHR]]
499
+ ;
500
+ %shl = shl nuw nsw i32 %x , %c
501
+ %sub = sub nuw i32 %y , %shl
502
+ %lshr = lshr exact i32 %sub , %c
503
+ ret i32 %lshr
504
+ }
505
+
506
+ ; Negative test
507
+
508
+ define i32 @shl_sub_lshr_reverse_no_exact (i32 %x , i32 %c , i32 %y ) {
509
+ ; CHECK-LABEL: @shl_sub_lshr_reverse_no_exact(
510
+ ; CHECK-NEXT: [[SHL:%.*]] = shl nuw i32 [[X:%.*]], [[C:%.*]]
511
+ ; CHECK-NEXT: [[SUB:%.*]] = sub nuw nsw i32 [[Y:%.*]], [[SHL]]
512
+ ; CHECK-NEXT: [[LSHR:%.*]] = lshr i32 [[SUB]], [[C]]
513
+ ; CHECK-NEXT: ret i32 [[LSHR]]
514
+ ;
515
+ %shl = shl nuw i32 %x , %c
516
+ %sub = sub nuw nsw i32 %y , %shl
517
+ %lshr = lshr i32 %sub , %c
518
+ ret i32 %lshr
519
+ }
520
+
521
+ ; Negative test
522
+
523
+ define i32 @shl_sub_lshr_reverse_multiuse (i32 %x , i32 %c , i32 %y ) {
524
+ ; CHECK-LABEL: @shl_sub_lshr_reverse_multiuse(
525
+ ; CHECK-NEXT: [[SHL:%.*]] = shl nuw i32 [[X:%.*]], [[C:%.*]]
526
+ ; CHECK-NEXT: [[SUB:%.*]] = sub nuw i32 [[Y:%.*]], [[SHL]]
527
+ ; CHECK-NEXT: call void @use(i32 [[SUB]])
528
+ ; CHECK-NEXT: [[LSHR:%.*]] = lshr exact i32 [[SUB]], [[C]]
529
+ ; CHECK-NEXT: ret i32 [[LSHR]]
530
+ ;
531
+ %shl = shl nuw i32 %x , %c
532
+ %sub = sub nuw i32 %y , %shl
533
+ call void @use (i32 %sub )
534
+ %lshr = lshr exact i32 %sub , %c
535
+ ret i32 %lshr
536
+ }
537
+
538
+ define i32 @shl_sub_lshr_reverse_multiuse2 (i32 %x , i32 %c , i32 %y ) {
539
+ ; CHECK-LABEL: @shl_sub_lshr_reverse_multiuse2(
540
+ ; CHECK-NEXT: [[SHL:%.*]] = shl nuw i32 [[X:%.*]], [[C:%.*]]
541
+ ; CHECK-NEXT: call void @use(i32 [[SHL]])
542
+ ; CHECK-NEXT: [[SUB:%.*]] = sub nuw i32 [[Y:%.*]], [[SHL]]
543
+ ; CHECK-NEXT: [[LSHR:%.*]] = lshr exact i32 [[SUB]], [[C]]
544
+ ; CHECK-NEXT: ret i32 [[LSHR]]
545
+ ;
546
+ %shl = shl nuw i32 %x , %c
547
+ call void @use (i32 %shl )
548
+ %sub = sub nuw i32 %y , %shl
549
+ %lshr = lshr exact i32 %sub , %c
550
+ ret i32 %lshr
551
+ }
552
+
553
+ ; Negative test
554
+
555
+ define i32 @shl_sub_lshr_reverse_no_nuw (i32 %x , i32 %c , i32 %y ) {
556
+ ; CHECK-LABEL: @shl_sub_lshr_reverse_no_nuw(
557
+ ; CHECK-NEXT: [[SHL:%.*]] = shl i32 [[X:%.*]], [[C:%.*]]
558
+ ; CHECK-NEXT: [[SUB:%.*]] = sub nuw i32 [[Y:%.*]], [[SHL]]
559
+ ; CHECK-NEXT: [[LSHR:%.*]] = lshr exact i32 [[SUB]], [[C]]
560
+ ; CHECK-NEXT: ret i32 [[LSHR]]
561
+ ;
562
+ %shl = shl i32 %x , %c
563
+ %sub = sub nuw i32 %y , %shl
564
+ %lshr = lshr exact i32 %sub , %c
565
+ ret i32 %lshr
566
+ }
567
+
568
+ ; Negative test
569
+
570
+ define i32 @shl_sub_lshr_reverse_no_nsw_2 (i32 %x , i32 %c , i32 %y ) {
571
+ ; CHECK-LABEL: @shl_sub_lshr_reverse_no_nsw_2(
572
+ ; CHECK-NEXT: [[SHL:%.*]] = shl nuw nsw i32 [[X:%.*]], [[C:%.*]]
573
+ ; CHECK-NEXT: [[SUB:%.*]] = sub i32 [[Y:%.*]], [[SHL]]
574
+ ; CHECK-NEXT: [[LSHR:%.*]] = lshr exact i32 [[SUB]], [[C]]
575
+ ; CHECK-NEXT: ret i32 [[LSHR]]
576
+ ;
577
+ %shl = shl nuw nsw i32 %x , %c
578
+ %sub = sub i32 %y , %shl
579
+ %lshr = lshr exact i32 %sub , %c
580
+ ret i32 %lshr
581
+ }
582
+
467
583
define i32 @shl_or_lshr (i32 %x , i32 %c , i32 %y ) {
468
584
; CHECK-LABEL: @shl_or_lshr(
469
585
; CHECK-NEXT: [[TMP1:%.*]] = lshr i32 [[Y:%.*]], [[C:%.*]]
0 commit comments