@@ -466,6 +466,34 @@ define i32 @shl_sub_lshr(i32 %x, i32 %c, i32 %y) {
466
466
ret i32 %lshr
467
467
}
468
468
469
+ define i32 @shl_sub_lshr_reverse (i32 %x , i32 %c , i32 %y ) {
470
+ ; CHECK-LABEL: @shl_sub_lshr_reverse(
471
+ ; CHECK-NEXT: [[SHL:%.*]] = shl nuw i32 [[X:%.*]], [[C:%.*]]
472
+ ; CHECK-NEXT: [[SUB:%.*]] = sub nuw nsw i32 [[Y:%.*]], [[SHL]]
473
+ ; CHECK-NEXT: [[LSHR:%.*]] = lshr exact i32 [[SUB]], [[C]]
474
+ ; CHECK-NEXT: ret i32 [[LSHR]]
475
+ ;
476
+ %shl = shl nuw i32 %x , %c
477
+ %sub = sub nuw nsw i32 %y , %shl
478
+ %lshr = lshr exact i32 %sub , %c
479
+ ret i32 %lshr
480
+ }
481
+
482
+ ; Negative test
483
+
484
+ define i32 @shl_sub_lshr_reverse_no_exact (i32 %x , i32 %c , i32 %y ) {
485
+ ; CHECK-LABEL: @shl_sub_lshr_reverse_no_exact(
486
+ ; CHECK-NEXT: [[SHL:%.*]] = shl nuw i32 [[X:%.*]], [[C:%.*]]
487
+ ; CHECK-NEXT: [[SUB:%.*]] = sub nuw nsw i32 [[Y:%.*]], [[SHL]]
488
+ ; CHECK-NEXT: [[LSHR:%.*]] = lshr i32 [[SUB]], [[C]]
489
+ ; CHECK-NEXT: ret i32 [[LSHR]]
490
+ ;
491
+ %shl = shl nuw i32 %x , %c
492
+ %sub = sub nuw nsw i32 %y , %shl
493
+ %lshr = lshr i32 %sub , %c
494
+ ret i32 %lshr
495
+ }
496
+
469
497
define i32 @shl_or_lshr (i32 %x , i32 %c , i32 %y ) {
470
498
; CHECK-LABEL: @shl_or_lshr(
471
499
; CHECK-NEXT: [[TMP1:%.*]] = lshr i32 [[Y:%.*]], [[C:%.*]]
0 commit comments