@@ -464,6 +464,34 @@ 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
+ ; Negative test
481
+
482
+ define i32 @shl_sub_lshr_reverse_no_exact (i32 %x , i32 %c , i32 %y ) {
483
+ ; CHECK-LABEL: @shl_sub_lshr_reverse_no_exact(
484
+ ; CHECK-NEXT: [[SHL:%.*]] = shl nuw i32 [[X:%.*]], [[C:%.*]]
485
+ ; CHECK-NEXT: [[SUB:%.*]] = sub nuw nsw i32 [[Y:%.*]], [[SHL]]
486
+ ; CHECK-NEXT: [[LSHR:%.*]] = lshr i32 [[SUB]], [[C]]
487
+ ; CHECK-NEXT: ret i32 [[LSHR]]
488
+ ;
489
+ %shl = shl nuw i32 %x , %c
490
+ %sub = sub nuw nsw i32 %y , %shl
491
+ %lshr = lshr i32 %sub , %c
492
+ ret i32 %lshr
493
+ }
494
+
467
495
define i32 @shl_or_lshr (i32 %x , i32 %c , i32 %y ) {
468
496
; CHECK-LABEL: @shl_or_lshr(
469
497
; CHECK-NEXT: [[TMP1:%.*]] = lshr i32 [[Y:%.*]], [[C:%.*]]
0 commit comments