[InstCombine] Add sub(add(x,y),minmax(x,y)) -> maxmin(x,y) tests

Based on Issue #37628
This commit is contained in:
Simon Pilgrim 2022-04-08 16:55:44 +01:00
parent 5562d9b3c0
commit 57f4dcfe15
1 changed files with 121 additions and 0 deletions

View File

@ -621,5 +621,126 @@ define i8 @umin_sub_op0_use(i8 %x, i8 %y) {
ret i8 %r
}
;
; TODO: sub(add(X,Y), s/umin(X,Y)) --> s/umax(X,Y)
; TODO: sub(add(X,Y), s/umax(X,Y)) --> s/umin(X,Y)
;
define i8 @diff_add_smin(i8 %x, i8 %y) {
; CHECK-LABEL: @diff_add_smin(
; CHECK-NEXT: [[A:%.*]] = add i8 [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: [[M:%.*]] = call i8 @llvm.smin.i8(i8 [[X]], i8 [[Y]])
; CHECK-NEXT: [[S:%.*]] = sub i8 [[A]], [[M]]
; CHECK-NEXT: ret i8 [[S]]
;
%a = add i8 %x, %y
%m = call i8 @llvm.smin.i8(i8 %x, i8 %y)
%s = sub i8 %a, %m
ret i8 %s
}
define i8 @diff_add_smax(i8 %x, i8 %y) {
; CHECK-LABEL: @diff_add_smax(
; CHECK-NEXT: [[A:%.*]] = add i8 [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: [[M:%.*]] = call i8 @llvm.smax.i8(i8 [[Y]], i8 [[X]])
; CHECK-NEXT: [[S:%.*]] = sub i8 [[A]], [[M]]
; CHECK-NEXT: ret i8 [[S]]
;
%a = add i8 %x, %y
%m = call i8 @llvm.smax.i8(i8 %y, i8 %x)
%s = sub i8 %a, %m
ret i8 %s
}
define i8 @diff_add_umin(i8 %x, i8 %y) {
; CHECK-LABEL: @diff_add_umin(
; CHECK-NEXT: [[A:%.*]] = add i8 [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: [[M:%.*]] = call i8 @llvm.umin.i8(i8 [[X]], i8 [[Y]])
; CHECK-NEXT: [[S:%.*]] = sub i8 [[A]], [[M]]
; CHECK-NEXT: ret i8 [[S]]
;
%a = add i8 %x, %y
%m = call i8 @llvm.umin.i8(i8 %x, i8 %y)
%s = sub i8 %a, %m
ret i8 %s
}
define i8 @diff_add_umax(i8 %x, i8 %y) {
; CHECK-LABEL: @diff_add_umax(
; CHECK-NEXT: [[A:%.*]] = add i8 [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: [[M:%.*]] = call i8 @llvm.umax.i8(i8 [[Y]], i8 [[X]])
; CHECK-NEXT: [[S:%.*]] = sub i8 [[A]], [[M]]
; CHECK-NEXT: ret i8 [[S]]
;
%a = add i8 %x, %y
%m = call i8 @llvm.umax.i8(i8 %y, i8 %x)
%s = sub i8 %a, %m
ret i8 %s
}
define i8 @diff_add_smin_use(i8 %x, i8 %y) {
; CHECK-LABEL: @diff_add_smin_use(
; CHECK-NEXT: [[A:%.*]] = add i8 [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: [[M:%.*]] = call i8 @llvm.smin.i8(i8 [[X]], i8 [[Y]])
; CHECK-NEXT: [[S:%.*]] = sub i8 [[A]], [[M]]
; CHECK-NEXT: call void @use8(i8 [[M]])
; CHECK-NEXT: ret i8 [[S]]
;
%a = add i8 %x, %y
%m = call i8 @llvm.smin.i8(i8 %x, i8 %y)
%s = sub i8 %a, %m
call void @use8(i8 %m)
ret i8 %s
}
define i8 @diff_add_use_smax(i8 %x, i8 %y) {
; CHECK-LABEL: @diff_add_use_smax(
; CHECK-NEXT: [[A:%.*]] = add i8 [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: [[M:%.*]] = call i8 @llvm.smax.i8(i8 [[Y]], i8 [[X]])
; CHECK-NEXT: [[S:%.*]] = sub i8 [[A]], [[M]]
; CHECK-NEXT: call void @use8(i8 [[A]])
; CHECK-NEXT: ret i8 [[S]]
;
%a = add i8 %x, %y
%m = call i8 @llvm.smax.i8(i8 %y, i8 %x)
%s = sub i8 %a, %m
call void @use8(i8 %a)
ret i8 %s
}
define i8 @diff_add_use_umin_use(i8 %x, i8 %y) {
; CHECK-LABEL: @diff_add_use_umin_use(
; CHECK-NEXT: [[A:%.*]] = add i8 [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: [[M:%.*]] = call i8 @llvm.umin.i8(i8 [[X]], i8 [[Y]])
; CHECK-NEXT: [[S:%.*]] = sub i8 [[A]], [[M]]
; CHECK-NEXT: call void @use8(i8 [[A]])
; CHECK-NEXT: call void @use8(i8 [[M]])
; CHECK-NEXT: ret i8 [[S]]
;
%a = add i8 %x, %y
%m = call i8 @llvm.umin.i8(i8 %x, i8 %y)
%s = sub i8 %a, %m
call void @use8(i8 %a)
call void @use8(i8 %m)
ret i8 %s
}
;
; TODO: sub(add(X,Y),umin(Y,Z)) --> add(X,usubsat(Y,Z))
;
define i8 @sub_add_umin(i8 %x, i8 %y, i8 %z) {
; CHECK-LABEL: @sub_add_umin(
; CHECK-NEXT: [[A:%.*]] = add i8 [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: [[M:%.*]] = call i8 @llvm.umin.i8(i8 [[Y]], i8 [[Z:%.*]])
; CHECK-NEXT: [[S:%.*]] = sub i8 [[A]], [[M]]
; CHECK-NEXT: ret i8 [[S]]
;
%a = add i8 %x, %y
%m = call i8 @llvm.umin.i8(i8 %y, i8 %z)
%s = sub i8 %a, %m
ret i8 %s
}
declare void @use8(i8)
declare void @use32(i32 %u)