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: lvx 3, 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: lvx 3, 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: lvx 3, 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: lvx 3, 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: lvx 3, 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: lvx 3, 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: lvx 3, 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: lvx 3, 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: lvx 3, 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: lvx 3, 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: lvx 3, 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: lvx 3, 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 0, 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: xxswapd 35, 0
524 ; CHECK-NEXT: lxvd2x 0, 0, 3
525 ; CHECK-NEXT: vminud 2, 2, 3
526 ; CHECK-NEXT: xxswapd 35, 0
527 ; CHECK-NEXT: vaddudm 2, 2, 3
529 %c = icmp ult <2 x i64> %x, <i64 -43, i64 -43>
530 %s = select <2 x i1> %c, <2 x i64> %x, <2 x i64> <i64 -43, i64 -43>
531 %r = add <2 x i64> %s, <i64 42, i64 42>
535 define <2 x i64> @unsigned_sat_constant_v2i64_using_cmp_sum(<2 x i64> %x) {
536 ; CHECK-LABEL: unsigned_sat_constant_v2i64_using_cmp_sum:
538 ; CHECK-NEXT: addis 3, 2, .LCPI34_0@toc@ha
539 ; CHECK-NEXT: addi 3, 3, .LCPI34_0@toc@l
540 ; CHECK-NEXT: lxvd2x 0, 0, 3
541 ; CHECK-NEXT: xxswapd 35, 0
542 ; CHECK-NEXT: xxleqv 0, 0, 0
543 ; CHECK-NEXT: vaddudm 3, 2, 3
544 ; CHECK-NEXT: vcmpgtud 2, 2, 3
545 ; CHECK-NEXT: xxsel 34, 35, 0, 34
547 %a = add <2 x i64> %x, <i64 42, i64 42>
548 %c = icmp ugt <2 x i64> %x, %a
549 %r = select <2 x i1> %c, <2 x i64> <i64 -1, i64 -1>, <2 x i64> %a
553 define <2 x i64> @unsigned_sat_constant_v2i64_using_cmp_notval(<2 x i64> %x) {
554 ; CHECK-LABEL: unsigned_sat_constant_v2i64_using_cmp_notval:
556 ; CHECK-NEXT: addis 3, 2, .LCPI35_1@toc@ha
557 ; CHECK-NEXT: addi 3, 3, .LCPI35_1@toc@l
558 ; CHECK-NEXT: lxvd2x 0, 0, 3
559 ; CHECK-NEXT: addis 3, 2, .LCPI35_0@toc@ha
560 ; CHECK-NEXT: addi 3, 3, .LCPI35_0@toc@l
561 ; CHECK-NEXT: lxvd2x 1, 0, 3
562 ; CHECK-NEXT: xxswapd 35, 0
563 ; CHECK-NEXT: xxleqv 0, 0, 0
564 ; CHECK-NEXT: xxswapd 36, 1
565 ; CHECK-NEXT: vcmpgtud 3, 2, 3
566 ; CHECK-NEXT: vaddudm 2, 2, 4
567 ; CHECK-NEXT: xxsel 34, 34, 0, 35
569 %a = add <2 x i64> %x, <i64 42, i64 42>
570 %c = icmp ugt <2 x i64> %x, <i64 -43, i64 -43>
571 %r = select <2 x i1> %c, <2 x i64> <i64 -1, i64 -1>, <2 x i64> %a
575 define <16 x i8> @unsigned_sat_variable_v16i8_using_min(<16 x i8> %x, <16 x i8> %y) {
576 ; CHECK-LABEL: unsigned_sat_variable_v16i8_using_min:
578 ; CHECK-NEXT: xxlnor 36, 35, 35
579 ; CHECK-NEXT: vminub 2, 2, 4
580 ; CHECK-NEXT: vaddubm 2, 2, 3
582 %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>
583 %c = icmp ult <16 x i8> %x, %noty
584 %s = select <16 x i1> %c, <16 x i8> %x, <16 x i8> %noty
585 %r = add <16 x i8> %s, %y
589 define <16 x i8> @unsigned_sat_variable_v16i8_using_cmp_sum(<16 x i8> %x, <16 x i8> %y) {
590 ; CHECK-LABEL: unsigned_sat_variable_v16i8_using_cmp_sum:
592 ; CHECK-NEXT: vaddubs 2, 2, 3
594 %a = add <16 x i8> %x, %y
595 %c = icmp ugt <16 x i8> %x, %a
596 %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
600 define <16 x i8> @unsigned_sat_variable_v16i8_using_cmp_notval(<16 x i8> %x, <16 x i8> %y) {
601 ; CHECK-LABEL: unsigned_sat_variable_v16i8_using_cmp_notval:
603 ; CHECK-NEXT: xxlnor 36, 35, 35
604 ; CHECK-NEXT: xxleqv 0, 0, 0
605 ; CHECK-NEXT: vcmpgtub 4, 2, 4
606 ; CHECK-NEXT: vaddubm 2, 2, 3
607 ; CHECK-NEXT: xxsel 34, 34, 0, 36
609 %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>
610 %a = add <16 x i8> %x, %y
611 %c = icmp ugt <16 x i8> %x, %noty
612 %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
616 define <8 x i16> @unsigned_sat_variable_v8i16_using_min(<8 x i16> %x, <8 x i16> %y) {
617 ; CHECK-LABEL: unsigned_sat_variable_v8i16_using_min:
619 ; CHECK-NEXT: xxlnor 36, 35, 35
620 ; CHECK-NEXT: vminuh 2, 2, 4
621 ; CHECK-NEXT: vadduhm 2, 2, 3
623 %noty = xor <8 x i16> %y, <i16 -1, i16 -1, i16 -1, i16 -1, i16 -1, i16 -1, i16 -1, i16 -1>
624 %c = icmp ult <8 x i16> %x, %noty
625 %s = select <8 x i1> %c, <8 x i16> %x, <8 x i16> %noty
626 %r = add <8 x i16> %s, %y
630 define <8 x i16> @unsigned_sat_variable_v8i16_using_cmp_sum(<8 x i16> %x, <8 x i16> %y) {
631 ; CHECK-LABEL: unsigned_sat_variable_v8i16_using_cmp_sum:
633 ; CHECK-NEXT: vadduhs 2, 2, 3
635 %a = add <8 x i16> %x, %y
636 %c = icmp ugt <8 x i16> %x, %a
637 %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
641 define <8 x i16> @unsigned_sat_variable_v8i16_using_cmp_notval(<8 x i16> %x, <8 x i16> %y) {
642 ; CHECK-LABEL: unsigned_sat_variable_v8i16_using_cmp_notval:
644 ; CHECK-NEXT: xxlnor 36, 35, 35
645 ; CHECK-NEXT: xxleqv 0, 0, 0
646 ; CHECK-NEXT: vcmpgtuh 4, 2, 4
647 ; CHECK-NEXT: vadduhm 2, 2, 3
648 ; CHECK-NEXT: xxsel 34, 34, 0, 36
650 %noty = xor <8 x i16> %y, <i16 -1, i16 -1, i16 -1, i16 -1, i16 -1, i16 -1, i16 -1, i16 -1>
651 %a = add <8 x i16> %x, %y
652 %c = icmp ugt <8 x i16> %x, %noty
653 %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
657 define <4 x i32> @unsigned_sat_variable_v4i32_using_min(<4 x i32> %x, <4 x i32> %y) {
658 ; CHECK-LABEL: unsigned_sat_variable_v4i32_using_min:
660 ; CHECK-NEXT: xxlnor 36, 35, 35
661 ; CHECK-NEXT: vminuw 2, 2, 4
662 ; CHECK-NEXT: vadduwm 2, 2, 3
664 %noty = xor <4 x i32> %y, <i32 -1, i32 -1, i32 -1, i32 -1>
665 %c = icmp ult <4 x i32> %x, %noty
666 %s = select <4 x i1> %c, <4 x i32> %x, <4 x i32> %noty
667 %r = add <4 x i32> %s, %y
671 define <4 x i32> @unsigned_sat_variable_v4i32_using_cmp_sum(<4 x i32> %x, <4 x i32> %y) {
672 ; CHECK-LABEL: unsigned_sat_variable_v4i32_using_cmp_sum:
674 ; CHECK-NEXT: vadduws 2, 2, 3
676 %a = add <4 x i32> %x, %y
677 %c = icmp ugt <4 x i32> %x, %a
678 %r = select <4 x i1> %c, <4 x i32> <i32 -1, i32 -1, i32 -1, i32 -1>, <4 x i32> %a
682 define <4 x i32> @unsigned_sat_variable_v4i32_using_cmp_notval(<4 x i32> %x, <4 x i32> %y) {
683 ; CHECK-LABEL: unsigned_sat_variable_v4i32_using_cmp_notval:
685 ; CHECK-NEXT: xxlnor 36, 35, 35
686 ; CHECK-NEXT: xxleqv 0, 0, 0
687 ; CHECK-NEXT: vcmpgtuw 4, 2, 4
688 ; CHECK-NEXT: vadduwm 2, 2, 3
689 ; CHECK-NEXT: xxsel 34, 34, 0, 36
691 %noty = xor <4 x i32> %y, <i32 -1, i32 -1, i32 -1, i32 -1>
692 %a = add <4 x i32> %x, %y
693 %c = icmp ugt <4 x i32> %x, %noty
694 %r = select <4 x i1> %c, <4 x i32> <i32 -1, i32 -1, i32 -1, i32 -1>, <4 x i32> %a
698 define <2 x i64> @unsigned_sat_variable_v2i64_using_min(<2 x i64> %x, <2 x i64> %y) {
699 ; CHECK-LABEL: unsigned_sat_variable_v2i64_using_min:
701 ; CHECK-NEXT: xxlnor 36, 35, 35
702 ; CHECK-NEXT: vminud 2, 2, 4
703 ; CHECK-NEXT: vaddudm 2, 2, 3
705 %noty = xor <2 x i64> %y, <i64 -1, i64 -1>
706 %c = icmp ult <2 x i64> %x, %noty
707 %s = select <2 x i1> %c, <2 x i64> %x, <2 x i64> %noty
708 %r = add <2 x i64> %s, %y
712 define <2 x i64> @unsigned_sat_variable_v2i64_using_cmp_sum(<2 x i64> %x, <2 x i64> %y) {
713 ; CHECK-LABEL: unsigned_sat_variable_v2i64_using_cmp_sum:
715 ; CHECK-NEXT: vaddudm 3, 2, 3
716 ; CHECK-NEXT: xxleqv 0, 0, 0
717 ; CHECK-NEXT: vcmpgtud 2, 2, 3
718 ; CHECK-NEXT: xxsel 34, 35, 0, 34
720 %a = add <2 x i64> %x, %y
721 %c = icmp ugt <2 x i64> %x, %a
722 %r = select <2 x i1> %c, <2 x i64> <i64 -1, i64 -1>, <2 x i64> %a
726 define <2 x i64> @unsigned_sat_variable_v2i64_using_cmp_notval(<2 x i64> %x, <2 x i64> %y) {
727 ; CHECK-LABEL: unsigned_sat_variable_v2i64_using_cmp_notval:
729 ; CHECK-NEXT: xxlnor 36, 35, 35
730 ; CHECK-NEXT: xxleqv 0, 0, 0
731 ; CHECK-NEXT: vcmpgtud 4, 2, 4
732 ; CHECK-NEXT: vaddudm 2, 2, 3
733 ; CHECK-NEXT: xxsel 34, 34, 0, 36
735 %noty = xor <2 x i64> %y, <i64 -1, i64 -1>
736 %a = add <2 x i64> %x, %y
737 %c = icmp ugt <2 x i64> %x, %noty
738 %r = select <2 x i1> %c, <2 x i64> <i64 -1, i64 -1>, <2 x i64> %a
742 declare <4 x i128> @llvm.sadd.sat.v4i128(<4 x i128> %a, <4 x i128> %b);
744 define <4 x i128> @sadd(<4 x i128> %a, <4 x i128> %b) local_unnamed_addr {
747 ; CHECK-NEXT: vadduqm 0, 2, 6
748 ; CHECK-NEXT: xxswapd 0, 34
749 ; CHECK-NEXT: std 30, -16(1) # 8-byte Folded Spill
750 ; CHECK-NEXT: li 3, -1
751 ; CHECK-NEXT: vadduqm 1, 3, 7
752 ; CHECK-NEXT: xxswapd 1, 35
753 ; CHECK-NEXT: xxswapd 2, 32
754 ; CHECK-NEXT: mfvsrd 4, 34
755 ; CHECK-NEXT: mfvsrd 9, 32
756 ; CHECK-NEXT: mffprd 0, 0
757 ; CHECK-NEXT: xxswapd 0, 33
758 ; CHECK-NEXT: mfvsrd 5, 38
759 ; CHECK-NEXT: cmpld 9, 4
760 ; CHECK-NEXT: cmpd 1, 9, 4
761 ; CHECK-NEXT: vadduqm 6, 4, 8
762 ; CHECK-NEXT: mffprd 4, 2
763 ; CHECK-NEXT: sradi 5, 5, 63
764 ; CHECK-NEXT: mffprd 30, 1
765 ; CHECK-NEXT: xxswapd 1, 36
766 ; CHECK-NEXT: crandc 20, 4, 2
767 ; CHECK-NEXT: cmpld 1, 4, 0
768 ; CHECK-NEXT: mffprd 4, 0
769 ; CHECK-NEXT: xxswapd 0, 38
770 ; CHECK-NEXT: mfvsrd 6, 35
771 ; CHECK-NEXT: vadduqm 10, 5, 9
772 ; CHECK-NEXT: cmpld 6, 4, 30
773 ; CHECK-NEXT: ld 30, -16(1) # 8-byte Folded Reload
774 ; CHECK-NEXT: mfvsrd 10, 33
775 ; CHECK-NEXT: mfvsrd 7, 36
776 ; CHECK-NEXT: mfvsrd 11, 38
777 ; CHECK-NEXT: crand 21, 2, 4
778 ; CHECK-NEXT: cmpld 10, 6
779 ; CHECK-NEXT: cmpd 1, 10, 6
780 ; CHECK-NEXT: mffprd 6, 1
781 ; CHECK-NEXT: xxswapd 1, 37
782 ; CHECK-NEXT: mffprd 4, 0
783 ; CHECK-NEXT: xxswapd 0, 42
784 ; CHECK-NEXT: mfvsrd 8, 37
785 ; CHECK-NEXT: mfvsrd 12, 42
786 ; CHECK-NEXT: crandc 22, 4, 2
787 ; CHECK-NEXT: cmpd 1, 11, 7
788 ; CHECK-NEXT: crand 23, 2, 24
789 ; CHECK-NEXT: cmpld 11, 7
790 ; CHECK-NEXT: crandc 24, 4, 2
791 ; CHECK-NEXT: cmpld 1, 4, 6
792 ; CHECK-NEXT: mffprd 4, 1
793 ; CHECK-NEXT: mffprd 6, 0
794 ; CHECK-NEXT: crand 25, 2, 4
795 ; CHECK-NEXT: cmpld 12, 8
796 ; CHECK-NEXT: cmpd 1, 12, 8
797 ; CHECK-NEXT: crandc 26, 4, 2
798 ; CHECK-NEXT: cmpld 1, 6, 4
799 ; CHECK-NEXT: mfvsrd 4, 39
800 ; CHECK-NEXT: mtfprd 0, 5
801 ; CHECK-NEXT: sradi 4, 4, 63
802 ; CHECK-NEXT: mfvsrd 5, 41
803 ; CHECK-NEXT: mtfprd 1, 4
804 ; CHECK-NEXT: xxspltd 34, 0, 0
805 ; CHECK-NEXT: mfvsrd 4, 40
806 ; CHECK-NEXT: crnor 20, 21, 20
807 ; CHECK-NEXT: sradi 4, 4, 63
808 ; CHECK-NEXT: crand 27, 2, 4
809 ; CHECK-NEXT: mtfprd 2, 4
810 ; CHECK-NEXT: sradi 4, 5, 63
811 ; CHECK-NEXT: sradi 5, 10, 63
812 ; CHECK-NEXT: mtfprd 3, 4
813 ; CHECK-NEXT: isel 4, 0, 3, 20
814 ; CHECK-NEXT: xxspltd 36, 2, 0
815 ; CHECK-NEXT: crnor 20, 23, 22
816 ; CHECK-NEXT: mtfprd 4, 4
817 ; CHECK-NEXT: sradi 4, 9, 63
818 ; CHECK-NEXT: mtfprd 0, 4
819 ; CHECK-NEXT: addis 4, 2, .LCPI48_0@toc@ha
820 ; CHECK-NEXT: mtfprd 5, 5
821 ; CHECK-NEXT: xxspltd 35, 4, 0
822 ; CHECK-NEXT: addi 4, 4, .LCPI48_0@toc@l
823 ; CHECK-NEXT: isel 5, 0, 3, 20
824 ; CHECK-NEXT: lxvd2x 6, 0, 4
825 ; CHECK-NEXT: mtfprd 4, 5
826 ; CHECK-NEXT: addis 5, 2, .LCPI48_1@toc@ha
827 ; CHECK-NEXT: xxspltd 37, 5, 0
828 ; CHECK-NEXT: addi 4, 5, .LCPI48_1@toc@l
829 ; CHECK-NEXT: xxlxor 7, 34, 35
830 ; CHECK-NEXT: xxspltd 34, 1, 0
831 ; CHECK-NEXT: sradi 5, 11, 63
832 ; CHECK-NEXT: lxvd2x 8, 0, 4
833 ; CHECK-NEXT: xxspltd 35, 4, 0
834 ; CHECK-NEXT: crnor 20, 25, 24
835 ; CHECK-NEXT: sradi 4, 12, 63
836 ; CHECK-NEXT: crnor 21, 27, 26
837 ; CHECK-NEXT: xxswapd 4, 6
838 ; CHECK-NEXT: mtfprd 1, 5
839 ; CHECK-NEXT: mtfprd 9, 4
840 ; CHECK-NEXT: xxswapd 6, 8
841 ; CHECK-NEXT: xxlxor 2, 34, 35
842 ; CHECK-NEXT: xxspltd 35, 0, 0
843 ; CHECK-NEXT: isel 4, 0, 3, 20
844 ; CHECK-NEXT: xxspltd 39, 1, 0
845 ; CHECK-NEXT: isel 3, 0, 3, 21
846 ; CHECK-NEXT: xxspltd 40, 9, 0
847 ; CHECK-NEXT: mtfprd 0, 4
848 ; CHECK-NEXT: xxspltd 34, 3, 0
849 ; CHECK-NEXT: mtfprd 1, 3
850 ; CHECK-NEXT: xxsel 3, 6, 4, 39
851 ; CHECK-NEXT: xxspltd 41, 0, 0
852 ; CHECK-NEXT: xxsel 0, 6, 4, 35
853 ; CHECK-NEXT: xxspltd 35, 1, 0
854 ; CHECK-NEXT: xxsel 1, 6, 4, 37
855 ; CHECK-NEXT: xxsel 4, 6, 4, 40
856 ; CHECK-NEXT: xxlxor 5, 36, 41
857 ; CHECK-NEXT: xxlxor 6, 34, 35
858 ; CHECK-NEXT: xxsel 34, 32, 0, 7
859 ; CHECK-NEXT: xxsel 35, 33, 1, 2
860 ; CHECK-NEXT: xxsel 36, 38, 3, 5
861 ; CHECK-NEXT: xxsel 37, 42, 4, 6
863 %c = call <4 x i128> @llvm.sadd.sat.v4i128(<4 x i128> %a, <4 x i128> %b)
867 define i64 @unsigned_sat_constant_i64_with_single_use(i64 %x) {
868 ; CHECK-LABEL: unsigned_sat_constant_i64_with_single_use:
870 ; CHECK-NEXT: addi 4, 3, -4
871 ; CHECK-NEXT: cmpld 4, 3
872 ; CHECK-NEXT: iselgt 3, 0, 4
874 %umin = call i64 @llvm.umin.i64(i64 %x, i64 4)
875 %sub = sub i64 %x, %umin
879 define i64 @unsigned_sat_constant_i64_with_multiple_use(i64 %x, i64 %y) {
880 ; CHECK-LABEL: unsigned_sat_constant_i64_with_multiple_use:
882 ; CHECK-NEXT: li 5, 4
883 ; CHECK-NEXT: cmpldi 3, 4
884 ; CHECK-NEXT: isellt 5, 3, 5
885 ; CHECK-NEXT: sub 3, 3, 5
886 ; CHECK-NEXT: add 4, 4, 5
887 ; CHECK-NEXT: mulld 3, 3, 4
889 %umin = call i64 @llvm.umin.i64(i64 %x, i64 4)
890 %sub = sub i64 %x, %umin
891 %add = add i64 %y, %umin
892 %res = mul i64 %sub, %add
896 declare i64 @llvm.umin.i64(i64, i64)