1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt < %s -instsimplify -S | FileCheck %s
3
4define i1 @test_umax1(i32 %n) {
5; CHECK-LABEL: @test_umax1(
6; CHECK-NEXT:    ret i1 true
7;
8  %c1 = icmp ugt i32 %n, 10
9  %s = select i1 %c1, i32 %n, i32 10
10  %c2 = icmp ugt i32 %s, 9
11  ret i1 %c2
12}
13
14define i1 @test_umax2(i32 %n) {
15; CHECK-LABEL: @test_umax2(
16; CHECK-NEXT:    [[C1:%.*]] = icmp ugt i32 [[N:%.*]], 10
17; CHECK-NEXT:    ret i1 [[C1]]
18;
19  %c1 = icmp ugt i32 %n, 10
20  %s = select i1 %c1, i32 %n, i32 10
21  %c2 = icmp ugt i32 %s, 10
22  ret i1 %c2
23}
24
25define i1 @test_umax3(i32 %n) {
26; CHECK-LABEL: @test_umax3(
27; CHECK-NEXT:    [[C1:%.*]] = icmp ugt i32 [[N:%.*]], 10
28; CHECK-NEXT:    [[S:%.*]] = select i1 [[C1]], i32 [[N]], i32 10
29; CHECK-NEXT:    [[C2:%.*]] = icmp ugt i32 [[S]], 11
30; CHECK-NEXT:    ret i1 [[C2]]
31;
32  %c1 = icmp ugt i32 %n, 10
33  %s = select i1 %c1, i32 %n, i32 10
34  %c2 = icmp ugt i32 %s, 11
35  ret i1 %c2
36}
37
38define i1 @test_umin1(i32 %n) {
39; CHECK-LABEL: @test_umin1(
40; CHECK-NEXT:    ret i1 true
41;
42  %c1 = icmp ult i32 %n, 10
43  %s = select i1 %c1, i32 %n, i32 10
44  %c2 = icmp ult i32 %s, 11
45  ret i1 %c2
46}
47
48define i1 @test_umin2(i32 %n) {
49; CHECK-LABEL: @test_umin2(
50; CHECK-NEXT:    [[C1:%.*]] = icmp ult i32 [[N:%.*]], 10
51; CHECK-NEXT:    ret i1 [[C1]]
52;
53  %c1 = icmp ult i32 %n, 10
54  %s = select i1 %c1, i32 %n, i32 10
55  %c2 = icmp ult i32 %s, 10
56  ret i1 %c2
57}
58
59define i1 @test_umin3(i32 %n) {
60; CHECK-LABEL: @test_umin3(
61; CHECK-NEXT:    [[C1:%.*]] = icmp ult i32 [[N:%.*]], 10
62; CHECK-NEXT:    [[S:%.*]] = select i1 [[C1]], i32 [[N]], i32 10
63; CHECK-NEXT:    [[C2:%.*]] = icmp ult i32 [[S]], 9
64; CHECK-NEXT:    ret i1 [[C2]]
65;
66  %c1 = icmp ult i32 %n, 10
67  %s = select i1 %c1, i32 %n, i32 10
68  %c2 = icmp ult i32 %s, 9
69  ret i1 %c2
70}
71
72define i1 @test_smax1(i32 %n) {
73; CHECK-LABEL: @test_smax1(
74; CHECK-NEXT:    ret i1 true
75;
76  %c1 = icmp sgt i32 %n, -10
77  %s = select i1 %c1, i32 %n, i32 -10
78  %c2 = icmp sgt i32 %s, -11
79  ret i1 %c2
80}
81
82define i1 @test_smax2(i32 %n) {
83; CHECK-LABEL: @test_smax2(
84; CHECK-NEXT:    [[C1:%.*]] = icmp sgt i32 [[N:%.*]], -10
85; CHECK-NEXT:    ret i1 [[C1]]
86;
87  %c1 = icmp sgt i32 %n, -10
88  %s = select i1 %c1, i32 %n, i32 -10
89  %c2 = icmp sgt i32 %s, -10
90  ret i1 %c2
91}
92
93define i1 @test_smax3(i32 %n) {
94; CHECK-LABEL: @test_smax3(
95; CHECK-NEXT:    [[C1:%.*]] = icmp sgt i32 [[N:%.*]], -10
96; CHECK-NEXT:    [[S:%.*]] = select i1 [[C1]], i32 [[N]], i32 -10
97; CHECK-NEXT:    [[C2:%.*]] = icmp sgt i32 [[S]], -9
98; CHECK-NEXT:    ret i1 [[C2]]
99;
100  %c1 = icmp sgt i32 %n, -10
101  %s = select i1 %c1, i32 %n, i32 -10
102  %c2 = icmp sgt i32 %s, -9
103  ret i1 %c2
104}
105
106define i1 @test_smin1(i32 %n) {
107; CHECK-LABEL: @test_smin1(
108; CHECK-NEXT:    ret i1 true
109;
110  %c1 = icmp slt i32 %n, 10
111  %s = select i1 %c1, i32 %n, i32 10
112  %c2 = icmp slt i32 %s, 11
113  ret i1 %c2
114}
115
116define i1 @test_smin2(i32 %n) {
117; CHECK-LABEL: @test_smin2(
118; CHECK-NEXT:    [[C1:%.*]] = icmp slt i32 [[N:%.*]], 10
119; CHECK-NEXT:    ret i1 [[C1]]
120;
121  %c1 = icmp slt i32 %n, 10
122  %s = select i1 %c1, i32 %n, i32 10
123  %c2 = icmp slt i32 %s, 10
124  ret i1 %c2
125}
126
127define i1 @test_smin3(i32 %n) {
128; CHECK-LABEL: @test_smin3(
129; CHECK-NEXT:    [[C1:%.*]] = icmp slt i32 [[N:%.*]], 10
130; CHECK-NEXT:    [[S:%.*]] = select i1 [[C1]], i32 [[N]], i32 10
131; CHECK-NEXT:    [[C2:%.*]] = icmp slt i32 [[S]], 9
132; CHECK-NEXT:    ret i1 [[C2]]
133;
134  %c1 = icmp slt i32 %n, 10
135  %s = select i1 %c1, i32 %n, i32 10
136  %c2 = icmp slt i32 %s, 9
137  ret i1 %c2
138}
139