blob: fb02779b85e0a6b8a1eed5f8761519f3c65a77df [file] [log] [blame]
commit cc8f98198799fe3a5f00e2fc0edcb5d90c124d2f
Author: Sanjay Patel <spatel@rotateright.com>
Date: Wed Mar 9 17:18:35 2022 -0500
[InstCombine] add tests to show miscompiled smin/smax; NFC
diff --git a/llvm/test/Transforms/InstCombine/select-min-max.ll b/llvm/test/Transforms/InstCombine/select-min-max.ll
index b285c7ee54b4..04dc62ec2f92 100644
--- a/llvm/test/Transforms/InstCombine/select-min-max.ll
+++ b/llvm/test/Transforms/InstCombine/select-min-max.ll
@@ -249,3 +249,51 @@ define i8 @umin_umax(i8 %x) {
%s = select i1 %c, i8 %m, i8 126
ret i8 %s
}
+
+define i8 @not_smax(i8 %i41, i8 %i43) {
+; CHECK-LABEL: @not_smax(
+; CHECK-NEXT: [[I46:%.*]] = sub nsw i8 [[I41:%.*]], [[I43:%.*]]
+; CHECK-NEXT: [[TMP1:%.*]] = call i8 @llvm.smax.i8(i8 [[I46]], i8 0)
+; CHECK-NEXT: ret i8 [[TMP1]]
+;
+ %i44 = icmp slt i8 %i41, %i43
+ %i46 = sub nsw i8 %i41, %i43
+ %spec.select = select i1 %i44, i8 0, i8 %i46
+ ret i8 %spec.select
+}
+
+define i8 @not_smax_swap(i8 %i41, i8 %i43) {
+; CHECK-LABEL: @not_smax_swap(
+; CHECK-NEXT: [[I46:%.*]] = sub nsw i8 [[I41:%.*]], [[I43:%.*]]
+; CHECK-NEXT: [[TMP1:%.*]] = call i8 @llvm.smax.i8(i8 [[I46]], i8 0)
+; CHECK-NEXT: ret i8 [[TMP1]]
+;
+ %i44 = icmp sgt i8 %i41, %i43
+ %i46 = sub nsw i8 %i41, %i43
+ %spec.select = select i1 %i44, i8 %i46, i8 0
+ ret i8 %spec.select
+}
+
+define i8 @not_smin(i8 %i41, i8 %i43) {
+; CHECK-LABEL: @not_smin(
+; CHECK-NEXT: [[I46:%.*]] = sub nsw i8 [[I41:%.*]], [[I43:%.*]]
+; CHECK-NEXT: [[TMP1:%.*]] = call i8 @llvm.smin.i8(i8 [[I46]], i8 0)
+; CHECK-NEXT: ret i8 [[TMP1]]
+;
+ %i44 = icmp sgt i8 %i41, %i43
+ %i46 = sub nsw i8 %i41, %i43
+ %spec.select = select i1 %i44, i8 0, i8 %i46
+ ret i8 %spec.select
+}
+
+define i8 @not_smin_swap(i8 %i41, i8 %i43) {
+; CHECK-LABEL: @not_smin_swap(
+; CHECK-NEXT: [[I46:%.*]] = sub nsw i8 [[I41:%.*]], [[I43:%.*]]
+; CHECK-NEXT: [[TMP1:%.*]] = call i8 @llvm.smin.i8(i8 [[I46]], i8 0)
+; CHECK-NEXT: ret i8 [[TMP1]]
+;
+ %i44 = icmp slt i8 %i41, %i43
+ %i46 = sub nsw i8 %i41, %i43
+ %spec.select = select i1 %i44, i8 %i46, i8 0
+ ret i8 %spec.select
+}