[llvm] 57f4dcf - [InstCombine] Add sub(add(x,y),minmax(x,y)) -> maxmin(x,y) tests
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 8 09:03:32 PDT 2022
Author: Simon Pilgrim
Date: 2022-04-08T17:03:12+01:00
New Revision: 57f4dcfe154fb55eebab3039ab9e4b62ab959a31
URL: https://github.com/llvm/llvm-project/commit/57f4dcfe154fb55eebab3039ab9e4b62ab959a31
DIFF: https://github.com/llvm/llvm-project/commit/57f4dcfe154fb55eebab3039ab9e4b62ab959a31.diff
LOG: [InstCombine] Add sub(add(x,y),minmax(x,y)) -> maxmin(x,y) tests
Based on Issue #37628
Added:
Modified:
llvm/test/Transforms/InstCombine/sub-minmax.ll
Removed:
################################################################################
diff --git a/llvm/test/Transforms/InstCombine/sub-minmax.ll b/llvm/test/Transforms/InstCombine/sub-minmax.ll
index 2deca35cdc9ff..4430c7a8f0010 100644
--- a/llvm/test/Transforms/InstCombine/sub-minmax.ll
+++ b/llvm/test/Transforms/InstCombine/sub-minmax.ll
@@ -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)
More information about the llvm-commits
mailing list