1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc < %s -mtriple=powerpc64le-- -verify-machineinstrs | FileCheck %s
4 ; There are at least 3 potential patterns corresponding to an unsigned saturated add: min, cmp with sum, cmp with not.
5 ; Test each of those patterns with i8/i16/i32/i64.
6 ; Test each of those with a constant operand and a variable operand.
7 ; Test each of those with a 128-bit vector type.
9 define i8 @unsigned_sat_constant_i8_using_min(i8 %x) {
10 ; CHECK-LABEL: unsigned_sat_constant_i8_using_min:
12 ; CHECK-NEXT: clrlwi 5, 3, 24
13 ; CHECK-NEXT: li 4, -43
14 ; CHECK-NEXT: cmplwi 5, 213
15 ; CHECK-NEXT: isellt 3, 3, 4
16 ; CHECK-NEXT: addi 3, 3, 42
18 %c = icmp ult i8 %x, -43
19 %s = select i1 %c, i8 %x, i8 -43
24 define i8 @unsigned_sat_constant_i8_using_cmp_sum(i8 %x) {
25 ; CHECK-LABEL: unsigned_sat_constant_i8_using_cmp_sum:
27 ; CHECK-NEXT: clrlwi 3, 3, 24
28 ; CHECK-NEXT: addi 3, 3, 42
29 ; CHECK-NEXT: andi. 4, 3, 256
30 ; CHECK-NEXT: li 4, -1
31 ; CHECK-NEXT: iseleq 3, 3, 4
34 %c = icmp ugt i8 %x, %a
35 %r = select i1 %c, i8 -1, i8 %a
39 define i8 @unsigned_sat_constant_i8_using_cmp_notval(i8 %x) {
40 ; CHECK-LABEL: unsigned_sat_constant_i8_using_cmp_notval:
42 ; CHECK-NEXT: clrlwi 5, 3, 24
43 ; CHECK-NEXT: li 4, -1
44 ; CHECK-NEXT: addi 3, 3, 42
45 ; CHECK-NEXT: cmplwi 5, 213
46 ; CHECK-NEXT: iselgt 3, 4, 3
49 %c = icmp ugt i8 %x, -43
50 %r = select i1 %c, i8 -1, i8 %a
54 define i16 @unsigned_sat_constant_i16_using_min(i16 %x) {
55 ; CHECK-LABEL: unsigned_sat_constant_i16_using_min:
57 ; CHECK-NEXT: clrlwi 5, 3, 16
58 ; CHECK-NEXT: li 4, -43
59 ; CHECK-NEXT: cmplwi 5, 65493
60 ; CHECK-NEXT: isellt 3, 3, 4
61 ; CHECK-NEXT: addi 3, 3, 42
63 %c = icmp ult i16 %x, -43
64 %s = select i1 %c, i16 %x, i16 -43
69 define i16 @unsigned_sat_constant_i16_using_cmp_sum(i16 %x) {
70 ; CHECK-LABEL: unsigned_sat_constant_i16_using_cmp_sum:
72 ; CHECK-NEXT: clrlwi 3, 3, 16
73 ; CHECK-NEXT: addi 3, 3, 42
74 ; CHECK-NEXT: andis. 4, 3, 1
75 ; CHECK-NEXT: li 4, -1
76 ; CHECK-NEXT: iseleq 3, 3, 4
79 %c = icmp ugt i16 %x, %a
80 %r = select i1 %c, i16 -1, i16 %a
84 define i16 @unsigned_sat_constant_i16_using_cmp_notval(i16 %x) {
85 ; CHECK-LABEL: unsigned_sat_constant_i16_using_cmp_notval:
87 ; CHECK-NEXT: clrlwi 5, 3, 16
88 ; CHECK-NEXT: li 4, -1
89 ; CHECK-NEXT: addi 3, 3, 42
90 ; CHECK-NEXT: cmplwi 5, 65493
91 ; CHECK-NEXT: iselgt 3, 4, 3
94 %c = icmp ugt i16 %x, -43
95 %r = select i1 %c, i16 -1, i16 %a
99 define i32 @unsigned_sat_constant_i32_using_min(i32 %x) {
100 ; CHECK-LABEL: unsigned_sat_constant_i32_using_min:
102 ; CHECK-NEXT: li 4, -43
103 ; CHECK-NEXT: cmplw 3, 4
104 ; CHECK-NEXT: isellt 3, 3, 4
105 ; CHECK-NEXT: addi 3, 3, 42
107 %c = icmp ult i32 %x, -43
108 %s = select i1 %c, i32 %x, i32 -43
113 define i32 @unsigned_sat_constant_i32_using_cmp_sum(i32 %x) {
114 ; CHECK-LABEL: unsigned_sat_constant_i32_using_cmp_sum:
116 ; CHECK-NEXT: addi 5, 3, 42
117 ; CHECK-NEXT: li 4, -1
118 ; CHECK-NEXT: cmplw 5, 3
119 ; CHECK-NEXT: isellt 3, 4, 5
122 %c = icmp ugt i32 %x, %a
123 %r = select i1 %c, i32 -1, i32 %a
127 define i32 @unsigned_sat_constant_i32_using_cmp_notval(i32 %x) {
128 ; CHECK-LABEL: unsigned_sat_constant_i32_using_cmp_notval:
130 ; CHECK-NEXT: li 4, -43
131 ; CHECK-NEXT: addi 5, 3, 42
132 ; CHECK-NEXT: cmplw 3, 4
133 ; CHECK-NEXT: li 3, -1
134 ; CHECK-NEXT: iselgt 3, 3, 5
137 %c = icmp ugt i32 %x, -43
138 %r = select i1 %c, i32 -1, i32 %a
142 define i64 @unsigned_sat_constant_i64_using_min(i64 %x) {
143 ; CHECK-LABEL: unsigned_sat_constant_i64_using_min:
145 ; CHECK-NEXT: li 4, -43
146 ; CHECK-NEXT: cmpld 3, 4
147 ; CHECK-NEXT: isellt 3, 3, 4
148 ; CHECK-NEXT: addi 3, 3, 42
150 %c = icmp ult i64 %x, -43
151 %s = select i1 %c, i64 %x, i64 -43
156 define i64 @unsigned_sat_constant_i64_using_cmp_sum(i64 %x) {
157 ; CHECK-LABEL: unsigned_sat_constant_i64_using_cmp_sum:
159 ; CHECK-NEXT: addi 5, 3, 42
160 ; CHECK-NEXT: li 4, -1
161 ; CHECK-NEXT: cmpld 5, 3
162 ; CHECK-NEXT: isellt 3, 4, 5
165 %c = icmp ugt i64 %x, %a
166 %r = select i1 %c, i64 -1, i64 %a
170 define i64 @unsigned_sat_constant_i64_using_cmp_notval(i64 %x) {
171 ; CHECK-LABEL: unsigned_sat_constant_i64_using_cmp_notval:
173 ; CHECK-NEXT: li 4, -43
174 ; CHECK-NEXT: addi 5, 3, 42
175 ; CHECK-NEXT: cmpld 3, 4
176 ; CHECK-NEXT: li 3, -1
177 ; CHECK-NEXT: iselgt 3, 3, 5
180 %c = icmp ugt i64 %x, -43
181 %r = select i1 %c, i64 -1, i64 %a
185 define i8 @unsigned_sat_variable_i8_using_min(i8 %x, i8 %y) {
186 ; CHECK-LABEL: unsigned_sat_variable_i8_using_min:
188 ; CHECK-NEXT: not 5, 4
189 ; CHECK-NEXT: clrlwi 6, 3, 24
190 ; CHECK-NEXT: clrlwi 7, 5, 24
191 ; CHECK-NEXT: cmplw 6, 7
192 ; CHECK-NEXT: isellt 3, 3, 5
193 ; CHECK-NEXT: add 3, 3, 4
195 %noty = xor i8 %y, -1
196 %c = icmp ult i8 %x, %noty
197 %s = select i1 %c, i8 %x, i8 %noty
202 define i8 @unsigned_sat_variable_i8_using_cmp_sum(i8 %x, i8 %y) {
203 ; CHECK-LABEL: unsigned_sat_variable_i8_using_cmp_sum:
205 ; CHECK-NEXT: clrlwi 4, 4, 24
206 ; CHECK-NEXT: clrlwi 3, 3, 24
207 ; CHECK-NEXT: add 3, 3, 4
208 ; CHECK-NEXT: andi. 4, 3, 256
209 ; CHECK-NEXT: li 4, -1
210 ; CHECK-NEXT: iseleq 3, 3, 4
213 %c = icmp ugt i8 %x, %a
214 %r = select i1 %c, i8 -1, i8 %a
218 define i8 @unsigned_sat_variable_i8_using_cmp_notval(i8 %x, i8 %y) {
219 ; CHECK-LABEL: unsigned_sat_variable_i8_using_cmp_notval:
221 ; CHECK-NEXT: not 6, 4
222 ; CHECK-NEXT: clrlwi 7, 3, 24
223 ; CHECK-NEXT: li 5, -1
224 ; CHECK-NEXT: add 3, 3, 4
225 ; CHECK-NEXT: clrlwi 6, 6, 24
226 ; CHECK-NEXT: cmplw 7, 6
227 ; CHECK-NEXT: iselgt 3, 5, 3
229 %noty = xor i8 %y, -1
231 %c = icmp ugt i8 %x, %noty
232 %r = select i1 %c, i8 -1, i8 %a
236 define i16 @unsigned_sat_variable_i16_using_min(i16 %x, i16 %y) {
237 ; CHECK-LABEL: unsigned_sat_variable_i16_using_min:
239 ; CHECK-NEXT: not 5, 4
240 ; CHECK-NEXT: clrlwi 6, 3, 16
241 ; CHECK-NEXT: clrlwi 7, 5, 16
242 ; CHECK-NEXT: cmplw 6, 7
243 ; CHECK-NEXT: isellt 3, 3, 5
244 ; CHECK-NEXT: add 3, 3, 4
246 %noty = xor i16 %y, -1
247 %c = icmp ult i16 %x, %noty
248 %s = select i1 %c, i16 %x, i16 %noty
253 define i16 @unsigned_sat_variable_i16_using_cmp_sum(i16 %x, i16 %y) {
254 ; CHECK-LABEL: unsigned_sat_variable_i16_using_cmp_sum:
256 ; CHECK-NEXT: clrlwi 4, 4, 16
257 ; CHECK-NEXT: clrlwi 3, 3, 16
258 ; CHECK-NEXT: add 3, 3, 4
259 ; CHECK-NEXT: andis. 4, 3, 1
260 ; CHECK-NEXT: li 4, -1
261 ; CHECK-NEXT: iseleq 3, 3, 4
264 %c = icmp ugt i16 %x, %a
265 %r = select i1 %c, i16 -1, i16 %a
269 define i16 @unsigned_sat_variable_i16_using_cmp_notval(i16 %x, i16 %y) {
270 ; CHECK-LABEL: unsigned_sat_variable_i16_using_cmp_notval:
272 ; CHECK-NEXT: not 6, 4
273 ; CHECK-NEXT: clrlwi 7, 3, 16
274 ; CHECK-NEXT: li 5, -1
275 ; CHECK-NEXT: add 3, 3, 4
276 ; CHECK-NEXT: clrlwi 6, 6, 16
277 ; CHECK-NEXT: cmplw 7, 6
278 ; CHECK-NEXT: iselgt 3, 5, 3
280 %noty = xor i16 %y, -1
282 %c = icmp ugt i16 %x, %noty
283 %r = select i1 %c, i16 -1, i16 %a
287 define i32 @unsigned_sat_variable_i32_using_min(i32 %x, i32 %y) {
288 ; CHECK-LABEL: unsigned_sat_variable_i32_using_min:
290 ; CHECK-NEXT: not 5, 4
291 ; CHECK-NEXT: cmplw 3, 5
292 ; CHECK-NEXT: isellt 3, 3, 5
293 ; CHECK-NEXT: add 3, 3, 4
295 %noty = xor i32 %y, -1
296 %c = icmp ult i32 %x, %noty
297 %s = select i1 %c, i32 %x, i32 %noty
302 define i32 @unsigned_sat_variable_i32_using_cmp_sum(i32 %x, i32 %y) {
303 ; CHECK-LABEL: unsigned_sat_variable_i32_using_cmp_sum:
305 ; CHECK-NEXT: add 4, 3, 4
306 ; CHECK-NEXT: li 5, -1
307 ; CHECK-NEXT: cmplw 4, 3
308 ; CHECK-NEXT: isellt 3, 5, 4
311 %c = icmp ugt i32 %x, %a
312 %r = select i1 %c, i32 -1, i32 %a
316 define i32 @unsigned_sat_variable_i32_using_cmp_notval(i32 %x, i32 %y) {
317 ; CHECK-LABEL: unsigned_sat_variable_i32_using_cmp_notval:
319 ; CHECK-NEXT: not 6, 4
320 ; CHECK-NEXT: li 5, -1
321 ; CHECK-NEXT: cmplw 3, 6
322 ; CHECK-NEXT: add 3, 3, 4
323 ; CHECK-NEXT: iselgt 3, 5, 3
325 %noty = xor i32 %y, -1
327 %c = icmp ugt i32 %x, %noty
328 %r = select i1 %c, i32 -1, i32 %a
332 define i64 @unsigned_sat_variable_i64_using_min(i64 %x, i64 %y) {
333 ; CHECK-LABEL: unsigned_sat_variable_i64_using_min:
335 ; CHECK-NEXT: not 5, 4
336 ; CHECK-NEXT: cmpld 3, 5
337 ; CHECK-NEXT: isellt 3, 3, 5
338 ; CHECK-NEXT: add 3, 3, 4
340 %noty = xor i64 %y, -1
341 %c = icmp ult i64 %x, %noty
342 %s = select i1 %c, i64 %x, i64 %noty
347 define i64 @unsigned_sat_variable_i64_using_cmp_sum(i64 %x, i64 %y) {
348 ; CHECK-LABEL: unsigned_sat_variable_i64_using_cmp_sum:
350 ; CHECK-NEXT: add 4, 3, 4
351 ; CHECK-NEXT: li 5, -1
352 ; CHECK-NEXT: cmpld 4, 3
353 ; CHECK-NEXT: isellt 3, 5, 4
356 %c = icmp ugt i64 %x, %a
357 %r = select i1 %c, i64 -1, i64 %a
361 define i64 @unsigned_sat_variable_i64_using_cmp_notval(i64 %x, i64 %y) {
362 ; CHECK-LABEL: unsigned_sat_variable_i64_using_cmp_notval:
364 ; CHECK-NEXT: not 6, 4
365 ; CHECK-NEXT: li 5, -1
366 ; CHECK-NEXT: cmpld 3, 6
367 ; CHECK-NEXT: add 3, 3, 4
368 ; CHECK-NEXT: iselgt 3, 5, 3
370 %noty = xor i64 %y, -1
372 %c = icmp ugt i64 %x, %noty
373 %r = select i1 %c, i64 -1, i64 %a
377 define <16 x i8> @unsigned_sat_constant_v16i8_using_min(<16 x i8> %x) {
378 ; CHECK-LABEL: unsigned_sat_constant_v16i8_using_min:
380 ; CHECK-NEXT: addis 3, 2, .LCPI24_0@toc@ha
381 ; CHECK-NEXT: addi 3, 3, .LCPI24_0@toc@l
382 ; CHECK-NEXT: lxvd2x 35, 0, 3
383 ; CHECK-NEXT: addis 3, 2, .LCPI24_1@toc@ha
384 ; CHECK-NEXT: addi 3, 3, .LCPI24_1@toc@l
385 ; CHECK-NEXT: vminub 2, 2, 3
386 ; CHECK-NEXT: lxvd2x 35, 0, 3
387 ; CHECK-NEXT: vaddubm 2, 2, 3
389 %c = icmp ult <16 x i8> %x, <i8 -43, i8 -43, i8 -43, i8 -43, i8 -43, i8 -43, i8 -43, i8 -43, i8 -43, i8 -43, i8 -43, i8 -43, i8 -43, i8 -43, i8 -43, i8 -43>
390 %s = select <16 x i1> %c, <16 x i8> %x, <16 x i8> <i8 -43, i8 -43, i8 -43, i8 -43, i8 -43, i8 -43, i8 -43, i8 -43, i8 -43, i8 -43, i8 -43, i8 -43, i8 -43, i8 -43, i8 -43, i8 -43>
391 %r = add <16 x i8> %s, <i8 42, i8 42, i8 42, i8 42, i8 42, i8 42, i8 42, i8 42, i8 42, i8 42, i8 42, i8 42, i8 42, i8 42, i8 42, i8 42>
395 define <16 x i8> @unsigned_sat_constant_v16i8_using_cmp_sum(<16 x i8> %x) {
396 ; CHECK-LABEL: unsigned_sat_constant_v16i8_using_cmp_sum:
398 ; CHECK-NEXT: addis 3, 2, .LCPI25_0@toc@ha
399 ; CHECK-NEXT: addi 3, 3, .LCPI25_0@toc@l
400 ; CHECK-NEXT: lxvd2x 35, 0, 3
401 ; CHECK-NEXT: vaddubs 2, 2, 3
403 %a = add <16 x i8> %x, <i8 42, i8 42, i8 42, i8 42, i8 42, i8 42, i8 42, i8 42, i8 42, i8 42, i8 42, i8 42, i8 42, i8 42, i8 42, i8 42>
404 %c = icmp ugt <16 x i8> %x, %a
405 %r = select <16 x i1> %c, <16 x i8> <i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1>, <16 x i8> %a
409 define <16 x i8> @unsigned_sat_constant_v16i8_using_cmp_notval(<16 x i8> %x) {
410 ; CHECK-LABEL: unsigned_sat_constant_v16i8_using_cmp_notval:
412 ; CHECK-NEXT: addis 3, 2, .LCPI26_0@toc@ha
413 ; CHECK-NEXT: addi 3, 3, .LCPI26_0@toc@l
414 ; CHECK-NEXT: lxvd2x 35, 0, 3
415 ; CHECK-NEXT: vaddubs 2, 2, 3
417 %a = add <16 x i8> %x, <i8 42, i8 42, i8 42, i8 42, i8 42, i8 42, i8 42, i8 42, i8 42, i8 42, i8 42, i8 42, i8 42, i8 42, i8 42, i8 42>
418 %c = icmp ugt <16 x i8> %x, <i8 -43, i8 -43, i8 -43, i8 -43, i8 -43, i8 -43, i8 -43, i8 -43, i8 -43, i8 -43, i8 -43, i8 -43, i8 -43, i8 -43, i8 -43, i8 -43>
419 %r = select <16 x i1> %c, <16 x i8> <i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1>, <16 x i8> %a
423 define <8 x i16> @unsigned_sat_constant_v8i16_using_min(<8 x i16> %x) {
424 ; CHECK-LABEL: unsigned_sat_constant_v8i16_using_min:
426 ; CHECK-NEXT: addis 3, 2, .LCPI27_0@toc@ha
427 ; CHECK-NEXT: addi 3, 3, .LCPI27_0@toc@l
428 ; CHECK-NEXT: lxvd2x 35, 0, 3
429 ; CHECK-NEXT: addis 3, 2, .LCPI27_1@toc@ha
430 ; CHECK-NEXT: addi 3, 3, .LCPI27_1@toc@l
431 ; CHECK-NEXT: vminuh 2, 2, 3
432 ; CHECK-NEXT: lxvd2x 35, 0, 3
433 ; CHECK-NEXT: vadduhm 2, 2, 3
435 %c = icmp ult <8 x i16> %x, <i16 -43, i16 -43, i16 -43, i16 -43, i16 -43, i16 -43, i16 -43, i16 -43>
436 %s = select <8 x i1> %c, <8 x i16> %x, <8 x i16> <i16 -43, i16 -43, i16 -43, i16 -43, i16 -43, i16 -43, i16 -43, i16 -43>
437 %r = add <8 x i16> %s, <i16 42, i16 42, i16 42, i16 42, i16 42, i16 42, i16 42, i16 42>
441 define <8 x i16> @unsigned_sat_constant_v8i16_using_cmp_sum(<8 x i16> %x) {
442 ; CHECK-LABEL: unsigned_sat_constant_v8i16_using_cmp_sum:
444 ; CHECK-NEXT: addis 3, 2, .LCPI28_0@toc@ha
445 ; CHECK-NEXT: addi 3, 3, .LCPI28_0@toc@l
446 ; CHECK-NEXT: lxvd2x 35, 0, 3
447 ; CHECK-NEXT: vadduhs 2, 2, 3
449 %a = add <8 x i16> %x, <i16 42, i16 42, i16 42, i16 42, i16 42, i16 42, i16 42, i16 42>
450 %c = icmp ugt <8 x i16> %x, %a
451 %r = select <8 x i1> %c, <8 x i16> <i16 -1, i16 -1, i16 -1, i16 -1, i16 -1, i16 -1, i16 -1, i16 -1>, <8 x i16> %a
455 define <8 x i16> @unsigned_sat_constant_v8i16_using_cmp_notval(<8 x i16> %x) {
456 ; CHECK-LABEL: unsigned_sat_constant_v8i16_using_cmp_notval:
458 ; CHECK-NEXT: addis 3, 2, .LCPI29_0@toc@ha
459 ; CHECK-NEXT: addi 3, 3, .LCPI29_0@toc@l
460 ; CHECK-NEXT: lxvd2x 35, 0, 3
461 ; CHECK-NEXT: vadduhs 2, 2, 3
463 %a = add <8 x i16> %x, <i16 42, i16 42, i16 42, i16 42, i16 42, i16 42, i16 42, i16 42>
464 %c = icmp ugt <8 x i16> %x, <i16 -43, i16 -43, i16 -43, i16 -43, i16 -43, i16 -43, i16 -43, i16 -43>
465 %r = select <8 x i1> %c, <8 x i16> <i16 -1, i16 -1, i16 -1, i16 -1, i16 -1, i16 -1, i16 -1, i16 -1>, <8 x i16> %a
469 define <4 x i32> @unsigned_sat_constant_v4i32_using_min(<4 x i32> %x) {
470 ; CHECK-LABEL: unsigned_sat_constant_v4i32_using_min:
472 ; CHECK-NEXT: addis 3, 2, .LCPI30_0@toc@ha
473 ; CHECK-NEXT: addi 3, 3, .LCPI30_0@toc@l
474 ; CHECK-NEXT: lxvd2x 35, 0, 3
475 ; CHECK-NEXT: addis 3, 2, .LCPI30_1@toc@ha
476 ; CHECK-NEXT: addi 3, 3, .LCPI30_1@toc@l
477 ; CHECK-NEXT: vminuw 2, 2, 3
478 ; CHECK-NEXT: lxvd2x 35, 0, 3
479 ; CHECK-NEXT: vadduwm 2, 2, 3
481 %c = icmp ult <4 x i32> %x, <i32 -43, i32 -43, i32 -43, i32 -43>
482 %s = select <4 x i1> %c, <4 x i32> %x, <4 x i32> <i32 -43, i32 -43, i32 -43, i32 -43>
483 %r = add <4 x i32> %s, <i32 42, i32 42, i32 42, i32 42>
487 define <4 x i32> @unsigned_sat_constant_v4i32_using_cmp_sum(<4 x i32> %x) {
488 ; CHECK-LABEL: unsigned_sat_constant_v4i32_using_cmp_sum:
490 ; CHECK-NEXT: addis 3, 2, .LCPI31_0@toc@ha
491 ; CHECK-NEXT: addi 3, 3, .LCPI31_0@toc@l
492 ; CHECK-NEXT: lxvd2x 35, 0, 3
493 ; CHECK-NEXT: vadduws 2, 2, 3
495 %a = add <4 x i32> %x, <i32 42, i32 42, i32 42, i32 42>
496 %c = icmp ugt <4 x i32> %x, %a
497 %r = select <4 x i1> %c, <4 x i32> <i32 -1, i32 -1, i32 -1, i32 -1>, <4 x i32> %a
501 define <4 x i32> @unsigned_sat_constant_v4i32_using_cmp_notval(<4 x i32> %x) {
502 ; CHECK-LABEL: unsigned_sat_constant_v4i32_using_cmp_notval:
504 ; CHECK-NEXT: addis 3, 2, .LCPI32_0@toc@ha
505 ; CHECK-NEXT: addi 3, 3, .LCPI32_0@toc@l
506 ; CHECK-NEXT: lxvd2x 35, 0, 3
507 ; CHECK-NEXT: vadduws 2, 2, 3
509 %a = add <4 x i32> %x, <i32 42, i32 42, i32 42, i32 42>
510 %c = icmp ugt <4 x i32> %x, <i32 -43, i32 -43, i32 -43, i32 -43>
511 %r = select <4 x i1> %c, <4 x i32> <i32 -1, i32 -1, i32 -1, i32 -1>, <4 x i32> %a
515 define <2 x i64> @unsigned_sat_constant_v2i64_using_min(<2 x i64> %x) {
516 ; CHECK-LABEL: unsigned_sat_constant_v2i64_using_min:
518 ; CHECK-NEXT: addis 3, 2, .LCPI33_0@toc@ha
519 ; CHECK-NEXT: addi 3, 3, .LCPI33_0@toc@l
520 ; CHECK-NEXT: lxvd2x 35, 0, 3
521 ; CHECK-NEXT: addis 3, 2, .LCPI33_1@toc@ha
522 ; CHECK-NEXT: addi 3, 3, .LCPI33_1@toc@l
523 ; CHECK-NEXT: vminud 2, 2, 3
524 ; CHECK-NEXT: lxvd2x 35, 0, 3
525 ; CHECK-NEXT: vaddudm 2, 2, 3
527 %c = icmp ult <2 x i64> %x, <i64 -43, i64 -43>
528 %s = select <2 x i1> %c, <2 x i64> %x, <2 x i64> <i64 -43, i64 -43>
529 %r = add <2 x i64> %s, <i64 42, i64 42>
533 define <2 x i64> @unsigned_sat_constant_v2i64_using_cmp_sum(<2 x i64> %x) {
534 ; CHECK-LABEL: unsigned_sat_constant_v2i64_using_cmp_sum:
536 ; CHECK-NEXT: addis 3, 2, .LCPI34_0@toc@ha
537 ; CHECK-NEXT: xxleqv 0, 0, 0
538 ; CHECK-NEXT: addi 3, 3, .LCPI34_0@toc@l
539 ; CHECK-NEXT: lxvd2x 35, 0, 3
540 ; CHECK-NEXT: vaddudm 3, 2, 3
541 ; CHECK-NEXT: vcmpgtud 2, 2, 3
542 ; CHECK-NEXT: xxsel 34, 35, 0, 34
544 %a = add <2 x i64> %x, <i64 42, i64 42>
545 %c = icmp ugt <2 x i64> %x, %a
546 %r = select <2 x i1> %c, <2 x i64> <i64 -1, i64 -1>, <2 x i64> %a
550 define <2 x i64> @unsigned_sat_constant_v2i64_using_cmp_notval(<2 x i64> %x) {
551 ; CHECK-LABEL: unsigned_sat_constant_v2i64_using_cmp_notval:
553 ; CHECK-NEXT: addis 3, 2, .LCPI35_1@toc@ha
554 ; CHECK-NEXT: xxleqv 0, 0, 0
555 ; CHECK-NEXT: addi 3, 3, .LCPI35_1@toc@l
556 ; CHECK-NEXT: lxvd2x 35, 0, 3
557 ; CHECK-NEXT: addis 3, 2, .LCPI35_0@toc@ha
558 ; CHECK-NEXT: addi 3, 3, .LCPI35_0@toc@l
559 ; CHECK-NEXT: lxvd2x 36, 0, 3
560 ; CHECK-NEXT: vcmpgtud 3, 2, 3
561 ; CHECK-NEXT: vaddudm 2, 2, 4
562 ; CHECK-NEXT: xxsel 34, 34, 0, 35
564 %a = add <2 x i64> %x, <i64 42, i64 42>
565 %c = icmp ugt <2 x i64> %x, <i64 -43, i64 -43>
566 %r = select <2 x i1> %c, <2 x i64> <i64 -1, i64 -1>, <2 x i64> %a
570 define <16 x i8> @unsigned_sat_variable_v16i8_using_min(<16 x i8> %x, <16 x i8> %y) {
571 ; CHECK-LABEL: unsigned_sat_variable_v16i8_using_min:
573 ; CHECK-NEXT: xxlnor 36, 35, 35
574 ; CHECK-NEXT: vminub 2, 2, 4
575 ; CHECK-NEXT: vaddubm 2, 2, 3
577 %noty = xor <16 x i8> %y, <i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1>
578 %c = icmp ult <16 x i8> %x, %noty
579 %s = select <16 x i1> %c, <16 x i8> %x, <16 x i8> %noty
580 %r = add <16 x i8> %s, %y
584 define <16 x i8> @unsigned_sat_variable_v16i8_using_cmp_sum(<16 x i8> %x, <16 x i8> %y) {
585 ; CHECK-LABEL: unsigned_sat_variable_v16i8_using_cmp_sum:
587 ; CHECK-NEXT: vaddubs 2, 2, 3
589 %a = add <16 x i8> %x, %y
590 %c = icmp ugt <16 x i8> %x, %a
591 %r = select <16 x i1> %c, <16 x i8> <i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1>, <16 x i8> %a
595 define <16 x i8> @unsigned_sat_variable_v16i8_using_cmp_notval(<16 x i8> %x, <16 x i8> %y) {
596 ; CHECK-LABEL: unsigned_sat_variable_v16i8_using_cmp_notval:
598 ; CHECK-NEXT: xxlnor 36, 35, 35
599 ; CHECK-NEXT: xxleqv 0, 0, 0
600 ; CHECK-NEXT: vcmpgtub 4, 2, 4
601 ; CHECK-NEXT: vaddubm 2, 2, 3
602 ; CHECK-NEXT: xxsel 34, 34, 0, 36
604 %noty = xor <16 x i8> %y, <i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1>
605 %a = add <16 x i8> %x, %y
606 %c = icmp ugt <16 x i8> %x, %noty
607 %r = select <16 x i1> %c, <16 x i8> <i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1>, <16 x i8> %a
611 define <8 x i16> @unsigned_sat_variable_v8i16_using_min(<8 x i16> %x, <8 x i16> %y) {
612 ; CHECK-LABEL: unsigned_sat_variable_v8i16_using_min:
614 ; CHECK-NEXT: xxlnor 36, 35, 35
615 ; CHECK-NEXT: vminuh 2, 2, 4
616 ; CHECK-NEXT: vadduhm 2, 2, 3
618 %noty = xor <8 x i16> %y, <i16 -1, i16 -1, i16 -1, i16 -1, i16 -1, i16 -1, i16 -1, i16 -1>
619 %c = icmp ult <8 x i16> %x, %noty
620 %s = select <8 x i1> %c, <8 x i16> %x, <8 x i16> %noty
621 %r = add <8 x i16> %s, %y
625 define <8 x i16> @unsigned_sat_variable_v8i16_using_cmp_sum(<8 x i16> %x, <8 x i16> %y) {
626 ; CHECK-LABEL: unsigned_sat_variable_v8i16_using_cmp_sum:
628 ; CHECK-NEXT: vadduhs 2, 2, 3
630 %a = add <8 x i16> %x, %y
631 %c = icmp ugt <8 x i16> %x, %a
632 %r = select <8 x i1> %c, <8 x i16> <i16 -1, i16 -1, i16 -1, i16 -1, i16 -1, i16 -1, i16 -1, i16 -1>, <8 x i16> %a
636 define <8 x i16> @unsigned_sat_variable_v8i16_using_cmp_notval(<8 x i16> %x, <8 x i16> %y) {
637 ; CHECK-LABEL: unsigned_sat_variable_v8i16_using_cmp_notval:
639 ; CHECK-NEXT: xxlnor 36, 35, 35
640 ; CHECK-NEXT: xxleqv 0, 0, 0
641 ; CHECK-NEXT: vcmpgtuh 4, 2, 4
642 ; CHECK-NEXT: vadduhm 2, 2, 3
643 ; CHECK-NEXT: xxsel 34, 34, 0, 36
645 %noty = xor <8 x i16> %y, <i16 -1, i16 -1, i16 -1, i16 -1, i16 -1, i16 -1, i16 -1, i16 -1>
646 %a = add <8 x i16> %x, %y
647 %c = icmp ugt <8 x i16> %x, %noty
648 %r = select <8 x i1> %c, <8 x i16> <i16 -1, i16 -1, i16 -1, i16 -1, i16 -1, i16 -1, i16 -1, i16 -1>, <8 x i16> %a
652 define <4 x i32> @unsigned_sat_variable_v4i32_using_min(<4 x i32> %x, <4 x i32> %y) {
653 ; CHECK-LABEL: unsigned_sat_variable_v4i32_using_min:
655 ; CHECK-NEXT: xxlnor 36, 35, 35
656 ; CHECK-NEXT: vminuw 2, 2, 4
657 ; CHECK-NEXT: vadduwm 2, 2, 3
659 %noty = xor <4 x i32> %y, <i32 -1, i32 -1, i32 -1, i32 -1>
660 %c = icmp ult <4 x i32> %x, %noty
661 %s = select <4 x i1> %c, <4 x i32> %x, <4 x i32> %noty
662 %r = add <4 x i32> %s, %y
666 define <4 x i32> @unsigned_sat_variable_v4i32_using_cmp_sum(<4 x i32> %x, <4 x i32> %y) {
667 ; CHECK-LABEL: unsigned_sat_variable_v4i32_using_cmp_sum:
669 ; CHECK-NEXT: vadduws 2, 2, 3
671 %a = add <4 x i32> %x, %y
672 %c = icmp ugt <4 x i32> %x, %a
673 %r = select <4 x i1> %c, <4 x i32> <i32 -1, i32 -1, i32 -1, i32 -1>, <4 x i32> %a
677 define <4 x i32> @unsigned_sat_variable_v4i32_using_cmp_notval(<4 x i32> %x, <4 x i32> %y) {
678 ; CHECK-LABEL: unsigned_sat_variable_v4i32_using_cmp_notval:
680 ; CHECK-NEXT: xxlnor 36, 35, 35
681 ; CHECK-NEXT: xxleqv 0, 0, 0
682 ; CHECK-NEXT: vcmpgtuw 4, 2, 4
683 ; CHECK-NEXT: vadduwm 2, 2, 3
684 ; CHECK-NEXT: xxsel 34, 34, 0, 36
686 %noty = xor <4 x i32> %y, <i32 -1, i32 -1, i32 -1, i32 -1>
687 %a = add <4 x i32> %x, %y
688 %c = icmp ugt <4 x i32> %x, %noty
689 %r = select <4 x i1> %c, <4 x i32> <i32 -1, i32 -1, i32 -1, i32 -1>, <4 x i32> %a
693 define <2 x i64> @unsigned_sat_variable_v2i64_using_min(<2 x i64> %x, <2 x i64> %y) {
694 ; CHECK-LABEL: unsigned_sat_variable_v2i64_using_min:
696 ; CHECK-NEXT: xxlnor 36, 35, 35
697 ; CHECK-NEXT: vminud 2, 2, 4
698 ; CHECK-NEXT: vaddudm 2, 2, 3
700 %noty = xor <2 x i64> %y, <i64 -1, i64 -1>
701 %c = icmp ult <2 x i64> %x, %noty
702 %s = select <2 x i1> %c, <2 x i64> %x, <2 x i64> %noty
703 %r = add <2 x i64> %s, %y
707 define <2 x i64> @unsigned_sat_variable_v2i64_using_cmp_sum(<2 x i64> %x, <2 x i64> %y) {
708 ; CHECK-LABEL: unsigned_sat_variable_v2i64_using_cmp_sum:
710 ; CHECK-NEXT: vaddudm 3, 2, 3
711 ; CHECK-NEXT: xxleqv 0, 0, 0
712 ; CHECK-NEXT: vcmpgtud 2, 2, 3
713 ; CHECK-NEXT: xxsel 34, 35, 0, 34
715 %a = add <2 x i64> %x, %y
716 %c = icmp ugt <2 x i64> %x, %a
717 %r = select <2 x i1> %c, <2 x i64> <i64 -1, i64 -1>, <2 x i64> %a
721 define <2 x i64> @unsigned_sat_variable_v2i64_using_cmp_notval(<2 x i64> %x, <2 x i64> %y) {
722 ; CHECK-LABEL: unsigned_sat_variable_v2i64_using_cmp_notval:
724 ; CHECK-NEXT: xxlnor 36, 35, 35
725 ; CHECK-NEXT: xxleqv 0, 0, 0
726 ; CHECK-NEXT: vcmpgtud 4, 2, 4
727 ; CHECK-NEXT: vaddudm 2, 2, 3
728 ; CHECK-NEXT: xxsel 34, 34, 0, 36
730 %noty = xor <2 x i64> %y, <i64 -1, i64 -1>
731 %a = add <2 x i64> %x, %y
732 %c = icmp ugt <2 x i64> %x, %noty
733 %r = select <2 x i1> %c, <2 x i64> <i64 -1, i64 -1>, <2 x i64> %a
737 declare <4 x i128> @llvm.sadd.sat.v4i128(<4 x i128> %a, <4 x i128> %b);
739 define <4 x i128> @sadd(<4 x i128> %a, <4 x i128> %b) local_unnamed_addr {
742 ; CHECK-NEXT: vadduqm 0, 2, 6
743 ; CHECK-NEXT: xxswapd 0, 34
744 ; CHECK-NEXT: std 30, -16(1) # 8-byte Folded Spill
745 ; CHECK-NEXT: addis 3, 2, .LCPI48_0@toc@ha
746 ; CHECK-NEXT: vadduqm 1, 3, 7
747 ; CHECK-NEXT: xxswapd 1, 35
748 ; CHECK-NEXT: addi 3, 3, .LCPI48_0@toc@l
749 ; CHECK-NEXT: xxswapd 3, 32
750 ; CHECK-NEXT: mfvsrd 4, 34
751 ; CHECK-NEXT: mfvsrd 8, 32
752 ; CHECK-NEXT: xxswapd 2, 36
753 ; CHECK-NEXT: mffprd 12, 0
754 ; CHECK-NEXT: xxswapd 0, 33
755 ; CHECK-NEXT: vadduqm 10, 4, 8
756 ; CHECK-NEXT: cmpld 8, 4
757 ; CHECK-NEXT: cmpd 1, 8, 4
758 ; CHECK-NEXT: mffprd 4, 3
759 ; CHECK-NEXT: lxvd2x 3, 0, 3
760 ; CHECK-NEXT: sradi 3, 8, 63
761 ; CHECK-NEXT: mffprd 0, 1
762 ; CHECK-NEXT: xxswapd 1, 37
763 ; CHECK-NEXT: mfvsrd 5, 35
764 ; CHECK-NEXT: vadduqm 11, 5, 9
765 ; CHECK-NEXT: xxswapd 34, 3
766 ; CHECK-NEXT: mfvsrd 9, 33
767 ; CHECK-NEXT: crandc 20, 4, 2
768 ; CHECK-NEXT: cmpld 1, 4, 12
769 ; CHECK-NEXT: mffprd 4, 0
770 ; CHECK-NEXT: xxswapd 0, 42
771 ; CHECK-NEXT: mfvsrd 6, 36
772 ; CHECK-NEXT: mfvsrd 10, 42
773 ; CHECK-NEXT: cmpld 6, 4, 0
774 ; CHECK-NEXT: crand 21, 2, 4
775 ; CHECK-NEXT: cmpld 9, 5
776 ; CHECK-NEXT: cmpd 1, 9, 5
777 ; CHECK-NEXT: mffprd 5, 1
778 ; CHECK-NEXT: xxswapd 1, 43
779 ; CHECK-NEXT: mffprd 30, 2
780 ; CHECK-NEXT: mffprd 4, 0
781 ; CHECK-NEXT: mfvsrd 7, 37
782 ; CHECK-NEXT: mfvsrd 11, 43
783 ; CHECK-NEXT: crandc 22, 4, 2
784 ; CHECK-NEXT: cmpd 1, 10, 6
785 ; CHECK-NEXT: crand 23, 2, 24
786 ; CHECK-NEXT: cmpld 10, 6
787 ; CHECK-NEXT: crandc 24, 4, 2
788 ; CHECK-NEXT: cmpld 1, 4, 30
789 ; CHECK-NEXT: ld 30, -16(1) # 8-byte Folded Reload
790 ; CHECK-NEXT: mffprd 4, 1
791 ; CHECK-NEXT: mfvsrd 6, 38
792 ; CHECK-NEXT: crand 25, 2, 4
793 ; CHECK-NEXT: cmpld 11, 7
794 ; CHECK-NEXT: cmpd 1, 11, 7
795 ; CHECK-NEXT: crandc 26, 4, 2
796 ; CHECK-NEXT: cmpld 1, 4, 5
797 ; CHECK-NEXT: sradi 4, 6, 63
798 ; CHECK-NEXT: mtfprd 0, 4
799 ; CHECK-NEXT: mfvsrd 4, 39
800 ; CHECK-NEXT: mfvsrd 5, 40
801 ; CHECK-NEXT: mfvsrd 6, 41
802 ; CHECK-NEXT: sradi 4, 4, 63
803 ; CHECK-NEXT: mtfprd 1, 4
804 ; CHECK-NEXT: sradi 4, 5, 63
805 ; CHECK-NEXT: mtfprd 2, 4
806 ; CHECK-NEXT: sradi 4, 6, 63
807 ; CHECK-NEXT: mtfprd 5, 3
808 ; CHECK-NEXT: sradi 3, 10, 63
809 ; CHECK-NEXT: mtfprd 4, 4
810 ; CHECK-NEXT: sradi 4, 9, 63
811 ; CHECK-NEXT: mtfprd 6, 4
812 ; CHECK-NEXT: xxspltd 35, 5, 0
813 ; CHECK-NEXT: sradi 4, 11, 63
814 ; CHECK-NEXT: crnor 20, 21, 20
815 ; CHECK-NEXT: xxspltd 38, 4, 0
816 ; CHECK-NEXT: mtfprd 3, 3
817 ; CHECK-NEXT: li 3, -1
818 ; CHECK-NEXT: xxspltd 36, 6, 0
819 ; CHECK-NEXT: mtfprd 5, 4
820 ; CHECK-NEXT: crand 27, 2, 4
821 ; CHECK-NEXT: xxspltd 37, 3, 0
822 ; CHECK-NEXT: xxlxor 3, 35, 34
823 ; CHECK-NEXT: xxspltd 35, 5, 0
824 ; CHECK-NEXT: isel 4, 0, 3, 20
825 ; CHECK-NEXT: mtfprd 8, 4
826 ; CHECK-NEXT: crnor 20, 23, 22
827 ; CHECK-NEXT: crnor 21, 25, 24
828 ; CHECK-NEXT: crnor 22, 27, 26
829 ; CHECK-NEXT: xxlxor 5, 36, 34
830 ; CHECK-NEXT: xxspltd 36, 2, 0
831 ; CHECK-NEXT: xxlxor 6, 37, 34
832 ; CHECK-NEXT: xxlxor 7, 35, 34
833 ; CHECK-NEXT: xxspltd 34, 0, 0
834 ; CHECK-NEXT: xxspltd 35, 8, 0
835 ; CHECK-NEXT: isel 4, 0, 3, 20
836 ; CHECK-NEXT: isel 5, 0, 3, 21
837 ; CHECK-NEXT: isel 3, 0, 3, 22
838 ; CHECK-NEXT: xxlxor 0, 34, 35
839 ; CHECK-NEXT: xxspltd 34, 1, 0
840 ; CHECK-NEXT: mtfprd 8, 4
841 ; CHECK-NEXT: mtfprd 1, 5
842 ; CHECK-NEXT: mtfprd 9, 3
843 ; CHECK-NEXT: xxspltd 35, 8, 0
844 ; CHECK-NEXT: xxspltd 37, 1, 0
845 ; CHECK-NEXT: xxspltd 39, 9, 0
846 ; CHECK-NEXT: xxlxor 1, 34, 35
847 ; CHECK-NEXT: xxsel 34, 32, 3, 0
848 ; CHECK-NEXT: xxlxor 2, 36, 37
849 ; CHECK-NEXT: xxlxor 4, 38, 39
850 ; CHECK-NEXT: xxsel 35, 33, 5, 1
851 ; CHECK-NEXT: xxsel 36, 42, 6, 2
852 ; CHECK-NEXT: xxsel 37, 43, 7, 4
854 %c = call <4 x i128> @llvm.sadd.sat.v4i128(<4 x i128> %a, <4 x i128> %b)
858 define i64 @unsigned_sat_constant_i64_with_single_use(i64 %x) {
859 ; CHECK-LABEL: unsigned_sat_constant_i64_with_single_use:
861 ; CHECK-NEXT: addi 4, 3, -4
862 ; CHECK-NEXT: cmpld 4, 3
863 ; CHECK-NEXT: iselgt 3, 0, 4
865 %umin = call i64 @llvm.umin.i64(i64 %x, i64 4)
866 %sub = sub i64 %x, %umin
870 define i64 @unsigned_sat_constant_i64_with_multiple_use(i64 %x, i64 %y) {
871 ; CHECK-LABEL: unsigned_sat_constant_i64_with_multiple_use:
873 ; CHECK-NEXT: li 5, 4
874 ; CHECK-NEXT: cmpldi 3, 4
875 ; CHECK-NEXT: isellt 5, 3, 5
876 ; CHECK-NEXT: sub 3, 3, 5
877 ; CHECK-NEXT: add 4, 4, 5
878 ; CHECK-NEXT: mulld 3, 3, 4
880 %umin = call i64 @llvm.umin.i64(i64 %x, i64 4)
881 %sub = sub i64 %x, %umin
882 %add = add i64 %y, %umin
883 %res = mul i64 %sub, %add
887 declare i64 @llvm.umin.i64(i64, i64)