Compiler projects using llvm
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -passes=instsimplify -S | FileCheck %s

define i1 @test_umax1(i32 %n) {
; CHECK-LABEL: @test_umax1(
; CHECK-NEXT:    ret i1 true
;
  %c1 = icmp ugt i32 %n, 10
  %s = select i1 %c1, i32 %n, i32 10
  %c2 = icmp ugt i32 %s, 9
  ret i1 %c2
}

define i1 @test_umax2(i32 %n) {
; CHECK-LABEL: @test_umax2(
; CHECK-NEXT:    [[C1:%.*]] = icmp ugt i32 [[N:%.*]], 10
; CHECK-NEXT:    ret i1 [[C1]]
;
  %c1 = icmp ugt i32 %n, 10
  %s = select i1 %c1, i32 %n, i32 10
  %c2 = icmp ugt i32 %s, 10
  ret i1 %c2
}

define i1 @test_umax3(i32 %n) {
; CHECK-LABEL: @test_umax3(
; CHECK-NEXT:    [[C1:%.*]] = icmp ugt i32 [[N:%.*]], 10
; CHECK-NEXT:    [[S:%.*]] = select i1 [[C1]], i32 [[N]], i32 10
; CHECK-NEXT:    [[C2:%.*]] = icmp ugt i32 [[S]], 11
; CHECK-NEXT:    ret i1 [[C2]]
;
  %c1 = icmp ugt i32 %n, 10
  %s = select i1 %c1, i32 %n, i32 10
  %c2 = icmp ugt i32 %s, 11
  ret i1 %c2
}

define i1 @test_umin1(i32 %n) {
; CHECK-LABEL: @test_umin1(
; CHECK-NEXT:    ret i1 true
;
  %c1 = icmp ult i32 %n, 10
  %s = select i1 %c1, i32 %n, i32 10
  %c2 = icmp ult i32 %s, 11
  ret i1 %c2
}

define i1 @test_umin2(i32 %n) {
; CHECK-LABEL: @test_umin2(
; CHECK-NEXT:    [[C1:%.*]] = icmp ult i32 [[N:%.*]], 10
; CHECK-NEXT:    ret i1 [[C1]]
;
  %c1 = icmp ult i32 %n, 10
  %s = select i1 %c1, i32 %n, i32 10
  %c2 = icmp ult i32 %s, 10
  ret i1 %c2
}

define i1 @test_umin3(i32 %n) {
; CHECK-LABEL: @test_umin3(
; CHECK-NEXT:    [[C1:%.*]] = icmp ult i32 [[N:%.*]], 10
; CHECK-NEXT:    [[S:%.*]] = select i1 [[C1]], i32 [[N]], i32 10
; CHECK-NEXT:    [[C2:%.*]] = icmp ult i32 [[S]], 9
; CHECK-NEXT:    ret i1 [[C2]]
;
  %c1 = icmp ult i32 %n, 10
  %s = select i1 %c1, i32 %n, i32 10
  %c2 = icmp ult i32 %s, 9
  ret i1 %c2
}

define i1 @test_smax1(i32 %n) {
; CHECK-LABEL: @test_smax1(
; CHECK-NEXT:    ret i1 true
;
  %c1 = icmp sgt i32 %n, -10
  %s = select i1 %c1, i32 %n, i32 -10
  %c2 = icmp sgt i32 %s, -11
  ret i1 %c2
}

define i1 @test_smax2(i32 %n) {
; CHECK-LABEL: @test_smax2(
; CHECK-NEXT:    [[C1:%.*]] = icmp sgt i32 [[N:%.*]], -10
; CHECK-NEXT:    ret i1 [[C1]]
;
  %c1 = icmp sgt i32 %n, -10
  %s = select i1 %c1, i32 %n, i32 -10
  %c2 = icmp sgt i32 %s, -10
  ret i1 %c2
}

define i1 @test_smax3(i32 %n) {
; CHECK-LABEL: @test_smax3(
; CHECK-NEXT:    [[C1:%.*]] = icmp sgt i32 [[N:%.*]], -10
; CHECK-NEXT:    [[S:%.*]] = select i1 [[C1]], i32 [[N]], i32 -10
; CHECK-NEXT:    [[C2:%.*]] = icmp sgt i32 [[S]], -9
; CHECK-NEXT:    ret i1 [[C2]]
;
  %c1 = icmp sgt i32 %n, -10
  %s = select i1 %c1, i32 %n, i32 -10
  %c2 = icmp sgt i32 %s, -9
  ret i1 %c2
}

define i1 @test_smin1(i32 %n) {
; CHECK-LABEL: @test_smin1(
; CHECK-NEXT:    ret i1 true
;
  %c1 = icmp slt i32 %n, 10
  %s = select i1 %c1, i32 %n, i32 10
  %c2 = icmp slt i32 %s, 11
  ret i1 %c2
}

define i1 @test_smin2(i32 %n) {
; CHECK-LABEL: @test_smin2(
; CHECK-NEXT:    [[C1:%.*]] = icmp slt i32 [[N:%.*]], 10
; CHECK-NEXT:    ret i1 [[C1]]
;
  %c1 = icmp slt i32 %n, 10
  %s = select i1 %c1, i32 %n, i32 10
  %c2 = icmp slt i32 %s, 10
  ret i1 %c2
}

define i1 @test_smin3(i32 %n) {
; CHECK-LABEL: @test_smin3(
; CHECK-NEXT:    [[C1:%.*]] = icmp slt i32 [[N:%.*]], 10
; CHECK-NEXT:    [[S:%.*]] = select i1 [[C1]], i32 [[N]], i32 10
; CHECK-NEXT:    [[C2:%.*]] = icmp slt i32 [[S]], 9
; CHECK-NEXT:    ret i1 [[C2]]
;
  %c1 = icmp slt i32 %n, 10
  %s = select i1 %c1, i32 %n, i32 10
  %c2 = icmp slt i32 %s, 9
  ret i1 %c2
}