Skip to content

Commit 8e0fbcd

Browse files
committed
[InstCombine] Pre-commit tests (NFC)
1 parent f639b57 commit 8e0fbcd

File tree

1 file changed

+116
-0
lines changed
  • llvm/test/Transforms/InstCombine

1 file changed

+116
-0
lines changed

llvm/test/Transforms/InstCombine/lshr.ll

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,122 @@ define i32 @shl_sub_lshr(i32 %x, i32 %c, i32 %y) {
466466
ret i32 %lshr
467467
}
468468

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

0 commit comments

Comments
 (0)