1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -instcombine < %s | FileCheck %s
4 define <2 x i32> @umin_of_nots(<2 x i32> %x, <2 x i32> %y) {
5 ; CHECK-LABEL: @umin_of_nots(
6 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ugt <2 x i32> [[X:%.*]], [[Y:%.*]]
7 ; CHECK-NEXT: [[TMP2:%.*]] = select <2 x i1> [[TMP1]], <2 x i32> [[X]], <2 x i32> [[Y]]
8 ; CHECK-NEXT: [[MIN:%.*]] = xor <2 x i32> [[TMP2]], <i32 -1, i32 -1>
9 ; CHECK-NEXT: ret <2 x i32> [[MIN]]
11 %notx = xor <2 x i32> %x, <i32 -1, i32 -1>
12 %noty = xor <2 x i32> %y, <i32 -1, i32 -1>
13 %cmp = icmp ult <2 x i32> %notx, %noty
14 %min = select <2 x i1> %cmp, <2 x i32> %notx, <2 x i32> %noty
18 define <2 x i32> @smin_of_nots(<2 x i32> %x, <2 x i32> %y) {
19 ; CHECK-LABEL: @smin_of_nots(
20 ; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt <2 x i32> [[X:%.*]], [[Y:%.*]]
21 ; CHECK-NEXT: [[TMP2:%.*]] = select <2 x i1> [[TMP1]], <2 x i32> [[X]], <2 x i32> [[Y]]
22 ; CHECK-NEXT: [[MIN:%.*]] = xor <2 x i32> [[TMP2]], <i32 -1, i32 -1>
23 ; CHECK-NEXT: ret <2 x i32> [[MIN]]
25 %notx = xor <2 x i32> %x, <i32 -1, i32 -1>
26 %noty = xor <2 x i32> %y, <i32 -1, i32 -1>
27 %cmp = icmp sle <2 x i32> %notx, %noty
28 %min = select <2 x i1> %cmp, <2 x i32> %notx, <2 x i32> %noty
32 define i32 @compute_min_2(i32 %x, i32 %y) {
33 ; CHECK-LABEL: @compute_min_2(
34 ; CHECK-NEXT: [[TMP1:%.*]] = icmp slt i32 [[X:%.*]], [[Y:%.*]]
35 ; CHECK-NEXT: [[TMP2:%.*]] = select i1 [[TMP1]], i32 [[X]], i32 [[Y]]
36 ; CHECK-NEXT: ret i32 [[TMP2]]
38 %not_x = sub i32 -1, %x
39 %not_y = sub i32 -1, %y
40 %cmp = icmp sgt i32 %not_x, %not_y
41 %not_min = select i1 %cmp, i32 %not_x, i32 %not_y
42 %min = sub i32 -1, %not_min
46 declare void @extra_use(i8)
47 define i8 @umin_not_1_extra_use(i8 %x, i8 %y) {
48 ; CHECK-LABEL: @umin_not_1_extra_use(
49 ; CHECK-NEXT: [[NX:%.*]] = xor i8 [[X:%.*]], -1
50 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ugt i8 [[Y:%.*]], [[X]]
51 ; CHECK-NEXT: [[TMP2:%.*]] = select i1 [[TMP1]], i8 [[Y]], i8 [[X]]
52 ; CHECK-NEXT: [[MINXY:%.*]] = xor i8 [[TMP2]], -1
53 ; CHECK-NEXT: call void @extra_use(i8 [[NX]])
54 ; CHECK-NEXT: ret i8 [[MINXY]]
58 %cmpxy = icmp ult i8 %nx, %ny
59 %minxy = select i1 %cmpxy, i8 %nx, i8 %ny
60 call void @extra_use(i8 %nx)
64 define i8 @umin_not_2_extra_use(i8 %x, i8 %y) {
65 ; CHECK-LABEL: @umin_not_2_extra_use(
66 ; CHECK-NEXT: [[NX:%.*]] = xor i8 [[X:%.*]], -1
67 ; CHECK-NEXT: [[NY:%.*]] = xor i8 [[Y:%.*]], -1
68 ; CHECK-NEXT: [[CMPXY:%.*]] = icmp ult i8 [[NX]], [[NY]]
69 ; CHECK-NEXT: [[MINXY:%.*]] = select i1 [[CMPXY]], i8 [[NX]], i8 [[NY]]
70 ; CHECK-NEXT: call void @extra_use(i8 [[NX]])
71 ; CHECK-NEXT: call void @extra_use(i8 [[NY]])
72 ; CHECK-NEXT: ret i8 [[MINXY]]
76 %cmpxy = icmp ult i8 %nx, %ny
77 %minxy = select i1 %cmpxy, i8 %nx, i8 %ny
78 call void @extra_use(i8 %nx)
79 call void @extra_use(i8 %ny)
83 ; PR35834 - https://bugs.llvm.org/show_bug.cgi?id=35834
85 define i8 @umin3_not(i8 %x, i8 %y, i8 %z) {
86 ; CHECK-LABEL: @umin3_not(
87 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ugt i8 [[X:%.*]], [[Z:%.*]]
88 ; CHECK-NEXT: [[TMP2:%.*]] = select i1 [[TMP1]], i8 [[X]], i8 [[Z]]
89 ; CHECK-NEXT: [[TMP3:%.*]] = icmp ugt i8 [[TMP2]], [[Y:%.*]]
90 ; CHECK-NEXT: [[R_V:%.*]] = select i1 [[TMP3]], i8 [[TMP2]], i8 [[Y]]
91 ; CHECK-NEXT: [[R:%.*]] = xor i8 [[R_V]], -1
92 ; CHECK-NEXT: ret i8 [[R]]
97 %cmpyx = icmp ult i8 %y, %x
98 %cmpxz = icmp ult i8 %nx, %nz
99 %minxz = select i1 %cmpxz, i8 %nx, i8 %nz
100 %cmpyz = icmp ult i8 %ny, %nz
101 %minyz = select i1 %cmpyz, i8 %ny, i8 %nz
102 %r = select i1 %cmpyx, i8 %minxz, i8 %minyz
106 ; PR35875 - https://bugs.llvm.org/show_bug.cgi?id=35875
108 define i8 @umin3_not_more_uses(i8 %x, i8 %y, i8 %z) {
109 ; CHECK-LABEL: @umin3_not_more_uses(
110 ; CHECK-NEXT: [[NX:%.*]] = xor i8 [[X:%.*]], -1
111 ; CHECK-NEXT: [[NY:%.*]] = xor i8 [[Y:%.*]], -1
112 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ugt i8 [[Z:%.*]], [[X]]
113 ; CHECK-NEXT: [[TMP2:%.*]] = select i1 [[TMP1]], i8 [[Z]], i8 [[X]]
114 ; CHECK-NEXT: [[TMP3:%.*]] = icmp ugt i8 [[TMP2]], [[Y]]
115 ; CHECK-NEXT: [[TMP4:%.*]] = select i1 [[TMP3]], i8 [[TMP2]], i8 [[Y]]
116 ; CHECK-NEXT: [[R:%.*]] = xor i8 [[TMP4]], -1
117 ; CHECK-NEXT: call void @extra_use(i8 [[NX]])
118 ; CHECK-NEXT: call void @extra_use(i8 [[NY]])
119 ; CHECK-NEXT: ret i8 [[R]]
124 %cmpxz = icmp ult i8 %nx, %nz
125 %minxz = select i1 %cmpxz, i8 %nx, i8 %nz
126 %cmpyz = icmp ult i8 %ny, %nz
127 %minyz = select i1 %cmpyz, i8 %ny, i8 %nz
128 %cmpyx = icmp ult i8 %y, %x
129 %r = select i1 %cmpyx, i8 %minxz, i8 %minyz
130 call void @extra_use(i8 %nx)
131 call void @extra_use(i8 %ny)
135 declare void @use8(i8)
137 define i8 @umin3_not_all_ops_extra_uses(i8 %x, i8 %y, i8 %z) {
138 ; CHECK-LABEL: @umin3_not_all_ops_extra_uses(
139 ; CHECK-NEXT: [[XN:%.*]] = xor i8 [[X:%.*]], -1
140 ; CHECK-NEXT: [[YN:%.*]] = xor i8 [[Y:%.*]], -1
141 ; CHECK-NEXT: [[ZN:%.*]] = xor i8 [[Z:%.*]], -1
142 ; CHECK-NEXT: [[CMPXZ:%.*]] = icmp ult i8 [[XN]], [[ZN]]
143 ; CHECK-NEXT: [[MINXZ:%.*]] = select i1 [[CMPXZ]], i8 [[XN]], i8 [[ZN]]
144 ; CHECK-NEXT: [[CMPXYZ:%.*]] = icmp ult i8 [[MINXZ]], [[YN]]
145 ; CHECK-NEXT: [[MINXYZ:%.*]] = select i1 [[CMPXYZ]], i8 [[MINXZ]], i8 [[YN]]
146 ; CHECK-NEXT: call void @use8(i8 [[XN]])
147 ; CHECK-NEXT: call void @use8(i8 [[YN]])
148 ; CHECK-NEXT: call void @use8(i8 [[ZN]])
149 ; CHECK-NEXT: ret i8 [[MINXYZ]]
154 %cmpxz = icmp ult i8 %xn, %zn
155 %minxz = select i1 %cmpxz, i8 %xn, i8 %zn
156 %cmpxyz = icmp ult i8 %minxz, %yn
157 %minxyz = select i1 %cmpxyz, i8 %minxz, i8 %yn
158 call void @use8(i8 %xn)
159 call void @use8(i8 %yn)
160 call void @use8(i8 %zn)
164 define i32 @compute_min_3(i32 %x, i32 %y, i32 %z) {
165 ; CHECK-LABEL: @compute_min_3(
166 ; CHECK-NEXT: [[TMP1:%.*]] = icmp slt i32 [[X:%.*]], [[Y:%.*]]
167 ; CHECK-NEXT: [[TMP2:%.*]] = select i1 [[TMP1]], i32 [[X]], i32 [[Y]]
168 ; CHECK-NEXT: [[TMP3:%.*]] = icmp slt i32 [[TMP2]], [[Z:%.*]]
169 ; CHECK-NEXT: [[TMP4:%.*]] = select i1 [[TMP3]], i32 [[TMP2]], i32 [[Z]]
170 ; CHECK-NEXT: ret i32 [[TMP4]]
172 %not_x = sub i32 -1, %x
173 %not_y = sub i32 -1, %y
174 %not_z = sub i32 -1, %z
175 %cmp_1 = icmp sgt i32 %not_x, %not_y
176 %not_min_1 = select i1 %cmp_1, i32 %not_x, i32 %not_y
177 %cmp_2 = icmp sgt i32 %not_min_1, %not_z
178 %not_min_2 = select i1 %cmp_2, i32 %not_min_1, i32 %not_z
179 %min = sub i32 -1, %not_min_2
183 ; Don't increase the critical path by moving the 'not' op after the 'select'.
185 define i32 @compute_min_arithmetic(i32 %x, i32 %y) {
186 ; CHECK-LABEL: @compute_min_arithmetic(
187 ; CHECK-NEXT: [[NOT_VALUE:%.*]] = sub i32 3, [[X:%.*]]
188 ; CHECK-NEXT: [[NOT_Y:%.*]] = xor i32 [[Y:%.*]], -1
189 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[NOT_VALUE]], [[NOT_Y]]
190 ; CHECK-NEXT: [[NOT_MIN:%.*]] = select i1 [[CMP]], i32 [[NOT_VALUE]], i32 [[NOT_Y]]
191 ; CHECK-NEXT: ret i32 [[NOT_MIN]]
193 %not_value = sub i32 3, %x
194 %not_y = sub i32 -1, %y
195 %cmp = icmp sgt i32 %not_value, %not_y
196 %not_min = select i1 %cmp, i32 %not_value, i32 %not_y
200 declare void @fake_use(i32)
202 define i32 @compute_min_pessimization(i32 %x, i32 %y) {
203 ; CHECK-LABEL: @compute_min_pessimization(
204 ; CHECK-NEXT: [[NOT_VALUE:%.*]] = sub i32 3, [[X:%.*]]
205 ; CHECK-NEXT: call void @fake_use(i32 [[NOT_VALUE]])
206 ; CHECK-NEXT: [[TMP1:%.*]] = add i32 [[X]], -4
207 ; CHECK-NEXT: [[TMP2:%.*]] = icmp slt i32 [[TMP1]], [[Y:%.*]]
208 ; CHECK-NEXT: [[MIN:%.*]] = select i1 [[TMP2]], i32 [[TMP1]], i32 [[Y]]
209 ; CHECK-NEXT: ret i32 [[MIN]]
211 %not_value = sub i32 3, %x
212 call void @fake_use(i32 %not_value)
213 %not_y = sub i32 -1, %y
214 %cmp = icmp sgt i32 %not_value, %not_y
215 %not_min = select i1 %cmp, i32 %not_value, i32 %not_y
216 %min = sub i32 -1, %not_min
220 define i32 @max_of_nots(i32 %x, i32 %y) {
221 ; CHECK-LABEL: @max_of_nots(
222 ; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt i32 [[Y:%.*]], 0
223 ; CHECK-NEXT: [[TMP2:%.*]] = select i1 [[TMP1]], i32 [[Y]], i32 0
224 ; CHECK-NEXT: [[TMP3:%.*]] = icmp slt i32 [[TMP2]], [[X:%.*]]
225 ; CHECK-NEXT: [[TMP4:%.*]] = select i1 [[TMP3]], i32 [[TMP2]], i32 [[X]]
226 ; CHECK-NEXT: [[SMAX96:%.*]] = xor i32 [[TMP4]], -1
227 ; CHECK-NEXT: ret i32 [[SMAX96]]
229 %c0 = icmp sgt i32 %y, 0
230 %xor_y = xor i32 %y, -1
231 %s0 = select i1 %c0, i32 %xor_y, i32 -1
232 %xor_x = xor i32 %x, -1
233 %c1 = icmp slt i32 %s0, %xor_x
234 %smax96 = select i1 %c1, i32 %xor_x, i32 %s0
238 ; negative test case (i.e. can not simplify) : ABS(MIN(NOT x,y))
239 define i32 @abs_of_min_of_not(i32 %x, i32 %y) {
240 ; CHECK-LABEL: @abs_of_min_of_not(
241 ; CHECK-NEXT: [[XORD:%.*]] = xor i32 [[X:%.*]], -1
242 ; CHECK-NEXT: [[YADD:%.*]] = add i32 [[Y:%.*]], 2
243 ; CHECK-NEXT: [[COND_I_NOT:%.*]] = icmp slt i32 [[YADD]], [[XORD]]
244 ; CHECK-NEXT: [[MIN:%.*]] = select i1 [[COND_I_NOT]], i32 [[YADD]], i32 [[XORD]]
245 ; CHECK-NEXT: [[TMP1:%.*]] = call i32 @llvm.abs.i32(i32 [[MIN]], i1 false)
246 ; CHECK-NEXT: ret i32 [[TMP1]]
249 %xord = xor i32 %x, -1
250 %yadd = add i32 %y, 2
251 %cond.i = icmp sge i32 %yadd, %xord
252 %min = select i1 %cond.i, i32 %xord, i32 %yadd
253 %cmp2 = icmp sgt i32 %min, -1
254 %sub = sub i32 0, %min
255 %abs = select i1 %cmp2, i32 %min, i32 %sub
259 define <2 x i32> @max_of_nots_vec(<2 x i32> %x, <2 x i32> %y) {
260 ; CHECK-LABEL: @max_of_nots_vec(
261 ; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt <2 x i32> [[Y:%.*]], zeroinitializer
262 ; CHECK-NEXT: [[TMP2:%.*]] = select <2 x i1> [[TMP1]], <2 x i32> [[Y]], <2 x i32> zeroinitializer
263 ; CHECK-NEXT: [[TMP3:%.*]] = icmp slt <2 x i32> [[TMP2]], [[X:%.*]]
264 ; CHECK-NEXT: [[TMP4:%.*]] = select <2 x i1> [[TMP3]], <2 x i32> [[TMP2]], <2 x i32> [[X]]
265 ; CHECK-NEXT: [[SMAX96:%.*]] = xor <2 x i32> [[TMP4]], <i32 -1, i32 -1>
266 ; CHECK-NEXT: ret <2 x i32> [[SMAX96]]
268 %c0 = icmp sgt <2 x i32> %y, zeroinitializer
269 %xor_y = xor <2 x i32> %y, <i32 -1, i32 -1>
270 %s0 = select <2 x i1> %c0, <2 x i32> %xor_y, <2 x i32> <i32 -1, i32 -1>
271 %xor_x = xor <2 x i32> %x, <i32 -1, i32 -1>
272 %c1 = icmp slt <2 x i32> %s0, %xor_x
273 %smax96 = select <2 x i1> %c1, <2 x i32> %xor_x, <2 x i32> %s0
274 ret <2 x i32> %smax96
277 define <2 x i37> @max_of_nots_weird_type_vec(<2 x i37> %x, <2 x i37> %y) {
278 ; CHECK-LABEL: @max_of_nots_weird_type_vec(
279 ; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt <2 x i37> [[Y:%.*]], zeroinitializer
280 ; CHECK-NEXT: [[TMP2:%.*]] = select <2 x i1> [[TMP1]], <2 x i37> [[Y]], <2 x i37> zeroinitializer
281 ; CHECK-NEXT: [[TMP3:%.*]] = icmp slt <2 x i37> [[TMP2]], [[X:%.*]]
282 ; CHECK-NEXT: [[TMP4:%.*]] = select <2 x i1> [[TMP3]], <2 x i37> [[TMP2]], <2 x i37> [[X]]
283 ; CHECK-NEXT: [[SMAX96:%.*]] = xor <2 x i37> [[TMP4]], <i37 -1, i37 -1>
284 ; CHECK-NEXT: ret <2 x i37> [[SMAX96]]
286 %c0 = icmp sgt <2 x i37> %y, zeroinitializer
287 %xor_y = xor <2 x i37> %y, <i37 -1, i37 -1>
288 %s0 = select <2 x i1> %c0, <2 x i37> %xor_y, <2 x i37> <i37 -1, i37 -1>
289 %xor_x = xor <2 x i37> %x, <i37 -1, i37 -1>
290 %c1 = icmp slt <2 x i37> %s0, %xor_x
291 %smax96 = select <2 x i1> %c1, <2 x i37> %xor_x, <2 x i37> %s0
292 ret <2 x i37> %smax96
295 ; max(min(%a, -1), -1) == -1
296 define i32 @max_of_min(i32 %a) {
297 ; CHECK-LABEL: @max_of_min(
298 ; CHECK-NEXT: ret i32 -1
300 %not_a = xor i32 %a, -1
301 %c0 = icmp sgt i32 %a, 0
302 %s0 = select i1 %c0, i32 %not_a, i32 -1
303 %c1 = icmp sgt i32 %s0, -1
304 %s1 = select i1 %c1, i32 %s0, i32 -1
308 ; max(min(%a, -1), -1) == -1 (swap predicate and select ops)
309 define i32 @max_of_min_swap(i32 %a) {
310 ; CHECK-LABEL: @max_of_min_swap(
311 ; CHECK-NEXT: ret i32 -1
313 %not_a = xor i32 %a, -1
314 %c0 = icmp slt i32 %a, 0
315 %s0 = select i1 %c0, i32 -1, i32 %not_a
316 %c1 = icmp sgt i32 %s0, -1
317 %s1 = select i1 %c1, i32 %s0, i32 -1
321 ; min(max(%a, -1), -1) == -1
322 define i32 @min_of_max(i32 %a) {
323 ; CHECK-LABEL: @min_of_max(
324 ; CHECK-NEXT: ret i32 -1
326 %not_a = xor i32 %a, -1
327 %c0 = icmp slt i32 %a, 0
328 %s0 = select i1 %c0, i32 %not_a, i32 -1
329 %c1 = icmp slt i32 %s0, -1
330 %s1 = select i1 %c1, i32 %s0, i32 -1
334 ; min(max(%a, -1), -1) == -1 (swap predicate and select ops)
335 define i32 @min_of_max_swap(i32 %a) {
336 ; CHECK-LABEL: @min_of_max_swap(
337 ; CHECK-NEXT: ret i32 -1
339 %not_a = xor i32 %a, -1
340 %c0 = icmp sgt i32 %a, 0
341 %s0 = select i1 %c0, i32 -1, i32 %not_a
342 %c1 = icmp slt i32 %s0, -1
343 %s1 = select i1 %c1, i32 %s0, i32 -1
347 define <2 x i32> @max_of_min_vec(<2 x i32> %a) {
348 ; CHECK-LABEL: @max_of_min_vec(
349 ; CHECK-NEXT: ret <2 x i32> <i32 -1, i32 -1>
351 %not_a = xor <2 x i32> %a, <i32 -1, i32 -1>
352 %c0 = icmp sgt <2 x i32> %a, zeroinitializer
353 %s0 = select <2 x i1> %c0, <2 x i32> %not_a, <2 x i32> <i32 -1, i32 -1>
354 %c1 = icmp sgt <2 x i32> %s0, <i32 -1, i32 -1>
355 %s1 = select <2 x i1> %c1, <2 x i32> %s0, <2 x i32> <i32 -1, i32 -1>
359 declare void @use(i8, i8, i8, i8)
361 define void @cmyk(i8 %r, i8 %g, i8 %b) {
362 ; CHECK-LABEL: @cmyk(
363 ; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt i8 [[R:%.*]], [[B:%.*]]
364 ; CHECK-NEXT: [[TMP2:%.*]] = select i1 [[TMP1]], i8 [[R]], i8 [[B]]
365 ; CHECK-NEXT: [[TMP3:%.*]] = icmp sgt i8 [[TMP2]], [[G:%.*]]
366 ; CHECK-NEXT: [[TMP4:%.*]] = select i1 [[TMP3]], i8 [[TMP2]], i8 [[G]]
367 ; CHECK-NEXT: [[TMP5:%.*]] = xor i8 [[TMP4]], -1
368 ; CHECK-NEXT: [[CK:%.*]] = sub i8 [[TMP4]], [[R]]
369 ; CHECK-NEXT: [[MK:%.*]] = sub i8 [[TMP4]], [[G]]
370 ; CHECK-NEXT: [[YK:%.*]] = sub i8 [[TMP4]], [[B]]
371 ; CHECK-NEXT: call void @use(i8 [[CK]], i8 [[MK]], i8 [[YK]], i8 [[TMP5]])
372 ; CHECK-NEXT: ret void
374 %notr = xor i8 %r, -1
375 %notg = xor i8 %g, -1
376 %notb = xor i8 %b, -1
377 %cmp_gr = icmp slt i8 %g, %r
378 %cmp_br = icmp slt i8 %notr, %notb
379 %min_br = select i1 %cmp_br, i8 %notr, i8 %notb
380 %cmp_gb = icmp slt i8 %notg, %notb
381 %min_gb = select i1 %cmp_gb, i8 %notg, i8 %notb
382 %k = select i1 %cmp_gr, i8 %min_br, i8 %min_gb
383 %ck = sub i8 %notr, %k
384 %mk = sub i8 %notg, %k
385 %yk = sub i8 %notb, %k
386 call void @use(i8 %ck, i8 %mk, i8 %yk, i8 %k)
390 define void @cmyk2(i8 %r, i8 %g, i8 %b) {
391 ; CHECK-LABEL: @cmyk2(
392 ; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt i8 [[R:%.*]], [[B:%.*]]
393 ; CHECK-NEXT: [[TMP2:%.*]] = select i1 [[TMP1]], i8 [[R]], i8 [[B]]
394 ; CHECK-NEXT: [[TMP3:%.*]] = icmp sgt i8 [[TMP2]], [[G:%.*]]
395 ; CHECK-NEXT: [[K_V:%.*]] = select i1 [[TMP3]], i8 [[TMP2]], i8 [[G]]
396 ; CHECK-NEXT: [[K:%.*]] = xor i8 [[K_V]], -1
397 ; CHECK-NEXT: [[CK:%.*]] = sub i8 [[K_V]], [[R]]
398 ; CHECK-NEXT: [[MK:%.*]] = sub i8 [[K_V]], [[G]]
399 ; CHECK-NEXT: [[YK:%.*]] = sub i8 [[K_V]], [[B]]
400 ; CHECK-NEXT: call void @use(i8 [[CK]], i8 [[MK]], i8 [[YK]], i8 [[K]])
401 ; CHECK-NEXT: ret void
403 %notr = xor i8 %r, -1
404 %notg = xor i8 %g, -1
405 %notb = xor i8 %b, -1
406 %cmp_gr = icmp slt i8 %g, %r
407 %cmp_br = icmp slt i8 %b, %r
408 %min_br = select i1 %cmp_br, i8 %notr, i8 %notb
409 %cmp_bg = icmp slt i8 %b, %g
410 %min_bg = select i1 %cmp_bg, i8 %notg, i8 %notb
411 %k = select i1 %cmp_gr, i8 %min_br, i8 %min_bg
412 %ck = sub i8 %notr, %k
413 %mk = sub i8 %notg, %k
414 %yk = sub i8 %notb, %k
415 call void @use(i8 %ck, i8 %mk, i8 %yk, i8 %k)
419 define void @cmyk3(i8 %r, i8 %g, i8 %b) {
420 ; CHECK-LABEL: @cmyk3(
421 ; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt i8 [[R:%.*]], [[B:%.*]]
422 ; CHECK-NEXT: [[TMP2:%.*]] = select i1 [[TMP1]], i8 [[R]], i8 [[B]]
423 ; CHECK-NEXT: [[TMP3:%.*]] = icmp sgt i8 [[TMP2]], [[G:%.*]]
424 ; CHECK-NEXT: [[K_V:%.*]] = select i1 [[TMP3]], i8 [[TMP2]], i8 [[G]]
425 ; CHECK-NEXT: [[K:%.*]] = xor i8 [[K_V]], -1
426 ; CHECK-NEXT: [[CK:%.*]] = sub i8 [[K_V]], [[R]]
427 ; CHECK-NEXT: [[MK:%.*]] = sub i8 [[K_V]], [[G]]
428 ; CHECK-NEXT: [[YK:%.*]] = sub i8 [[K_V]], [[B]]
429 ; CHECK-NEXT: call void @use(i8 [[CK]], i8 [[MK]], i8 [[YK]], i8 [[K]])
430 ; CHECK-NEXT: ret void
432 %notr = xor i8 %r, -1
433 %notg = xor i8 %g, -1
434 %notb = xor i8 %b, -1
435 %cmp_gr = icmp slt i8 %g, %r
436 %cmp_br = icmp sgt i8 %r, %b
437 %min_br = select i1 %cmp_br, i8 %notr, i8 %notb
438 %cmp_bg = icmp slt i8 %b, %g
439 %min_bg = select i1 %cmp_bg, i8 %notg, i8 %notb
440 %k = select i1 %cmp_gr, i8 %min_br, i8 %min_bg
441 %ck = sub i8 %notr, %k
442 %mk = sub i8 %notg, %k
443 %yk = sub i8 %notb, %k
444 call void @use(i8 %ck, i8 %mk, i8 %yk, i8 %k)
448 define void @cmyk4(i8 %r, i8 %g, i8 %b) {
449 ; CHECK-LABEL: @cmyk4(
450 ; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt i8 [[R:%.*]], [[B:%.*]]
451 ; CHECK-NEXT: [[TMP2:%.*]] = select i1 [[TMP1]], i8 [[R]], i8 [[B]]
452 ; CHECK-NEXT: [[TMP3:%.*]] = icmp sgt i8 [[TMP2]], [[G:%.*]]
453 ; CHECK-NEXT: [[K_V:%.*]] = select i1 [[TMP3]], i8 [[TMP2]], i8 [[G]]
454 ; CHECK-NEXT: [[K:%.*]] = xor i8 [[K_V]], -1
455 ; CHECK-NEXT: [[CK:%.*]] = sub i8 [[K_V]], [[R]]
456 ; CHECK-NEXT: [[MK:%.*]] = sub i8 [[K_V]], [[G]]
457 ; CHECK-NEXT: [[YK:%.*]] = sub i8 [[K_V]], [[B]]
458 ; CHECK-NEXT: call void @use(i8 [[CK]], i8 [[MK]], i8 [[YK]], i8 [[K]])
459 ; CHECK-NEXT: ret void
461 %notr = xor i8 %r, -1
462 %notg = xor i8 %g, -1
463 %notb = xor i8 %b, -1
464 %cmp_gr = icmp slt i8 %g, %r
465 %cmp_br = icmp sgt i8 %r, %b
466 %min_br = select i1 %cmp_br, i8 %notr, i8 %notb
467 %cmp_bg = icmp sgt i8 %g, %b
468 %min_bg = select i1 %cmp_bg, i8 %notg, i8 %notb
469 %k = select i1 %cmp_gr, i8 %min_br, i8 %min_bg
470 %ck = sub i8 %notr, %k
471 %mk = sub i8 %notg, %k
472 %yk = sub i8 %notb, %k
473 call void @use(i8 %ck, i8 %mk, i8 %yk, i8 %k)
477 define void @cmyk5(i8 %r, i8 %g, i8 %b) {
478 ; CHECK-LABEL: @cmyk5(
479 ; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt i8 [[R:%.*]], [[B:%.*]]
480 ; CHECK-NEXT: [[TMP2:%.*]] = select i1 [[TMP1]], i8 [[R]], i8 [[B]]
481 ; CHECK-NEXT: [[TMP3:%.*]] = icmp sgt i8 [[TMP2]], [[G:%.*]]
482 ; CHECK-NEXT: [[K_V:%.*]] = select i1 [[TMP3]], i8 [[TMP2]], i8 [[G]]
483 ; CHECK-NEXT: [[K:%.*]] = xor i8 [[K_V]], -1
484 ; CHECK-NEXT: [[CK:%.*]] = sub i8 [[K_V]], [[R]]
485 ; CHECK-NEXT: [[MK:%.*]] = sub i8 [[K_V]], [[G]]
486 ; CHECK-NEXT: [[YK:%.*]] = sub i8 [[K_V]], [[B]]
487 ; CHECK-NEXT: call void @use(i8 [[CK]], i8 [[MK]], i8 [[YK]], i8 [[K]])
488 ; CHECK-NEXT: ret void
490 %notr = xor i8 %r, -1
491 %notg = xor i8 %g, -1
492 %notb = xor i8 %b, -1
493 %cmp_gr = icmp sgt i8 %r, %g
494 %cmp_br = icmp sgt i8 %r, %b
495 %min_br = select i1 %cmp_br, i8 %notr, i8 %notb
496 %cmp_bg = icmp sgt i8 %g, %b
497 %min_bg = select i1 %cmp_bg, i8 %notg, i8 %notb
498 %k = select i1 %cmp_gr, i8 %min_br, i8 %min_bg
499 %ck = sub i8 %notr, %k
500 %mk = sub i8 %notg, %k
501 %yk = sub i8 %notb, %k
502 call void @use(i8 %ck, i8 %mk, i8 %yk, i8 %k)
506 define void @cmyk6(i8 %r, i8 %g, i8 %b) {
507 ; CHECK-LABEL: @cmyk6(
508 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ugt i8 [[R:%.*]], [[B:%.*]]
509 ; CHECK-NEXT: [[TMP2:%.*]] = select i1 [[TMP1]], i8 [[R]], i8 [[B]]
510 ; CHECK-NEXT: [[TMP3:%.*]] = icmp ugt i8 [[TMP2]], [[G:%.*]]
511 ; CHECK-NEXT: [[K_V:%.*]] = select i1 [[TMP3]], i8 [[TMP2]], i8 [[G]]
512 ; CHECK-NEXT: [[K:%.*]] = xor i8 [[K_V]], -1
513 ; CHECK-NEXT: [[CK:%.*]] = sub i8 [[K_V]], [[R]]
514 ; CHECK-NEXT: [[MK:%.*]] = sub i8 [[K_V]], [[G]]
515 ; CHECK-NEXT: [[YK:%.*]] = sub i8 [[K_V]], [[B]]
516 ; CHECK-NEXT: tail call void @use(i8 [[CK]], i8 [[MK]], i8 [[YK]], i8 [[K]])
517 ; CHECK-NEXT: ret void
519 %notr = xor i8 %r, -1
520 %notg = xor i8 %g, -1
521 %notb = xor i8 %b, -1
522 %cmp_gr = icmp ult i8 %g, %r
523 %cmp_br = icmp ult i8 %b, %r
524 %sel_rb = select i1 %cmp_br, i8 %notr, i8 %notb
525 %cmp_bg = icmp ult i8 %b, %g
526 %sel_gb = select i1 %cmp_bg, i8 %notg, i8 %notb
527 %k = select i1 %cmp_gr, i8 %sel_rb, i8 %sel_gb
528 %ck = sub i8 %notr, %k
529 %mk = sub i8 %notg, %k
530 %yk = sub i8 %notb, %k
531 tail call void @use(i8 %ck, i8 %mk, i8 %yk, i8 %k)