[llvm] 1b5a195 - [InstCombine] add tests for factorization of min/max intrinsics; NFC
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 12 08:25:13 PDT 2021
Author: Sanjay Patel
Date: 2021-08-12T11:19:09-04:00
New Revision: 1b5a195845e1612ca0f76ee1b03f7e008e4912b8
URL: https://github.com/llvm/llvm-project/commit/1b5a195845e1612ca0f76ee1b03f7e008e4912b8
DIFF: https://github.com/llvm/llvm-project/commit/1b5a195845e1612ca0f76ee1b03f7e008e4912b8.diff
LOG: [InstCombine] add tests for factorization of min/max intrinsics; NFC
Added:
Modified:
llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
llvm/test/Transforms/InstCombine/minmax-intrinsics.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
index 01f8e60db7e78..ff94f39dc6906 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
@@ -1007,6 +1007,9 @@ Instruction *InstCombinerImpl::visitShl(BinaryOperator &I) {
return BinaryOperator::CreateAnd(Mask, X);
}
+ if (match(Op0, m_OneUse(m_Neg(m_Value(X)))))
+ return BinaryOperator::CreateNeg(Builder.CreateShl(X, Op1));
+
Constant *C1;
if (match(Op1, m_Constant(C1))) {
Constant *C2;
diff --git a/llvm/test/Transforms/InstCombine/minmax-intrinsics.ll b/llvm/test/Transforms/InstCombine/minmax-intrinsics.ll
index 963c2bc476665..faa95e8262284 100644
--- a/llvm/test/Transforms/InstCombine/minmax-intrinsics.ll
+++ b/llvm/test/Transforms/InstCombine/minmax-intrinsics.ll
@@ -904,3 +904,76 @@ define <3 x i1> @umin_ne_zero2(<3 x i8> %a, <3 x i8> %b) {
%res = icmp ne <3 x i8> %umin, zeroinitializer
ret <3 x i1> %res
}
+
+define i8 @smax(i8 %x, i8 %y, i8 %z) {
+; CHECK-LABEL: @smax(
+; CHECK-NEXT: [[M1:%.*]] = call i8 @llvm.smax.i8(i8 [[X:%.*]], i8 [[Y:%.*]])
+; CHECK-NEXT: [[M2:%.*]] = call i8 @llvm.smax.i8(i8 [[X]], i8 [[Z:%.*]])
+; CHECK-NEXT: [[M3:%.*]] = call i8 @llvm.smax.i8(i8 [[M1]], i8 [[M2]])
+; CHECK-NEXT: ret i8 [[M3]]
+;
+ %m1 = call i8 @llvm.smax.i8(i8 %x, i8 %y)
+ %m2 = call i8 @llvm.smax.i8(i8 %x, i8 %z)
+ %m3 = call i8 @llvm.smax.i8(i8 %m1, i8 %m2)
+ ret i8 %m3
+}
+
+define <3 x i8> @smin(<3 x i8> %x, <3 x i8> %y, <3 x i8> %z) {
+; CHECK-LABEL: @smin(
+; CHECK-NEXT: [[M1:%.*]] = call <3 x i8> @llvm.smin.v3i8(<3 x i8> [[Y:%.*]], <3 x i8> [[X:%.*]])
+; CHECK-NEXT: [[M2:%.*]] = call <3 x i8> @llvm.smin.v3i8(<3 x i8> [[X]], <3 x i8> [[Z:%.*]])
+; CHECK-NEXT: [[M3:%.*]] = call <3 x i8> @llvm.smin.v3i8(<3 x i8> [[M1]], <3 x i8> [[M2]])
+; CHECK-NEXT: ret <3 x i8> [[M3]]
+;
+ %m1 = call <3 x i8> @llvm.smin.v3i8(<3 x i8> %y, <3 x i8> %x)
+ %m2 = call <3 x i8> @llvm.smin.v3i8(<3 x i8> %x, <3 x i8> %z)
+ %m3 = call <3 x i8> @llvm.smin.v3i8(<3 x i8> %m1, <3 x i8> %m2)
+ ret <3 x i8> %m3
+}
+
+define i8 @umax(i8 %x, i8 %y, i8 %z) {
+; CHECK-LABEL: @umax(
+; CHECK-NEXT: [[M1:%.*]] = call i8 @llvm.umax.i8(i8 [[X:%.*]], i8 [[Y:%.*]])
+; CHECK-NEXT: call void @use(i8 [[M1]])
+; CHECK-NEXT: [[M2:%.*]] = call i8 @llvm.umax.i8(i8 [[Z:%.*]], i8 [[X]])
+; CHECK-NEXT: [[M3:%.*]] = call i8 @llvm.umax.i8(i8 [[M1]], i8 [[M2]])
+; CHECK-NEXT: ret i8 [[M3]]
+;
+ %m1 = call i8 @llvm.umax.i8(i8 %x, i8 %y)
+ call void @use(i8 %m1)
+ %m2 = call i8 @llvm.umax.i8(i8 %z, i8 %x)
+ %m3 = call i8 @llvm.umax.i8(i8 %m1, i8 %m2)
+ ret i8 %m3
+}
+
+define i8 @umin(i8 %x, i8 %y, i8 %z) {
+; CHECK-LABEL: @umin(
+; CHECK-NEXT: [[M1:%.*]] = call i8 @llvm.umin.i8(i8 [[Y:%.*]], i8 [[X:%.*]])
+; CHECK-NEXT: [[M2:%.*]] = call i8 @llvm.umin.i8(i8 [[Z:%.*]], i8 [[X]])
+; CHECK-NEXT: call void @use(i8 [[M2]])
+; CHECK-NEXT: [[M3:%.*]] = call i8 @llvm.umin.i8(i8 [[M1]], i8 [[M2]])
+; CHECK-NEXT: ret i8 [[M3]]
+;
+ %m1 = call i8 @llvm.umin.i8(i8 %y, i8 %x)
+ %m2 = call i8 @llvm.umin.i8(i8 %z, i8 %x)
+ call void @use(i8 %m2)
+ %m3 = call i8 @llvm.umin.i8(i8 %m1, i8 %m2)
+ ret i8 %m3
+}
+
+define i8 @smax_uses(i8 %x, i8 %y, i8 %z) {
+; CHECK-LABEL: @smax_uses(
+; CHECK-NEXT: [[M1:%.*]] = call i8 @llvm.smax.i8(i8 [[X:%.*]], i8 [[Y:%.*]])
+; CHECK-NEXT: call void @use(i8 [[M1]])
+; CHECK-NEXT: [[M2:%.*]] = call i8 @llvm.smax.i8(i8 [[X]], i8 [[Z:%.*]])
+; CHECK-NEXT: call void @use(i8 [[M2]])
+; CHECK-NEXT: [[M3:%.*]] = call i8 @llvm.smax.i8(i8 [[M1]], i8 [[M2]])
+; CHECK-NEXT: ret i8 [[M3]]
+;
+ %m1 = call i8 @llvm.smax.i8(i8 %x, i8 %y)
+ call void @use(i8 %m1)
+ %m2 = call i8 @llvm.smax.i8(i8 %x, i8 %z)
+ call void @use(i8 %m2)
+ %m3 = call i8 @llvm.smax.i8(i8 %m1, i8 %m2)
+ ret i8 %m3
+}
More information about the llvm-commits
mailing list