[llvm] 8f3ff1b - Precommit tests for max(a, b) nsw/nuw - min(a, b) --> abs(a - b); NFC
Jun Zhang via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 7 19:25:03 PST 2023
Author: Jun Zhang
Date: 2023-03-08T11:22:06+08:00
New Revision: 8f3ff1b88b50faa323edf3ceda7c9233cf068df0
URL: https://github.com/llvm/llvm-project/commit/8f3ff1b88b50faa323edf3ceda7c9233cf068df0
DIFF: https://github.com/llvm/llvm-project/commit/8f3ff1b88b50faa323edf3ceda7c9233cf068df0.diff
LOG: Precommit tests for max(a,b) nsw/nuw - min(a,b) --> abs(a - b); NFC
Signed-off-by: Jun Zhang <jun at junz.org>
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 79396ca099831..41e1270118529 100644
--- a/llvm/test/Transforms/InstCombine/sub-minmax.ll
+++ b/llvm/test/Transforms/InstCombine/sub-minmax.ll
@@ -998,5 +998,61 @@ define i8 @sub_smin0_sub_nsw_commute(i8 %x, i8 %y) {
ret i8 %r
}
+define i8 @sub_max_min_nsw(i8 %a, i8 %b) {
+; CHECK-LABEL: define {{[^@]+}}@sub_max_min_nsw
+; CHECK-SAME: (i8 [[A:%.*]], i8 [[B:%.*]]) {
+; CHECK-NEXT: [[MIN:%.*]] = call i8 @llvm.smin.i8(i8 [[A]], i8 [[B]])
+; CHECK-NEXT: [[MAX:%.*]] = call i8 @llvm.smax.i8(i8 [[A]], i8 [[B]])
+; CHECK-NEXT: [[AB:%.*]] = sub nsw i8 [[MAX]], [[MIN]]
+; CHECK-NEXT: ret i8 [[AB]]
+;
+ %min = call i8 @llvm.smin.i8(i8 %a, i8 %b)
+ %max = call i8 @llvm.smax.i8(i8 %a, i8 %b)
+ %ab = sub nsw i8 %max, %min
+ ret i8 %ab
+}
+
+define i8 @sub_max_min_nuw(i8 %a, i8 %b) {
+; CHECK-LABEL: define {{[^@]+}}@sub_max_min_nuw
+; CHECK-SAME: (i8 [[A:%.*]], i8 [[B:%.*]]) {
+; CHECK-NEXT: [[MIN:%.*]] = call i8 @llvm.smin.i8(i8 [[A]], i8 [[B]])
+; CHECK-NEXT: [[MAX:%.*]] = call i8 @llvm.smax.i8(i8 [[A]], i8 [[B]])
+; CHECK-NEXT: [[AB:%.*]] = sub nuw i8 [[MAX]], [[MIN]]
+; CHECK-NEXT: ret i8 [[AB]]
+;
+ %min = call i8 @llvm.smin.i8(i8 %a, i8 %b)
+ %max = call i8 @llvm.smax.i8(i8 %a, i8 %b)
+ %ab = sub nuw i8 %max, %min
+ ret i8 %ab
+}
+
+define <2 x i8> @sub_max_min_vec_nsw(<2 x i8> %a, <2 x i8> %b) {
+; CHECK-LABEL: define {{[^@]+}}@sub_max_min_vec_nsw
+; CHECK-SAME: (<2 x i8> [[A:%.*]], <2 x i8> [[B:%.*]]) {
+; CHECK-NEXT: [[MIN:%.*]] = call <2 x i8> @llvm.smin.v2i8(<2 x i8> [[A]], <2 x i8> [[B]])
+; CHECK-NEXT: [[MAX:%.*]] = call <2 x i8> @llvm.smax.v2i8(<2 x i8> [[A]], <2 x i8> [[B]])
+; CHECK-NEXT: [[AB:%.*]] = sub nsw <2 x i8> [[MAX]], [[MIN]]
+; CHECK-NEXT: ret <2 x i8> [[AB]]
+;
+ %min = call <2 x i8> @llvm.smin.v2i8(<2 x i8> %a, <2 x i8> %b)
+ %max = call <2 x i8> @llvm.smax.v2i8(<2 x i8> %a, <2 x i8> %b)
+ %ab = sub nsw <2 x i8> %max, %min
+ ret <2 x i8> %ab
+}
+
+define <2 x i8> @sub_max_min_vec_nuw(<2 x i8> %a, <2 x i8> %b) {
+; CHECK-LABEL: define {{[^@]+}}@sub_max_min_vec_nuw
+; CHECK-SAME: (<2 x i8> [[A:%.*]], <2 x i8> [[B:%.*]]) {
+; CHECK-NEXT: [[MIN:%.*]] = call <2 x i8> @llvm.smin.v2i8(<2 x i8> [[A]], <2 x i8> [[B]])
+; CHECK-NEXT: [[MAX:%.*]] = call <2 x i8> @llvm.smax.v2i8(<2 x i8> [[A]], <2 x i8> [[B]])
+; CHECK-NEXT: [[AB:%.*]] = sub nuw <2 x i8> [[MAX]], [[MIN]]
+; CHECK-NEXT: ret <2 x i8> [[AB]]
+;
+ %min = call <2 x i8> @llvm.smin.v2i8(<2 x i8> %a, <2 x i8> %b)
+ %max = call <2 x i8> @llvm.smax.v2i8(<2 x i8> %a, <2 x i8> %b)
+ %ab = sub nuw <2 x i8> %max, %min
+ ret <2 x i8> %ab
+}
+
declare void @use8(i8)
declare void @use32(i32 %u)
More information about the llvm-commits
mailing list