[llvm] 8ef0532 - [InstCombine] add tests for sub of smin/smax; NFC
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 4 16:57:21 PDT 2022
Author: Sanjay Patel
Date: 2022-07-04T18:46:40-04:00
New Revision: 8ef053273abf2ae3ae05801808908af9dd7887c3
URL: https://github.com/llvm/llvm-project/commit/8ef053273abf2ae3ae05801808908af9dd7887c3
DIFF: https://github.com/llvm/llvm-project/commit/8ef053273abf2ae3ae05801808908af9dd7887c3.diff
LOG: [InstCombine] add tests for sub of smin/smax; NFC
issue #55470
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 fa762987c6b9..0191ebe9daec 100644
--- a/llvm/test/Transforms/InstCombine/sub-minmax.ll
+++ b/llvm/test/Transforms/InstCombine/sub-minmax.ll
@@ -2,6 +2,8 @@
; RUN: opt < %s -passes=instcombine -S | FileCheck %s
declare i5 @llvm.umin.i5(i5, i5)
+declare <2 x i8> @llvm.smin.v2i8(<2 x i8>, <2 x i8>)
+declare <2 x i8> @llvm.smax.v2i8(<2 x i8>, <2 x i8>)
declare <2 x i8> @llvm.umin.v2i8(<2 x i8>, <2 x i8>)
declare <2 x i8> @llvm.umax.v2i8(<2 x i8>, <2 x i8>)
@@ -877,5 +879,121 @@ define i8 @sub_add_umin_use_m(i8 %x, i8 %y, i8 %z) {
ret i8 %s
}
+define <2 x i8> @sub_smax0_sub_nsw(<2 x i8> %x, <2 x i8> %y) {
+; CHECK-LABEL: define {{[^@]+}}@sub_smax0_sub_nsw
+; CHECK-SAME: (<2 x i8> [[X:%.*]], <2 x i8> [[Y:%.*]]) {
+; CHECK-NEXT: [[SUB:%.*]] = sub nsw <2 x i8> [[X]], [[Y]]
+; CHECK-NEXT: [[M:%.*]] = call <2 x i8> @llvm.smax.v2i8(<2 x i8> [[SUB]], <2 x i8> <i8 0, i8 poison>)
+; CHECK-NEXT: [[R:%.*]] = sub <2 x i8> [[X]], [[M]]
+; CHECK-NEXT: ret <2 x i8> [[R]]
+;
+ %sub = sub nsw <2 x i8> %x, %y
+ %m = call <2 x i8> @llvm.smax.v2i8(<2 x i8> %sub, <2 x i8> <i8 0, i8 poison>)
+ %r = sub <2 x i8> %x, %m
+ ret <2 x i8> %r
+}
+
+define i8 @sub_smax0_sub_nsw_use(i8 %x, i8 %y) {
+; CHECK-LABEL: define {{[^@]+}}@sub_smax0_sub_nsw_use
+; CHECK-SAME: (i8 [[X:%.*]], i8 [[Y:%.*]]) {
+; CHECK-NEXT: [[SUB:%.*]] = sub nsw i8 [[X]], [[Y]]
+; CHECK-NEXT: [[M:%.*]] = call i8 @llvm.smax.i8(i8 [[SUB]], i8 0)
+; CHECK-NEXT: call void @use8(i8 [[M]])
+; CHECK-NEXT: [[R:%.*]] = sub i8 [[X]], [[M]]
+; CHECK-NEXT: ret i8 [[R]]
+;
+ %sub = sub nsw i8 %x, %y
+ %m = call i8 @llvm.smax.i8(i8 %sub, i8 0)
+ call void @use8(i8 %m)
+ %r = sub i8 %x, %m
+ ret i8 %r
+}
+
+define i8 @sub_smax0_sub(i8 %x, i8 %y) {
+; CHECK-LABEL: define {{[^@]+}}@sub_smax0_sub
+; CHECK-SAME: (i8 [[X:%.*]], i8 [[Y:%.*]]) {
+; CHECK-NEXT: [[SUB:%.*]] = sub i8 [[X]], [[Y]]
+; CHECK-NEXT: [[M:%.*]] = call i8 @llvm.smax.i8(i8 [[SUB]], i8 0)
+; CHECK-NEXT: [[R:%.*]] = sub i8 [[X]], [[M]]
+; CHECK-NEXT: ret i8 [[R]]
+;
+ %sub = sub i8 %x, %y
+ %m = call i8 @llvm.smax.i8(i8 %sub, i8 0)
+ %r = sub i8 %x, %m
+ ret i8 %r
+}
+
+define i8 @sub_smax0_sub_commute(i8 %x, i8 %y) {
+; CHECK-LABEL: define {{[^@]+}}@sub_smax0_sub_commute
+; CHECK-SAME: (i8 [[X:%.*]], i8 [[Y:%.*]]) {
+; CHECK-NEXT: [[SUB:%.*]] = sub i8 [[X]], [[Y]]
+; CHECK-NEXT: [[M:%.*]] = call i8 @llvm.smax.i8(i8 [[SUB]], i8 0)
+; CHECK-NEXT: [[R:%.*]] = sub i8 [[M]], [[X]]
+; CHECK-NEXT: ret i8 [[R]]
+;
+ %sub = sub i8 %x, %y
+ %m = call i8 @llvm.smax.i8(i8 %sub, i8 0)
+ %r = sub i8 %m, %x
+ ret i8 %r
+}
+
+define i8 @sub_smin0_sub_nsw_use(i8 %x, i8 %y) {
+; CHECK-LABEL: define {{[^@]+}}@sub_smin0_sub_nsw_use
+; CHECK-SAME: (i8 [[X:%.*]], i8 [[Y:%.*]]) {
+; CHECK-NEXT: [[SUB:%.*]] = sub nsw i8 [[X]], [[Y]]
+; CHECK-NEXT: call void @use8(i8 [[SUB]])
+; CHECK-NEXT: [[M:%.*]] = call i8 @llvm.smin.i8(i8 [[SUB]], i8 0)
+; CHECK-NEXT: [[R:%.*]] = sub i8 [[X]], [[M]]
+; CHECK-NEXT: ret i8 [[R]]
+;
+ %sub = sub nsw i8 %x, %y
+ call void @use8(i8 %sub)
+ %m = call i8 @llvm.smin.i8(i8 %sub, i8 0)
+ %r = sub i8 %x, %m
+ ret i8 %r
+}
+
+define <2 x i8> @sub_smin0_sub_nsw(<2 x i8> %x, <2 x i8> %y) {
+; CHECK-LABEL: define {{[^@]+}}@sub_smin0_sub_nsw
+; CHECK-SAME: (<2 x i8> [[X:%.*]], <2 x i8> [[Y:%.*]]) {
+; CHECK-NEXT: [[SUB:%.*]] = sub nsw <2 x i8> [[X]], [[Y]]
+; CHECK-NEXT: [[M:%.*]] = call <2 x i8> @llvm.smin.v2i8(<2 x i8> [[SUB]], <2 x i8> zeroinitializer)
+; CHECK-NEXT: [[R:%.*]] = sub <2 x i8> [[X]], [[M]]
+; CHECK-NEXT: ret <2 x i8> [[R]]
+;
+ %sub = sub nsw <2 x i8> %x, %y
+ %m = call <2 x i8> @llvm.smin.v2i8(<2 x i8> %sub, <2 x i8> zeroinitializer)
+ %r = sub <2 x i8> %x, %m
+ ret <2 x i8> %r
+}
+
+define i8 @sub_smin0_sub(i8 %x, i8 %y) {
+; CHECK-LABEL: define {{[^@]+}}@sub_smin0_sub
+; CHECK-SAME: (i8 [[X:%.*]], i8 [[Y:%.*]]) {
+; CHECK-NEXT: [[SUB:%.*]] = sub i8 [[X]], [[Y]]
+; CHECK-NEXT: [[M:%.*]] = call i8 @llvm.smin.i8(i8 [[SUB]], i8 0)
+; CHECK-NEXT: [[R:%.*]] = sub i8 [[X]], [[M]]
+; CHECK-NEXT: ret i8 [[R]]
+;
+ %sub = sub i8 %x, %y
+ %m = call i8 @llvm.smin.i8(i8 %sub, i8 0)
+ %r = sub i8 %x, %m
+ ret i8 %r
+}
+
+define i8 @sub_smin0_sub_nsw_commute(i8 %x, i8 %y) {
+; CHECK-LABEL: define {{[^@]+}}@sub_smin0_sub_nsw_commute
+; CHECK-SAME: (i8 [[X:%.*]], i8 [[Y:%.*]]) {
+; CHECK-NEXT: [[SUB:%.*]] = sub nsw i8 [[Y]], [[X]]
+; CHECK-NEXT: [[M:%.*]] = call i8 @llvm.smin.i8(i8 [[SUB]], i8 0)
+; CHECK-NEXT: [[R:%.*]] = sub i8 [[X]], [[M]]
+; CHECK-NEXT: ret i8 [[R]]
+;
+ %sub = sub nsw i8 %y, %x
+ %m = call i8 @llvm.smin.i8(i8 %sub, i8 0)
+ %r = sub i8 %x, %m
+ ret i8 %r
+}
+
declare void @use8(i8)
declare void @use32(i32 %u)
More information about the llvm-commits
mailing list