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 4, 3, 24
13 ; CHECK-NEXT: cmplwi 4, 213
14 ; CHECK-NEXT: li 4, -43
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 4, 3, 24
43 ; CHECK-NEXT: addi 3, 3, 42
44 ; CHECK-NEXT: cmplwi 4, 213
45 ; CHECK-NEXT: li 4, -1
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 4, 3, 16
58 ; CHECK-NEXT: cmplwi 4, 65493
59 ; CHECK-NEXT: li 4, -43
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 4, 3, 16
88 ; CHECK-NEXT: addi 3, 3, 42
89 ; CHECK-NEXT: cmplwi 4, 65493
90 ; CHECK-NEXT: li 4, -1
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 4, 3, 42
117 ; CHECK-NEXT: cmplw 4, 3
118 ; CHECK-NEXT: li 3, -1
119 ; CHECK-NEXT: isellt 3, 3, 4
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 5, -43
131 ; CHECK-NEXT: addi 4, 3, 42
132 ; CHECK-NEXT: cmplw 3, 5
133 ; CHECK-NEXT: li 3, -1
134 ; CHECK-NEXT: iselgt 3, 3, 4
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 4, 3, 42
160 ; CHECK-NEXT: cmpld 4, 3
161 ; CHECK-NEXT: li 3, -1
162 ; CHECK-NEXT: isellt 3, 3, 4
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 5, -43
174 ; CHECK-NEXT: addi 4, 3, 42
175 ; CHECK-NEXT: cmpld 3, 5
176 ; CHECK-NEXT: li 3, -1
177 ; CHECK-NEXT: iselgt 3, 3, 4
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 6, 4
189 ; CHECK-NEXT: clrlwi 5, 3, 24
190 ; CHECK-NEXT: clrlwi 7, 6, 24
191 ; CHECK-NEXT: cmplw 5, 7
192 ; CHECK-NEXT: isellt 3, 3, 6
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 5, 3, 24
223 ; CHECK-NEXT: add 3, 3, 4
224 ; CHECK-NEXT: li 4, -1
225 ; CHECK-NEXT: clrlwi 6, 6, 24
226 ; CHECK-NEXT: cmplw 5, 6
227 ; CHECK-NEXT: iselgt 3, 4, 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 6, 4
240 ; CHECK-NEXT: clrlwi 5, 3, 16
241 ; CHECK-NEXT: clrlwi 7, 6, 16
242 ; CHECK-NEXT: cmplw 5, 7
243 ; CHECK-NEXT: isellt 3, 3, 6
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 5, 3, 16
274 ; CHECK-NEXT: add 3, 3, 4
275 ; CHECK-NEXT: li 4, -1
276 ; CHECK-NEXT: clrlwi 6, 6, 16
277 ; CHECK-NEXT: cmplw 5, 6
278 ; CHECK-NEXT: iselgt 3, 4, 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: cmplw 4, 3
307 ; CHECK-NEXT: li 3, -1
308 ; CHECK-NEXT: isellt 3, 3, 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 5, 4
320 ; CHECK-NEXT: add 4, 3, 4
321 ; CHECK-NEXT: cmplw 3, 5
322 ; CHECK-NEXT: li 3, -1
323 ; CHECK-NEXT: iselgt 3, 3, 4
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: cmpld 4, 3
352 ; CHECK-NEXT: li 3, -1
353 ; CHECK-NEXT: isellt 3, 3, 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 5, 4
365 ; CHECK-NEXT: add 4, 3, 4
366 ; CHECK-NEXT: cmpld 3, 5
367 ; CHECK-NEXT: li 3, -1
368 ; CHECK-NEXT: iselgt 3, 3, 4
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_0@toc@ha
554 ; CHECK-NEXT: xxleqv 0, 0, 0
555 ; CHECK-NEXT: addi 3, 3, .LCPI35_0@toc@l
556 ; CHECK-NEXT: lxvd2x 35, 0, 3
557 ; CHECK-NEXT: addis 3, 2, .LCPI35_1@toc@ha
558 ; CHECK-NEXT: addi 3, 3, .LCPI35_1@toc@l
559 ; CHECK-NEXT: lxvd2x 36, 0, 3
560 ; CHECK-NEXT: vaddudm 3, 2, 3
561 ; CHECK-NEXT: vcmpgtud 2, 2, 4
562 ; CHECK-NEXT: xxsel 34, 35, 0, 34
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: vaddubm 3, 2, 3
600 ; CHECK-NEXT: xxleqv 0, 0, 0
601 ; CHECK-NEXT: vcmpgtub 2, 2, 4
602 ; CHECK-NEXT: xxsel 34, 35, 0, 34
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: vadduhm 3, 2, 3
641 ; CHECK-NEXT: xxleqv 0, 0, 0
642 ; CHECK-NEXT: vcmpgtuh 2, 2, 4
643 ; CHECK-NEXT: xxsel 34, 35, 0, 34
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: vadduwm 3, 2, 3
682 ; CHECK-NEXT: xxleqv 0, 0, 0
683 ; CHECK-NEXT: vcmpgtuw 2, 2, 4
684 ; CHECK-NEXT: xxsel 34, 35, 0, 34
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: vaddudm 3, 2, 3
726 ; CHECK-NEXT: xxleqv 0, 0, 0
727 ; CHECK-NEXT: vcmpgtud 2, 2, 4
728 ; CHECK-NEXT: xxsel 34, 35, 0, 34
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: vadduqm 10, 4, 8
744 ; CHECK-NEXT: mfocrf 12, 32
745 ; CHECK-NEXT: stw 12, 8(1)
746 ; CHECK-NEXT: xxswapd 0, 34
747 ; CHECK-NEXT: xxswapd 4, 36
748 ; CHECK-NEXT: vadduqm 1, 3, 7
749 ; CHECK-NEXT: vadduqm 11, 5, 9
750 ; CHECK-NEXT: mffprd 3, 0
751 ; CHECK-NEXT: mffprd 6, 4
752 ; CHECK-NEXT: lwz 12, 8(1)
753 ; CHECK-NEXT: xxswapd 2, 35
754 ; CHECK-NEXT: xxswapd 5, 37
755 ; CHECK-NEXT: mffprd 4, 2
756 ; CHECK-NEXT: xxswapd 1, 32
757 ; CHECK-NEXT: xxswapd 6, 42
758 ; CHECK-NEXT: mffprd 5, 1
759 ; CHECK-NEXT: cmpld 5, 3
760 ; CHECK-NEXT: mffprd 7, 6
761 ; CHECK-NEXT: xxswapd 3, 33
762 ; CHECK-NEXT: xxswapd 7, 43
763 ; CHECK-NEXT: mffprd 3, 3
764 ; CHECK-NEXT: cmpld 5, 7, 6
765 ; CHECK-NEXT: mffprd 6, 5
766 ; CHECK-NEXT: mffprd 7, 7
767 ; CHECK-NEXT: mfvsrd 5, 36
768 ; CHECK-NEXT: cmpld 1, 3, 4
769 ; CHECK-NEXT: mfvsrd 3, 34
770 ; CHECK-NEXT: cmpld 6, 7, 6
771 ; CHECK-NEXT: mfvsrd 7, 32
772 ; CHECK-NEXT: mfvsrd 4, 35
773 ; CHECK-NEXT: mfvsrd 6, 37
774 ; CHECK-NEXT: cmpld 7, 7, 3
775 ; CHECK-NEXT: cmpd 2, 7, 3
776 ; CHECK-NEXT: mfvsrd 3, 33
777 ; CHECK-NEXT: crandc 21, 8, 30
778 ; CHECK-NEXT: crand 22, 30, 0
779 ; CHECK-NEXT: cmpld 3, 4
780 ; CHECK-NEXT: cmpd 7, 3, 4
781 ; CHECK-NEXT: mfvsrd 4, 42
782 ; CHECK-NEXT: sradi 3, 3, 63
783 ; CHECK-NEXT: mtocrf 32, 12
784 ; CHECK-NEXT: crnor 21, 22, 21
785 ; CHECK-NEXT: crandc 23, 28, 2
786 ; CHECK-NEXT: crand 25, 2, 4
787 ; CHECK-NEXT: cmpld 4, 5
788 ; CHECK-NEXT: cmpd 1, 4, 5
789 ; CHECK-NEXT: mfvsrd 5, 43
790 ; CHECK-NEXT: crnor 22, 25, 23
791 ; CHECK-NEXT: mtfprd 5, 3
792 ; CHECK-NEXT: sradi 4, 4, 63
793 ; CHECK-NEXT: mtfprd 6, 4
794 ; CHECK-NEXT: crandc 26, 4, 2
795 ; CHECK-NEXT: crand 20, 2, 20
796 ; CHECK-NEXT: cmpld 5, 6
797 ; CHECK-NEXT: cmpd 1, 5, 6
798 ; CHECK-NEXT: mfvsrd 6, 38
799 ; CHECK-NEXT: sradi 5, 5, 63
800 ; CHECK-NEXT: crnor 20, 20, 26
801 ; CHECK-NEXT: mtfprd 7, 5
802 ; CHECK-NEXT: sradi 6, 6, 63
803 ; CHECK-NEXT: crandc 27, 4, 2
804 ; CHECK-NEXT: crand 24, 2, 24
805 ; CHECK-NEXT: crnor 23, 24, 27
806 ; CHECK-NEXT: mtfprd 0, 6
807 ; CHECK-NEXT: mfvsrd 6, 39
808 ; CHECK-NEXT: sradi 6, 6, 63
809 ; CHECK-NEXT: mtfprd 1, 6
810 ; CHECK-NEXT: mfvsrd 6, 40
811 ; CHECK-NEXT: sradi 6, 6, 63
812 ; CHECK-NEXT: mtfprd 2, 6
813 ; CHECK-NEXT: mfvsrd 6, 41
814 ; CHECK-NEXT: sradi 6, 6, 63
815 ; CHECK-NEXT: mtfprd 3, 6
816 ; CHECK-NEXT: sradi 6, 7, 63
817 ; CHECK-NEXT: mtfprd 4, 6
818 ; CHECK-NEXT: li 6, -1
819 ; CHECK-NEXT: isel 3, 0, 6, 21
820 ; CHECK-NEXT: isel 4, 0, 6, 22
821 ; CHECK-NEXT: isel 5, 0, 6, 20
822 ; CHECK-NEXT: isel 6, 0, 6, 23
823 ; CHECK-NEXT: mtfprd 8, 3
824 ; CHECK-NEXT: addis 3, 2, .LCPI48_0@toc@ha
825 ; CHECK-NEXT: mtfprd 10, 4
826 ; CHECK-NEXT: mtfprd 11, 5
827 ; CHECK-NEXT: mtfprd 12, 6
828 ; CHECK-NEXT: addi 3, 3, .LCPI48_0@toc@l
829 ; CHECK-NEXT: lxvd2x 9, 0, 3
830 ; CHECK-NEXT: xxspltd 45, 6, 0
831 ; CHECK-NEXT: xxspltd 46, 7, 0
832 ; CHECK-NEXT: xxspltd 34, 0, 0
833 ; CHECK-NEXT: xxspltd 40, 5, 0
834 ; CHECK-NEXT: xxspltd 35, 1, 0
835 ; CHECK-NEXT: xxspltd 36, 2, 0
836 ; CHECK-NEXT: xxspltd 38, 3, 0
837 ; CHECK-NEXT: xxspltd 39, 4, 0
838 ; CHECK-NEXT: xxspltd 41, 8, 0
839 ; CHECK-NEXT: xxspltd 44, 10, 0
840 ; CHECK-NEXT: xxspltd 47, 11, 0
841 ; CHECK-NEXT: xxspltd 48, 12, 0
842 ; CHECK-NEXT: xxlxor 0, 34, 41
843 ; CHECK-NEXT: xxlxor 1, 35, 44
844 ; CHECK-NEXT: xxswapd 37, 9
845 ; CHECK-NEXT: xxlxor 2, 39, 37
846 ; CHECK-NEXT: xxlxor 3, 40, 37
847 ; CHECK-NEXT: xxsel 34, 32, 2, 0
848 ; CHECK-NEXT: xxsel 35, 33, 3, 1
849 ; CHECK-NEXT: xxlxor 0, 36, 47
850 ; CHECK-NEXT: xxlxor 1, 45, 37
851 ; CHECK-NEXT: xxsel 36, 42, 1, 0
852 ; CHECK-NEXT: xxlxor 0, 38, 48
853 ; CHECK-NEXT: xxlxor 1, 46, 37
854 ; CHECK-NEXT: xxsel 37, 43, 1, 0
856 %c = call <4 x i128> @llvm.sadd.sat.v4i128(<4 x i128> %a, <4 x i128> %b)
860 define i64 @unsigned_sat_constant_i64_with_single_use(i64 %x) {
861 ; CHECK-LABEL: unsigned_sat_constant_i64_with_single_use:
863 ; CHECK-NEXT: addi 4, 3, -4
864 ; CHECK-NEXT: cmpld 4, 3
865 ; CHECK-NEXT: iselgt 3, 0, 4
867 %umin = call i64 @llvm.umin.i64(i64 %x, i64 4)
868 %sub = sub i64 %x, %umin
872 define i64 @unsigned_sat_constant_i64_with_multiple_use(i64 %x, i64 %y) {
873 ; CHECK-LABEL: unsigned_sat_constant_i64_with_multiple_use:
875 ; CHECK-NEXT: cmpldi 3, 4
876 ; CHECK-NEXT: li 5, 4
877 ; CHECK-NEXT: isellt 5, 3, 5
878 ; CHECK-NEXT: sub 3, 3, 5
879 ; CHECK-NEXT: add 4, 4, 5
880 ; CHECK-NEXT: mulld 3, 3, 4
882 %umin = call i64 @llvm.umin.i64(i64 %x, i64 4)
883 %sub = sub i64 %x, %umin
884 %add = add i64 %y, %umin
885 %res = mul i64 %sub, %add
889 declare i64 @llvm.umin.i64(i64, i64)