1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instcombine -S | FileCheck %s
4 declare i5 @llvm.smin.i5(i5, i5)
5 declare <2 x i8> @llvm.smax.v2i8(<2 x i8>, <2 x i8>)
6 declare i5 @llvm.umin.i5(i5, i5)
7 declare <3 x i5> @llvm.umax.v3i5(<3 x i5>, <3 x i5>)
9 define i5 @smin_smin_common_op_00(i1 %cond, i5 %x, i5 %y, i5 %z) {
10 ; CHECK-LABEL: @smin_smin_common_op_00(
11 ; CHECK-NEXT: [[MINMAXOP:%.*]] = select i1 [[COND:%.*]], i5 [[X:%.*]], i5 [[Y:%.*]]
12 ; CHECK-NEXT: [[SEL:%.*]] = call i5 @llvm.smin.i5(i5 [[MINMAXOP]], i5 [[Z:%.*]])
13 ; CHECK-NEXT: ret i5 [[SEL]]
15 %m1 = call i5 @llvm.smin.i5(i5 %z, i5 %x)
16 %m2 = call i5 @llvm.smin.i5(i5 %z, i5 %y)
17 %sel = select i1 %cond, i5 %m1, i5 %m2
21 define <2 x i8> @smax_smax_common_op_01(<2 x i1> %cond, <2 x i8> %x, <2 x i8> %y, <2 x i8> %z) {
22 ; CHECK-LABEL: @smax_smax_common_op_01(
23 ; CHECK-NEXT: [[MINMAXOP:%.*]] = select <2 x i1> [[COND:%.*]], <2 x i8> [[X:%.*]], <2 x i8> [[Y:%.*]]
24 ; CHECK-NEXT: [[SEL:%.*]] = call <2 x i8> @llvm.smax.v2i8(<2 x i8> [[MINMAXOP]], <2 x i8> [[Z:%.*]])
25 ; CHECK-NEXT: ret <2 x i8> [[SEL]]
27 %m1 = call <2 x i8> @llvm.smax.v2i8(<2 x i8> %z, <2 x i8> %x)
28 %m2 = call <2 x i8> @llvm.smax.v2i8(<2 x i8> %y, <2 x i8> %z)
29 %sel = select <2 x i1> %cond, <2 x i8> %m1, <2 x i8> %m2
33 define i5 @umin_umin_common_op_10(i1 %cond, i5 %x, i5 %y, i5 %z, i5* %p) {
34 ; CHECK-LABEL: @umin_umin_common_op_10(
35 ; CHECK-NEXT: [[M1:%.*]] = call i5 @llvm.umin.i5(i5 [[X:%.*]], i5 [[Z:%.*]])
36 ; CHECK-NEXT: store i5 [[M1]], i5* [[P:%.*]], align 1
37 ; CHECK-NEXT: [[MINMAXOP:%.*]] = select i1 [[COND:%.*]], i5 [[X]], i5 [[Y:%.*]]
38 ; CHECK-NEXT: [[SEL:%.*]] = call i5 @llvm.umin.i5(i5 [[MINMAXOP]], i5 [[Z]])
39 ; CHECK-NEXT: ret i5 [[SEL]]
41 %m1 = call i5 @llvm.umin.i5(i5 %x, i5 %z)
43 %m2 = call i5 @llvm.umin.i5(i5 %z, i5 %y)
44 %sel = select i1 %cond, i5 %m1, i5 %m2
48 define <3 x i5> @umax_umax_common_op_11(i1 %cond, <3 x i5> %x, <3 x i5> %y, <3 x i5> %z, <3 x i5>* %p) {
49 ; CHECK-LABEL: @umax_umax_common_op_11(
50 ; CHECK-NEXT: [[M2:%.*]] = call <3 x i5> @llvm.umax.v3i5(<3 x i5> [[Y:%.*]], <3 x i5> [[Z:%.*]])
51 ; CHECK-NEXT: store <3 x i5> [[M2]], <3 x i5>* [[P:%.*]], align 2
52 ; CHECK-NEXT: [[MINMAXOP:%.*]] = select i1 [[COND:%.*]], <3 x i5> [[X:%.*]], <3 x i5> [[Y]]
53 ; CHECK-NEXT: [[SEL:%.*]] = call <3 x i5> @llvm.umax.v3i5(<3 x i5> [[MINMAXOP]], <3 x i5> [[Z]])
54 ; CHECK-NEXT: ret <3 x i5> [[SEL]]
56 %m1 = call <3 x i5> @llvm.umax.v3i5(<3 x i5> %x, <3 x i5> %z)
57 %m2 = call <3 x i5> @llvm.umax.v3i5(<3 x i5> %y, <3 x i5> %z)
58 store <3 x i5> %m2, <3 x i5>* %p
59 %sel = select i1 %cond, <3 x i5> %m1, <3 x i5> %m2
63 ; negative test - intrinsic mismatch
65 define i5 @smin_umin_common_op_11(i1 %cond, i5 %x, i5 %y, i5 %z) {
66 ; CHECK-LABEL: @smin_umin_common_op_11(
67 ; CHECK-NEXT: [[M1:%.*]] = call i5 @llvm.smin.i5(i5 [[X:%.*]], i5 [[Z:%.*]])
68 ; CHECK-NEXT: [[M2:%.*]] = call i5 @llvm.umin.i5(i5 [[Y:%.*]], i5 [[Z]])
69 ; CHECK-NEXT: [[SEL:%.*]] = select i1 [[COND:%.*]], i5 [[M1]], i5 [[M2]]
70 ; CHECK-NEXT: ret i5 [[SEL]]
72 %m1 = call i5 @llvm.smin.i5(i5 %x, i5 %z)
73 %m2 = call i5 @llvm.umin.i5(i5 %y, i5 %z)
74 %sel = select i1 %cond, i5 %m1, i5 %m2
78 ; negative test - require shared operand
80 define i5 @smin_smin_no_common_op(i1 %cond, i5 %x, i5 %y, i5 %z, i5 %w) {
81 ; CHECK-LABEL: @smin_smin_no_common_op(
82 ; CHECK-NEXT: [[M1:%.*]] = call i5 @llvm.smin.i5(i5 [[Z:%.*]], i5 [[X:%.*]])
83 ; CHECK-NEXT: [[M2:%.*]] = call i5 @llvm.smin.i5(i5 [[W:%.*]], i5 [[Y:%.*]])
84 ; CHECK-NEXT: [[SEL:%.*]] = select i1 [[COND:%.*]], i5 [[M1]], i5 [[M2]]
85 ; CHECK-NEXT: ret i5 [[SEL]]
87 %m1 = call i5 @llvm.smin.i5(i5 %z, i5 %x)
88 %m2 = call i5 @llvm.smin.i5(i5 %w, i5 %y)
89 %sel = select i1 %cond, i5 %m1, i5 %m2
93 ; negative test - too many uses
95 define i5 @umin_umin_common_op_10_uses(i1 %cond, i5 %x, i5 %y, i5 %z, i5* %p1, i5* %p2) {
96 ; CHECK-LABEL: @umin_umin_common_op_10_uses(
97 ; CHECK-NEXT: [[M1:%.*]] = call i5 @llvm.umin.i5(i5 [[X:%.*]], i5 [[Z:%.*]])
98 ; CHECK-NEXT: store i5 [[M1]], i5* [[P1:%.*]], align 1
99 ; CHECK-NEXT: [[M2:%.*]] = call i5 @llvm.umin.i5(i5 [[Z]], i5 [[Y:%.*]])
100 ; CHECK-NEXT: store i5 [[M2]], i5* [[P2:%.*]], align 1
101 ; CHECK-NEXT: [[SEL:%.*]] = select i1 [[COND:%.*]], i5 [[M1]], i5 [[M2]]
102 ; CHECK-NEXT: ret i5 [[SEL]]
104 %m1 = call i5 @llvm.umin.i5(i5 %x, i5 %z)
105 store i5 %m1, i5* %p1
106 %m2 = call i5 @llvm.umin.i5(i5 %z, i5 %y)
107 store i5 %m2, i5* %p2
108 %sel = select i1 %cond, i5 %m1, i5 %m2
112 define i5 @smin_select_const_const(i1 %b) {
113 ; CHECK-LABEL: @smin_select_const_const(
114 ; CHECK-NEXT: [[C:%.*]] = select i1 [[B:%.*]], i5 -3, i5 5
115 ; CHECK-NEXT: ret i5 [[C]]
117 %s = select i1 %b, i5 -3, i5 8
118 %c = call i5 @llvm.smin.i5(i5 %s, i5 5)
122 define <2 x i8> @smax_select_const_const(<2 x i1> %b) {
123 ; CHECK-LABEL: @smax_select_const_const(
124 ; CHECK-NEXT: [[C:%.*]] = select <2 x i1> [[B:%.*]], <2 x i8> <i8 1, i8 42>, <2 x i8> <i8 5, i8 43>
125 ; CHECK-NEXT: ret <2 x i8> [[C]]
127 %s = select <2 x i1> %b, <2 x i8> <i8 1, i8 3>, <2 x i8> <i8 5, i8 43>
128 %c = call <2 x i8> @llvm.smax.v2i8(<2 x i8> %s, <2 x i8> <i8 0, i8 42>)
132 define i5 @umin_select_const_const(i1 %b) {
133 ; CHECK-LABEL: @umin_select_const_const(
134 ; CHECK-NEXT: [[C:%.*]] = select i1 [[B:%.*]], i5 4, i5 3
135 ; CHECK-NEXT: ret i5 [[C]]
137 %s = select i1 %b, i5 8, i5 3
138 %c = call i5 @llvm.umin.i5(i5 4, i5 %s)
142 define <3 x i5> @umax_select_const_const(<3 x i1> %b) {
143 ; CHECK-LABEL: @umax_select_const_const(
144 ; CHECK-NEXT: [[C:%.*]] = select <3 x i1> [[B:%.*]], <3 x i5> <i5 5, i5 8, i5 -16>, <3 x i5> <i5 7, i5 8, i5 -16>
145 ; CHECK-NEXT: ret <3 x i5> [[C]]
147 %s = select <3 x i1> %b, <3 x i5> <i5 2, i5 3, i5 4>, <3 x i5> <i5 7, i5 8, i5 9>
148 %c = call <3 x i5> @llvm.umax.v3i5(<3 x i5> <i5 5, i5 8, i5 16>, <3 x i5> %s)
152 define i5 @smin_select_const(i1 %b, i5 %x) {
153 ; CHECK-LABEL: @smin_select_const(
154 ; CHECK-NEXT: [[TMP1:%.*]] = call i5 @llvm.smin.i5(i5 [[X:%.*]], i5 5)
155 ; CHECK-NEXT: [[C:%.*]] = select i1 [[B:%.*]], i5 -3, i5 [[TMP1]]
156 ; CHECK-NEXT: ret i5 [[C]]
158 %s = select i1 %b, i5 -3, i5 %x
159 %c = call i5 @llvm.smin.i5(i5 %s, i5 5)
163 define <2 x i8> @smax_select_const(<2 x i1> %b, <2 x i8> %x) {
164 ; CHECK-LABEL: @smax_select_const(
165 ; CHECK-NEXT: [[TMP1:%.*]] = call <2 x i8> @llvm.smax.v2i8(<2 x i8> [[X:%.*]], <2 x i8> <i8 0, i8 42>)
166 ; CHECK-NEXT: [[C:%.*]] = select <2 x i1> [[B:%.*]], <2 x i8> [[TMP1]], <2 x i8> <i8 5, i8 43>
167 ; CHECK-NEXT: ret <2 x i8> [[C]]
169 %s = select <2 x i1> %b, <2 x i8> %x, <2 x i8> <i8 5, i8 43>
170 %c = call <2 x i8> @llvm.smax.v2i8(<2 x i8> %s, <2 x i8> <i8 0, i8 42>)
174 define i5 @umin_select_const(i1 %b, i5 %x) {
175 ; CHECK-LABEL: @umin_select_const(
176 ; CHECK-NEXT: [[TMP1:%.*]] = call i5 @llvm.umin.i5(i5 [[X:%.*]], i5 4)
177 ; CHECK-NEXT: [[C:%.*]] = select i1 [[B:%.*]], i5 [[TMP1]], i5 3
178 ; CHECK-NEXT: ret i5 [[C]]
180 %s = select i1 %b, i5 %x, i5 3
181 %c = call i5 @llvm.umin.i5(i5 4, i5 %s)
185 define <3 x i5> @umax_select_const(<3 x i1> %b, <3 x i5> %x) {
186 ; CHECK-LABEL: @umax_select_const(
187 ; CHECK-NEXT: [[TMP1:%.*]] = call <3 x i5> @llvm.umax.v3i5(<3 x i5> [[X:%.*]], <3 x i5> <i5 5, i5 8, i5 1>)
188 ; CHECK-NEXT: [[C:%.*]] = select <3 x i1> [[B:%.*]], <3 x i5> <i5 5, i5 8, i5 4>, <3 x i5> [[TMP1]]
189 ; CHECK-NEXT: ret <3 x i5> [[C]]
191 %s = select <3 x i1> %b, <3 x i5> <i5 2, i5 3, i5 4>, <3 x i5> %x
192 %c = call <3 x i5> @llvm.umax.v3i5(<3 x i5> <i5 5, i5 8, i5 1>, <3 x i5> %s)
196 declare i32 @llvm.smax.i32(i32, i32);
197 declare i32 @llvm.smin.i32(i32, i32);
198 declare i8 @llvm.umax.i8(i8, i8);
199 declare i8 @llvm.umin.i8(i8, i8);
201 ; Each of the following 4 tests would infinite loop because
202 ; we had conflicting transforms for icmp and select using
205 define i32 @smax_smin(i32 %x) {
206 ; CHECK-LABEL: @smax_smin(
207 ; CHECK-NEXT: [[M:%.*]] = call i32 @llvm.smax.i32(i32 [[X:%.*]], i32 0)
208 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ult i32 [[M]], 1
209 ; CHECK-NEXT: [[S:%.*]] = select i1 [[TMP1]], i32 [[M]], i32 1
210 ; CHECK-NEXT: ret i32 [[S]]
212 %m = call i32 @llvm.smax.i32(i32 %x, i32 0)
213 %c = icmp slt i32 %x, 1
214 %s = select i1 %c, i32 %m, i32 1
218 define i32 @smin_smax(i32 %x) {
219 ; CHECK-LABEL: @smin_smax(
220 ; CHECK-NEXT: [[M:%.*]] = call i32 @llvm.smin.i32(i32 [[X:%.*]], i32 -1)
221 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ugt i32 [[M]], -2
222 ; CHECK-NEXT: [[S:%.*]] = select i1 [[TMP1]], i32 [[M]], i32 -2
223 ; CHECK-NEXT: ret i32 [[S]]
225 %m = call i32 @llvm.smin.i32(i32 %x, i32 -1)
226 %c = icmp sgt i32 %x, -2
227 %s = select i1 %c, i32 %m, i32 -2
231 define i8 @umax_umin(i8 %x) {
232 ; CHECK-LABEL: @umax_umin(
233 ; CHECK-NEXT: [[M:%.*]] = call i8 @llvm.umax.i8(i8 [[X:%.*]], i8 -128)
234 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ult i8 [[M]], -127
235 ; CHECK-NEXT: [[S:%.*]] = select i1 [[TMP1]], i8 [[M]], i8 -127
236 ; CHECK-NEXT: ret i8 [[S]]
238 %m = call i8 @llvm.umax.i8(i8 %x, i8 128)
239 %c = icmp ult i8 %x, 129
240 %s = select i1 %c, i8 %m, i8 129
244 define i8 @umin_umax(i8 %x) {
245 ; CHECK-LABEL: @umin_umax(
246 ; CHECK-NEXT: [[M:%.*]] = call i8 @llvm.umin.i8(i8 [[X:%.*]], i8 127)
247 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ugt i8 [[M]], 126
248 ; CHECK-NEXT: [[S:%.*]] = select i1 [[TMP1]], i8 [[M]], i8 126
249 ; CHECK-NEXT: ret i8 [[S]]
251 %m = call i8 @llvm.umin.i8(i8 %x, i8 127)
252 %c = icmp ugt i8 %x, 126
253 %s = select i1 %c, i8 %m, i8 126