-; NOTE: Assertions have been autogenerated by update_test_checks.py
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -instsimplify -S | FileCheck %s
+define i8 @smax_min_limit(i8 %x) {
+; CHECK-LABEL: @smax_min_limit(
+; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[X:%.*]], -128
+; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i8 [[X]], i8 -128
+; CHECK-NEXT: ret i8 [[SEL]]
+;
+ %cmp = icmp sgt i8 %x, -128
+ %sel = select i1 %cmp, i8 %x, i8 -128
+ ret i8 %sel
+}
+
+define i8 @smin_max_limit(i8 %x) {
+; CHECK-LABEL: @smin_max_limit(
+; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[X:%.*]], 127
+; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i8 [[X]], i8 127
+; CHECK-NEXT: ret i8 [[SEL]]
+;
+ %cmp = icmp slt i8 %x, 127
+ %sel = select i1 %cmp, i8 %x, i8 127
+ ret i8 %sel
+}
+
+define <2 x i8> @umax_min_limit(<2 x i8> %x) {
+; CHECK-LABEL: @umax_min_limit(
+; CHECK-NEXT: [[CMP:%.*]] = icmp ugt <2 x i8> [[X:%.*]], zeroinitializer
+; CHECK-NEXT: [[SEL:%.*]] = select <2 x i1> [[CMP]], <2 x i8> [[X]], <2 x i8> zeroinitializer
+; CHECK-NEXT: ret <2 x i8> [[SEL]]
+;
+ %cmp = icmp ugt <2 x i8> %x, zeroinitializer
+ %sel = select <2 x i1> %cmp, <2 x i8> %x, <2 x i8> zeroinitializer
+ ret <2 x i8> %sel
+}
+
+define i8 @umin_max_limit(i8 %x) {
+; CHECK-LABEL: @umin_max_limit(
+; CHECK-NEXT: [[CMP:%.*]] = icmp ult i8 [[X:%.*]], -1
+; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i8 [[X]], i8 -1
+; CHECK-NEXT: ret i8 [[SEL]]
+;
+ %cmp = icmp ult i8 %x, 255
+ %sel = select i1 %cmp, i8 %x, i8 255
+ ret i8 %sel
+}
+
+define i8 @smax_not_min_limit(i8 %x) {
+; CHECK-LABEL: @smax_not_min_limit(
+; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[X:%.*]], -127
+; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i8 [[X]], i8 -127
+; CHECK-NEXT: ret i8 [[SEL]]
+;
+ %cmp = icmp sgt i8 %x, -127
+ %sel = select i1 %cmp, i8 %x, i8 -127
+ ret i8 %sel
+}
+
+define i8 @smin_not_min_limit(i8 %x) {
+; CHECK-LABEL: @smin_not_min_limit(
+; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[X:%.*]], 0
+; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i8 [[X]], i8 0
+; CHECK-NEXT: ret i8 [[SEL]]
+;
+ %cmp = icmp slt i8 %x, 0
+ %sel = select i1 %cmp, i8 %x, i8 0
+ ret i8 %sel
+}
+
define i1 @max1(i32 %x, i32 %y) {
; CHECK-LABEL: @max1(
-; CHECK: ret i1 false
+; CHECK-NEXT: ret i1 false
;
%c = icmp sgt i32 %x, %y
%m = select i1 %c, i32 %x, i32 %y
define i1 @max2(i32 %x, i32 %y) {
; CHECK-LABEL: @max2(
-; CHECK: ret i1 true
+; CHECK-NEXT: ret i1 true
;
%c = icmp sge i32 %x, %y
%m = select i1 %c, i32 %x, i32 %y
define i1 @max3(i32 %x, i32 %y) {
; CHECK-LABEL: @max3(
-; CHECK: ret i1 false
+; CHECK-NEXT: ret i1 false
;
%c = icmp ugt i32 %x, %y
%m = select i1 %c, i32 %x, i32 %y
define i1 @max4(i32 %x, i32 %y) {
; CHECK-LABEL: @max4(
-; CHECK: ret i1 true
+; CHECK-NEXT: ret i1 true
;
%c = icmp uge i32 %x, %y
%m = select i1 %c, i32 %x, i32 %y
define i1 @max5(i32 %x, i32 %y) {
; CHECK-LABEL: @max5(
-; CHECK: ret i1 false
+; CHECK-NEXT: ret i1 false
;
%c = icmp sgt i32 %x, %y
%m = select i1 %c, i32 %x, i32 %y
define i1 @max6(i32 %x, i32 %y) {
; CHECK-LABEL: @max6(
-; CHECK: ret i1 true
+; CHECK-NEXT: ret i1 true
;
%c = icmp sge i32 %x, %y
%m = select i1 %c, i32 %x, i32 %y
define i1 @max7(i32 %x, i32 %y) {
; CHECK-LABEL: @max7(
-; CHECK: ret i1 false
+; CHECK-NEXT: ret i1 false
;
%c = icmp ugt i32 %x, %y
%m = select i1 %c, i32 %x, i32 %y
define i1 @max8(i32 %x, i32 %y) {
; CHECK-LABEL: @max8(
-; CHECK: ret i1 true
+; CHECK-NEXT: ret i1 true
;
%c = icmp uge i32 %x, %y
%m = select i1 %c, i32 %x, i32 %y
define i1 @min1(i32 %x, i32 %y) {
; CHECK-LABEL: @min1(
-; CHECK: ret i1 false
+; CHECK-NEXT: ret i1 false
;
%c = icmp sgt i32 %x, %y
%m = select i1 %c, i32 %y, i32 %x
define i1 @min2(i32 %x, i32 %y) {
; CHECK-LABEL: @min2(
-; CHECK: ret i1 true
+; CHECK-NEXT: ret i1 true
;
%c = icmp sge i32 %x, %y
%m = select i1 %c, i32 %y, i32 %x
define i1 @min3(i32 %x, i32 %y) {
; CHECK-LABEL: @min3(
-; CHECK: ret i1 false
+; CHECK-NEXT: ret i1 false
;
%c = icmp ugt i32 %x, %y
%m = select i1 %c, i32 %y, i32 %x
define i1 @min4(i32 %x, i32 %y) {
; CHECK-LABEL: @min4(
-; CHECK: ret i1 true
+; CHECK-NEXT: ret i1 true
;
%c = icmp uge i32 %x, %y
%m = select i1 %c, i32 %y, i32 %x
define i1 @min5(i32 %x, i32 %y) {
; CHECK-LABEL: @min5(
-; CHECK: ret i1 false
+; CHECK-NEXT: ret i1 false
;
%c = icmp sgt i32 %x, %y
%m = select i1 %c, i32 %y, i32 %x
define i1 @min6(i32 %x, i32 %y) {
; CHECK-LABEL: @min6(
-; CHECK: ret i1 true
+; CHECK-NEXT: ret i1 true
;
%c = icmp sge i32 %x, %y
%m = select i1 %c, i32 %y, i32 %x
define i1 @min7(i32 %x, i32 %y) {
; CHECK-LABEL: @min7(
-; CHECK: ret i1 false
+; CHECK-NEXT: ret i1 false
;
%c = icmp ugt i32 %x, %y
%m = select i1 %c, i32 %y, i32 %x
define i1 @min8(i32 %x, i32 %y) {
; CHECK-LABEL: @min8(
-; CHECK: ret i1 true
+; CHECK-NEXT: ret i1 true
;
%c = icmp uge i32 %x, %y
%m = select i1 %c, i32 %y, i32 %x
define i1 @maxmin1(i32 %x, i32 %y, i32 %z) {
; CHECK-LABEL: @maxmin1(
-; CHECK: ret i1 true
+; CHECK-NEXT: ret i1 true
;
%c1 = icmp sge i32 %x, %y
%max = select i1 %c1, i32 %x, i32 %y
define i1 @maxmin2(i32 %x, i32 %y, i32 %z) {
; CHECK-LABEL: @maxmin2(
-; CHECK: ret i1 false
+; CHECK-NEXT: ret i1 false
;
%c1 = icmp sge i32 %x, %y
%max = select i1 %c1, i32 %x, i32 %y
define i1 @maxmin3(i32 %x, i32 %y, i32 %z) {
; CHECK-LABEL: @maxmin3(
-; CHECK: ret i1 true
+; CHECK-NEXT: ret i1 true
;
%c1 = icmp sge i32 %x, %y
%max = select i1 %c1, i32 %x, i32 %y
define i1 @maxmin4(i32 %x, i32 %y, i32 %z) {
; CHECK-LABEL: @maxmin4(
-; CHECK: ret i1 false
+; CHECK-NEXT: ret i1 false
;
%c1 = icmp sge i32 %x, %y
%max = select i1 %c1, i32 %x, i32 %y
define i1 @maxmin5(i32 %x, i32 %y, i32 %z) {
; CHECK-LABEL: @maxmin5(
-; CHECK: ret i1 true
+; CHECK-NEXT: ret i1 true
;
%c1 = icmp uge i32 %x, %y
%max = select i1 %c1, i32 %x, i32 %y
define i1 @maxmin6(i32 %x, i32 %y, i32 %z) {
; CHECK-LABEL: @maxmin6(
-; CHECK: ret i1 false
+; CHECK-NEXT: ret i1 false
;
%c1 = icmp uge i32 %x, %y
%max = select i1 %c1, i32 %x, i32 %y
define i1 @maxmin7(i32 %x, i32 %y, i32 %z) {
; CHECK-LABEL: @maxmin7(
-; CHECK: ret i1 true
+; CHECK-NEXT: ret i1 true
;
%c1 = icmp uge i32 %x, %y
%max = select i1 %c1, i32 %x, i32 %y
define i1 @maxmin8(i32 %x, i32 %y, i32 %z) {
; CHECK-LABEL: @maxmin8(
-; CHECK: ret i1 false
+; CHECK-NEXT: ret i1 false
;
%c1 = icmp uge i32 %x, %y
%max = select i1 %c1, i32 %x, i32 %y
define i1 @eqcmp1(i32 %x, i32 %y) {
; CHECK-LABEL: @eqcmp1(
-; CHECK: [[C:%.*]] = icmp sge i32 %x, %y
+; CHECK-NEXT: [[C:%.*]] = icmp sge i32 [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: ret i1 [[C]]
;
%c = icmp sge i32 %x, %y
define i1 @eqcmp2(i32 %x, i32 %y) {
; CHECK-LABEL: @eqcmp2(
-; CHECK: [[C:%.*]] = icmp sge i32 %x, %y
+; CHECK-NEXT: [[C:%.*]] = icmp sge i32 [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: ret i1 [[C]]
;
%c = icmp sge i32 %x, %y
define i1 @eqcmp3(i32 %x, i32 %y) {
; CHECK-LABEL: @eqcmp3(
-; CHECK: [[C:%.*]] = icmp uge i32 %x, %y
+; CHECK-NEXT: [[C:%.*]] = icmp uge i32 [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: ret i1 [[C]]
;
%c = icmp uge i32 %x, %y
define i1 @eqcmp4(i32 %x, i32 %y) {
; CHECK-LABEL: @eqcmp4(
-; CHECK: [[C:%.*]] = icmp uge i32 %x, %y
+; CHECK-NEXT: [[C:%.*]] = icmp uge i32 [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: ret i1 [[C]]
;
%c = icmp uge i32 %x, %y