[llvm] 4fc068e - [InstCombine] add tests for clamp patterns using min/max intrinsics; NFC
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 27 12:35:58 PDT 2021
Author: Sanjay Patel
Date: 2021-04-27T15:35:49-04:00
New Revision: 4fc068eb82c8190308b3e09c2aecbd1a635317f8
URL: https://github.com/llvm/llvm-project/commit/4fc068eb82c8190308b3e09c2aecbd1a635317f8
DIFF: https://github.com/llvm/llvm-project/commit/4fc068eb82c8190308b3e09c2aecbd1a635317f8.diff
LOG: [InstCombine] add tests for clamp patterns using min/max intrinsics; NFC
Added:
Modified:
llvm/test/Transforms/InstCombine/minmax-intrinsics.ll
Removed:
################################################################################
diff --git a/llvm/test/Transforms/InstCombine/minmax-intrinsics.ll b/llvm/test/Transforms/InstCombine/minmax-intrinsics.ll
index a1185c50bc8b..f447c0a7db05 100644
--- a/llvm/test/Transforms/InstCombine/minmax-intrinsics.ll
+++ b/llvm/test/Transforms/InstCombine/minmax-intrinsics.ll
@@ -703,3 +703,105 @@ define i8 @smax_negation_uses(i8 %x, i8 %y) {
%r = call i8 @llvm.smax.i8(i8 %s1, i8 %s2)
ret i8 %r
}
+
+define i8 @clamp_two_vals_smax_smin(i8 %x) {
+; CHECK-LABEL: @clamp_two_vals_smax_smin(
+; CHECK-NEXT: [[M:%.*]] = call i8 @llvm.smax.i8(i8 [[X:%.*]], i8 42)
+; CHECK-NEXT: [[R:%.*]] = call i8 @llvm.smin.i8(i8 [[M]], i8 43)
+; CHECK-NEXT: ret i8 [[R]]
+;
+ %m = call i8 @llvm.smax.i8(i8 %x, i8 42)
+ %r = call i8 @llvm.smin.i8(i8 %m, i8 43)
+ ret i8 %r
+}
+
+define <3 x i8> @clamp_two_vals_smin_smax(<3 x i8> %x) {
+; CHECK-LABEL: @clamp_two_vals_smin_smax(
+; CHECK-NEXT: [[M:%.*]] = call <3 x i8> @llvm.smin.v3i8(<3 x i8> [[X:%.*]], <3 x i8> <i8 42, i8 42, i8 42>)
+; CHECK-NEXT: [[R:%.*]] = call <3 x i8> @llvm.smax.v3i8(<3 x i8> [[M]], <3 x i8> <i8 41, i8 41, i8 41>)
+; CHECK-NEXT: ret <3 x i8> [[R]]
+;
+ %m = call <3 x i8> @llvm.smin.v3i8(<3 x i8> %x, <3 x i8> <i8 42, i8 42, i8 42>)
+ %r = call <3 x i8> @llvm.smax.v3i8(<3 x i8> %m, <3 x i8> <i8 41, i8 41, i8 41>)
+ ret <3 x i8> %r
+}
+
+define i8 @clamp_two_vals_umax_umin(i8 %x) {
+; CHECK-LABEL: @clamp_two_vals_umax_umin(
+; CHECK-NEXT: [[M:%.*]] = call i8 @llvm.umax.i8(i8 [[X:%.*]], i8 42)
+; CHECK-NEXT: [[R:%.*]] = call i8 @llvm.umin.i8(i8 [[M]], i8 43)
+; CHECK-NEXT: ret i8 [[R]]
+;
+ %m = call i8 @llvm.umax.i8(i8 %x, i8 42)
+ %r = call i8 @llvm.umin.i8(i8 %m, i8 43)
+ ret i8 %r
+}
+
+define i8 @clamp_two_vals_umin_umax(i8 %x) {
+; CHECK-LABEL: @clamp_two_vals_umin_umax(
+; CHECK-NEXT: [[M:%.*]] = call i8 @llvm.umin.i8(i8 [[X:%.*]], i8 42)
+; CHECK-NEXT: [[R:%.*]] = call i8 @llvm.umax.i8(i8 [[M]], i8 41)
+; CHECK-NEXT: ret i8 [[R]]
+;
+ %m = call i8 @llvm.umin.i8(i8 %x, i8 42)
+ %r = call i8 @llvm.umax.i8(i8 %m, i8 41)
+ ret i8 %r
+}
+
+define i8 @clamp_two_vals_smax_umin(i8 %x) {
+; CHECK-LABEL: @clamp_two_vals_smax_umin(
+; CHECK-NEXT: [[M:%.*]] = call i8 @llvm.smax.i8(i8 [[X:%.*]], i8 42)
+; CHECK-NEXT: [[R:%.*]] = call i8 @llvm.umin.i8(i8 [[M]], i8 43)
+; CHECK-NEXT: ret i8 [[R]]
+;
+ %m = call i8 @llvm.smax.i8(i8 %x, i8 42)
+ %r = call i8 @llvm.umin.i8(i8 %m, i8 43)
+ ret i8 %r
+}
+
+define i8 @clamp_three_vals_smax_smin(i8 %x) {
+; CHECK-LABEL: @clamp_three_vals_smax_smin(
+; CHECK-NEXT: [[M:%.*]] = call i8 @llvm.smax.i8(i8 [[X:%.*]], i8 42)
+; CHECK-NEXT: [[R:%.*]] = call i8 @llvm.smin.i8(i8 [[M]], i8 44)
+; CHECK-NEXT: ret i8 [[R]]
+;
+ %m = call i8 @llvm.smax.i8(i8 %x, i8 42)
+ %r = call i8 @llvm.smin.i8(i8 %m, i8 44)
+ ret i8 %r
+}
+
+define i8 @clamp_two_vals_umax_umin_edge(i8 %x) {
+; CHECK-LABEL: @clamp_two_vals_umax_umin_edge(
+; CHECK-NEXT: ret i8 0
+;
+ %m = call i8 @llvm.umax.i8(i8 %x, i8 255)
+ %r = call i8 @llvm.umin.i8(i8 %m, i8 0)
+ ret i8 %r
+}
+
+define i8 @clamp_two_vals_umin_umax_edge(i8 %x) {
+; CHECK-LABEL: @clamp_two_vals_umin_umax_edge(
+; CHECK-NEXT: ret i8 -1
+;
+ %m = call i8 @llvm.umin.i8(i8 %x, i8 0)
+ %r = call i8 @llvm.umax.i8(i8 %m, i8 255)
+ ret i8 %r
+}
+
+define i8 @clamp_two_vals_smax_smin_edge(i8 %x) {
+; CHECK-LABEL: @clamp_two_vals_smax_smin_edge(
+; CHECK-NEXT: ret i8 -128
+;
+ %m = call i8 @llvm.smax.i8(i8 %x, i8 127)
+ %r = call i8 @llvm.smin.i8(i8 %m, i8 128)
+ ret i8 %r
+}
+
+define i8 @clamp_two_vals_smin_smax_edge(i8 %x) {
+; CHECK-LABEL: @clamp_two_vals_smin_smax_edge(
+; CHECK-NEXT: ret i8 127
+;
+ %m = call i8 @llvm.smin.i8(i8 %x, i8 128)
+ %r = call i8 @llvm.smax.i8(i8 %m, i8 127)
+ ret i8 %r
+}
More information about the llvm-commits
mailing list