[InstCombine] add tests for min/max intrinsics with offset operand; NFC

This commit is contained in:
Sanjay Patel 2021-09-17 14:47:49 -04:00
parent 46e77b5d10
commit 6da3503602
1 changed files with 216 additions and 0 deletions

View File

@ -1866,3 +1866,219 @@ define void @cmyk_commute11(i8 %r, i8 %g, i8 %b) {
call void @use4(i8 %ck, i8 %mk, i8 %yk, i8 %k)
ret void
}
define i8 @smax_offset(i8 %x) {
; CHECK-LABEL: @smax_offset(
; CHECK-NEXT: [[A:%.*]] = add nsw i8 [[X:%.*]], 3
; CHECK-NEXT: [[M:%.*]] = call i8 @llvm.smax.i8(i8 [[A]], i8 -124)
; CHECK-NEXT: ret i8 [[M]]
;
%a = add nsw i8 %x, 3
%m = call i8 @llvm.smax.i8(i8 %a, i8 -124)
ret i8 %m
}
define i8 @smax_offset_limit(i8 %x) {
; CHECK-LABEL: @smax_offset_limit(
; CHECK-NEXT: [[A:%.*]] = add nsw i8 [[X:%.*]], 3
; CHECK-NEXT: ret i8 [[A]]
;
%a = add nsw i8 %x, 3
%m = call i8 @llvm.smax.i8(i8 %a, i8 -125)
ret i8 %m
}
define i8 @smax_offset_overflow(i8 %x) {
; CHECK-LABEL: @smax_offset_overflow(
; CHECK-NEXT: [[A:%.*]] = add nsw i8 [[X:%.*]], 3
; CHECK-NEXT: ret i8 [[A]]
;
%a = add nsw i8 %x, 3
%m = call i8 @llvm.smax.i8(i8 %a, i8 -126)
ret i8 %m
}
define i8 @smax_offset_may_wrap(i8 %x) {
; CHECK-LABEL: @smax_offset_may_wrap(
; CHECK-NEXT: [[A:%.*]] = add i8 [[X:%.*]], 3
; CHECK-NEXT: [[M:%.*]] = call i8 @llvm.smax.i8(i8 [[A]], i8 -124)
; CHECK-NEXT: ret i8 [[M]]
;
%a = add i8 %x, 3
%m = call i8 @llvm.smax.i8(i8 %a, i8 -124)
ret i8 %m
}
define i8 @smax_offset_uses(i8 %x) {
; CHECK-LABEL: @smax_offset_uses(
; CHECK-NEXT: [[A:%.*]] = add nsw i8 [[X:%.*]], 3
; CHECK-NEXT: call void @use(i8 [[A]])
; CHECK-NEXT: [[M:%.*]] = call i8 @llvm.smax.i8(i8 [[A]], i8 -124)
; CHECK-NEXT: ret i8 [[M]]
;
%a = add nsw i8 %x, 3
call void @use(i8 %a)
%m = call i8 @llvm.smax.i8(i8 %a, i8 -124)
ret i8 %m
}
define <3 x i8> @smin_offset(<3 x i8> %x) {
; CHECK-LABEL: @smin_offset(
; CHECK-NEXT: [[A:%.*]] = add nsw <3 x i8> [[X:%.*]], <i8 124, i8 124, i8 124>
; CHECK-NEXT: [[M:%.*]] = call <3 x i8> @llvm.smin.v3i8(<3 x i8> [[A]], <3 x i8> <i8 -3, i8 -3, i8 -3>)
; CHECK-NEXT: ret <3 x i8> [[M]]
;
%a = add nsw <3 x i8> %x, <i8 124, i8 124, i8 124>
%m = call <3 x i8> @llvm.smin.v3i8(<3 x i8> %a, <3 x i8> <i8 -3, i8 -3, i8 -3>)
ret <3 x i8> %m
}
define i8 @smin_offset_limit(i8 %x) {
; CHECK-LABEL: @smin_offset_limit(
; CHECK-NEXT: ret i8 -3
;
%a = add nsw i8 %x, 125
%m = call i8 @llvm.smin.i8(i8 %a, i8 -3)
ret i8 %m
}
define i8 @smin_offset_overflow(i8 %x) {
; CHECK-LABEL: @smin_offset_overflow(
; CHECK-NEXT: ret i8 -3
;
%a = add nsw i8 %x, 126
%m = call i8 @llvm.smin.i8(i8 %a, i8 -3)
ret i8 %m
}
define i8 @smin_offset_may_wrap(i8 %x) {
; CHECK-LABEL: @smin_offset_may_wrap(
; CHECK-NEXT: [[A:%.*]] = add nuw i8 [[X:%.*]], 124
; CHECK-NEXT: [[M:%.*]] = call i8 @llvm.smin.i8(i8 [[A]], i8 -3)
; CHECK-NEXT: ret i8 [[M]]
;
%a = add nuw i8 %x, 124
%m = call i8 @llvm.smin.i8(i8 %a, i8 -3)
ret i8 %m
}
define i8 @smin_offset_uses(i8 %x) {
; CHECK-LABEL: @smin_offset_uses(
; CHECK-NEXT: [[A:%.*]] = add nsw i8 [[X:%.*]], 124
; CHECK-NEXT: call void @use(i8 [[A]])
; CHECK-NEXT: [[M:%.*]] = call i8 @llvm.smin.i8(i8 [[A]], i8 -3)
; CHECK-NEXT: ret i8 [[M]]
;
%a = add nsw i8 %x, 124
call void @use(i8 %a)
%m = call i8 @llvm.smin.i8(i8 %a, i8 -3)
ret i8 %m
}
define <3 x i8> @umax_offset(<3 x i8> %x) {
; CHECK-LABEL: @umax_offset(
; CHECK-NEXT: [[A:%.*]] = add nuw <3 x i8> [[X:%.*]], <i8 3, i8 3, i8 3>
; CHECK-NEXT: [[M:%.*]] = call <3 x i8> @llvm.umax.v3i8(<3 x i8> [[A]], <3 x i8> <i8 4, i8 4, i8 4>)
; CHECK-NEXT: ret <3 x i8> [[M]]
;
%a = add nuw <3 x i8> %x, <i8 3, i8 3, i8 3>
%m = call <3 x i8> @llvm.umax.v3i8(<3 x i8> %a, <3 x i8> <i8 4, i8 4, i8 4>)
ret <3 x i8> %m
}
define i8 @umax_offset_limit(i8 %x) {
; CHECK-LABEL: @umax_offset_limit(
; CHECK-NEXT: [[A:%.*]] = add nuw i8 [[X:%.*]], 3
; CHECK-NEXT: ret i8 [[A]]
;
%a = add nuw i8 %x, 3
%m = call i8 @llvm.umax.i8(i8 %a, i8 3)
ret i8 %m
}
define i8 @umax_offset_overflow(i8 %x) {
; CHECK-LABEL: @umax_offset_overflow(
; CHECK-NEXT: [[A:%.*]] = add nuw i8 [[X:%.*]], 3
; CHECK-NEXT: ret i8 [[A]]
;
%a = add nuw i8 %x, 3
%m = call i8 @llvm.umax.i8(i8 %a, i8 2)
ret i8 %m
}
define i8 @umax_offset_may_wrap(i8 %x) {
; CHECK-LABEL: @umax_offset_may_wrap(
; CHECK-NEXT: [[A:%.*]] = add i8 [[X:%.*]], 3
; CHECK-NEXT: [[M:%.*]] = call i8 @llvm.umax.i8(i8 [[A]], i8 4)
; CHECK-NEXT: ret i8 [[M]]
;
%a = add i8 %x, 3
%m = call i8 @llvm.umax.i8(i8 %a, i8 4)
ret i8 %m
}
define i8 @umax_offset_uses(i8 %x) {
; CHECK-LABEL: @umax_offset_uses(
; CHECK-NEXT: [[A:%.*]] = add nuw i8 [[X:%.*]], 3
; CHECK-NEXT: call void @use(i8 [[A]])
; CHECK-NEXT: [[M:%.*]] = call i8 @llvm.umax.i8(i8 [[A]], i8 4)
; CHECK-NEXT: ret i8 [[M]]
;
%a = add nuw i8 %x, 3
call void @use(i8 %a)
%m = call i8 @llvm.umax.i8(i8 %a, i8 4)
ret i8 %m
}
define i8 @umin_offset(i8 %x) {
; CHECK-LABEL: @umin_offset(
; CHECK-NEXT: [[A:%.*]] = add nuw i8 [[X:%.*]], -5
; CHECK-NEXT: [[M:%.*]] = call i8 @llvm.umin.i8(i8 [[A]], i8 -4)
; CHECK-NEXT: ret i8 [[M]]
;
%a = add nuw i8 %x, 251
%m = call i8 @llvm.umin.i8(i8 %a, i8 252)
ret i8 %m
}
define i8 @umin_offset_limit(i8 %x) {
; CHECK-LABEL: @umin_offset_limit(
; CHECK-NEXT: ret i8 -4
;
%a = add nuw i8 %x, 252
%m = call i8 @llvm.umin.i8(i8 %a, i8 252)
ret i8 %m
}
define i8 @umin_offset_overflow(i8 %x) {
; CHECK-LABEL: @umin_offset_overflow(
; CHECK-NEXT: ret i8 -4
;
%a = add nuw i8 %x, 253
%m = call i8 @llvm.umin.i8(i8 %a, i8 252)
ret i8 %m
}
define i8 @umin_offset_may_wrap(i8 %x) {
; CHECK-LABEL: @umin_offset_may_wrap(
; CHECK-NEXT: [[A:%.*]] = add nsw i8 [[X:%.*]], -5
; CHECK-NEXT: [[M:%.*]] = call i8 @llvm.umin.i8(i8 [[A]], i8 -4)
; CHECK-NEXT: ret i8 [[M]]
;
%a = add nsw i8 %x, 251
%m = call i8 @llvm.umin.i8(i8 %a, i8 252)
ret i8 %m
}
define i8 @umin_offset_uses(i8 %x) {
; CHECK-LABEL: @umin_offset_uses(
; CHECK-NEXT: [[A:%.*]] = add nuw i8 [[X:%.*]], -5
; CHECK-NEXT: call void @use(i8 [[A]])
; CHECK-NEXT: [[M:%.*]] = call i8 @llvm.umin.i8(i8 [[A]], i8 -4)
; CHECK-NEXT: ret i8 [[M]]
;
%a = add nuw i8 %x, 251
call void @use(i8 %a)
%m = call i8 @llvm.umin.i8(i8 %a, i8 252)
ret i8 %m
}