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: isel 3, 3, 4, 0
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: rlwinm 3, 3, 0, 24, 31
28 ; CHECK-NEXT: addi 3, 3, 42
29 ; CHECK-NEXT: andi. 4, 3, 256
30 ; CHECK-NEXT: li 4, -1
31 ; CHECK-NEXT: isel 3, 3, 4, 2
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: isel 3, 4, 3, 1
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: isel 3, 3, 4, 0
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: rlwinm 3, 3, 0, 16, 31
73 ; CHECK-NEXT: addi 3, 3, 42
74 ; CHECK-NEXT: andis. 4, 3, 1
75 ; CHECK-NEXT: li 4, -1
76 ; CHECK-NEXT: isel 3, 3, 4, 2
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: isel 3, 4, 3, 1
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: isel 3, 3, 4, 0
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 0, 5, 3
119 ; CHECK-NEXT: isel 3, 4, 5, 0
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 0, 3, 4
133 ; CHECK-NEXT: li 3, -1
134 ; CHECK-NEXT: isel 3, 3, 5, 1
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: isel 3, 3, 4, 0
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: isel 3, 4, 5, 0
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: isel 3, 3, 5, 1
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: nor 5, 4, 4
189 ; CHECK-NEXT: clrlwi 6, 3, 24
190 ; CHECK-NEXT: clrlwi 7, 5, 24
191 ; CHECK-NEXT: cmplw 6, 7
192 ; CHECK-NEXT: isel 3, 3, 5, 0
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: rlwinm 4, 4, 0, 24, 31
206 ; CHECK-NEXT: rlwinm 3, 3, 0, 24, 31
207 ; CHECK-NEXT: add 3, 3, 4
208 ; CHECK-NEXT: andi. 4, 3, 256
209 ; CHECK-NEXT: li 4, -1
210 ; CHECK-NEXT: isel 3, 3, 4, 2
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: nor 6, 4, 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: isel 3, 5, 3, 1
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: nor 5, 4, 4
240 ; CHECK-NEXT: clrlwi 6, 3, 16
241 ; CHECK-NEXT: clrlwi 7, 5, 16
242 ; CHECK-NEXT: cmplw 6, 7
243 ; CHECK-NEXT: isel 3, 3, 5, 0
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: rlwinm 4, 4, 0, 16, 31
257 ; CHECK-NEXT: rlwinm 3, 3, 0, 16, 31
258 ; CHECK-NEXT: add 3, 3, 4
259 ; CHECK-NEXT: andis. 4, 3, 1
260 ; CHECK-NEXT: li 4, -1
261 ; CHECK-NEXT: isel 3, 3, 4, 2
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: nor 6, 4, 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: isel 3, 5, 3, 1
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: nor 5, 4, 4
291 ; CHECK-NEXT: cmplw 3, 5
292 ; CHECK-NEXT: isel 3, 3, 5, 0
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 0, 4, 3
308 ; CHECK-NEXT: isel 3, 5, 4, 0
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: nor 6, 4, 4
320 ; CHECK-NEXT: li 5, -1
321 ; CHECK-NEXT: cmplw 3, 6
322 ; CHECK-NEXT: add 3, 3, 4
323 ; CHECK-NEXT: isel 3, 5, 3, 1
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: isel 3, 3, 5, 0
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: isel 3, 5, 4, 0
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: isel 3, 5, 3, 1
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: vcmpgtub 4, 3, 2
386 ; CHECK-NEXT: xxsel 34, 35, 34, 36
387 ; CHECK-NEXT: lvx 3, 0, 3
388 ; CHECK-NEXT: vaddubm 2, 2, 3
390 %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>
391 %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>
392 %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>
396 define <16 x i8> @unsigned_sat_constant_v16i8_using_cmp_sum(<16 x i8> %x) {
397 ; CHECK-LABEL: unsigned_sat_constant_v16i8_using_cmp_sum:
399 ; CHECK-NEXT: addis 3, 2, .LCPI25_0@toc@ha
400 ; CHECK-NEXT: vspltisb 4, -1
401 ; CHECK-NEXT: addi 3, 3, .LCPI25_0@toc@l
402 ; CHECK-NEXT: lvx 3, 0, 3
403 ; CHECK-NEXT: vaddubm 3, 2, 3
404 ; CHECK-NEXT: vcmpgtub 2, 2, 3
405 ; CHECK-NEXT: xxsel 34, 35, 36, 34
407 %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>
408 %c = icmp ugt <16 x i8> %x, %a
409 %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
413 define <16 x i8> @unsigned_sat_constant_v16i8_using_cmp_notval(<16 x i8> %x) {
414 ; CHECK-LABEL: unsigned_sat_constant_v16i8_using_cmp_notval:
416 ; CHECK-NEXT: addis 3, 2, .LCPI26_1@toc@ha
417 ; CHECK-NEXT: vspltisb 5, -1
418 ; CHECK-NEXT: addi 3, 3, .LCPI26_1@toc@l
419 ; CHECK-NEXT: lvx 3, 0, 3
420 ; CHECK-NEXT: addis 3, 2, .LCPI26_0@toc@ha
421 ; CHECK-NEXT: addi 3, 3, .LCPI26_0@toc@l
422 ; CHECK-NEXT: vcmpgtub 3, 2, 3
423 ; CHECK-NEXT: lvx 4, 0, 3
424 ; CHECK-NEXT: vaddubm 2, 2, 4
425 ; CHECK-NEXT: xxsel 34, 34, 37, 35
427 %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>
428 %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>
429 %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
433 define <8 x i16> @unsigned_sat_constant_v8i16_using_min(<8 x i16> %x) {
434 ; CHECK-LABEL: unsigned_sat_constant_v8i16_using_min:
436 ; CHECK-NEXT: addis 3, 2, .LCPI27_0@toc@ha
437 ; CHECK-NEXT: addi 3, 3, .LCPI27_0@toc@l
438 ; CHECK-NEXT: lvx 3, 0, 3
439 ; CHECK-NEXT: addis 3, 2, .LCPI27_1@toc@ha
440 ; CHECK-NEXT: addi 3, 3, .LCPI27_1@toc@l
441 ; CHECK-NEXT: vcmpgtuh 4, 3, 2
442 ; CHECK-NEXT: xxsel 34, 35, 34, 36
443 ; CHECK-NEXT: lvx 3, 0, 3
444 ; CHECK-NEXT: vadduhm 2, 2, 3
446 %c = icmp ult <8 x i16> %x, <i16 -43, i16 -43, i16 -43, i16 -43, i16 -43, i16 -43, i16 -43, i16 -43>
447 %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>
448 %r = add <8 x i16> %s, <i16 42, i16 42, i16 42, i16 42, i16 42, i16 42, i16 42, i16 42>
452 define <8 x i16> @unsigned_sat_constant_v8i16_using_cmp_sum(<8 x i16> %x) {
453 ; CHECK-LABEL: unsigned_sat_constant_v8i16_using_cmp_sum:
455 ; CHECK-NEXT: addis 3, 2, .LCPI28_0@toc@ha
456 ; CHECK-NEXT: vspltisb 4, -1
457 ; CHECK-NEXT: addi 3, 3, .LCPI28_0@toc@l
458 ; CHECK-NEXT: lvx 3, 0, 3
459 ; CHECK-NEXT: vadduhm 3, 2, 3
460 ; CHECK-NEXT: vcmpgtuh 2, 2, 3
461 ; CHECK-NEXT: xxsel 34, 35, 36, 34
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, %a
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 <8 x i16> @unsigned_sat_constant_v8i16_using_cmp_notval(<8 x i16> %x) {
470 ; CHECK-LABEL: unsigned_sat_constant_v8i16_using_cmp_notval:
472 ; CHECK-NEXT: addis 3, 2, .LCPI29_1@toc@ha
473 ; CHECK-NEXT: vspltisb 5, -1
474 ; CHECK-NEXT: addi 3, 3, .LCPI29_1@toc@l
475 ; CHECK-NEXT: lvx 3, 0, 3
476 ; CHECK-NEXT: addis 3, 2, .LCPI29_0@toc@ha
477 ; CHECK-NEXT: addi 3, 3, .LCPI29_0@toc@l
478 ; CHECK-NEXT: vcmpgtuh 3, 2, 3
479 ; CHECK-NEXT: lvx 4, 0, 3
480 ; CHECK-NEXT: vadduhm 2, 2, 4
481 ; CHECK-NEXT: xxsel 34, 34, 37, 35
483 %a = add <8 x i16> %x, <i16 42, i16 42, i16 42, i16 42, i16 42, i16 42, i16 42, i16 42>
484 %c = icmp ugt <8 x i16> %x, <i16 -43, i16 -43, i16 -43, i16 -43, i16 -43, i16 -43, i16 -43, i16 -43>
485 %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
489 define <4 x i32> @unsigned_sat_constant_v4i32_using_min(<4 x i32> %x) {
490 ; CHECK-LABEL: unsigned_sat_constant_v4i32_using_min:
492 ; CHECK-NEXT: addis 3, 2, .LCPI30_0@toc@ha
493 ; CHECK-NEXT: addi 3, 3, .LCPI30_0@toc@l
494 ; CHECK-NEXT: lvx 3, 0, 3
495 ; CHECK-NEXT: addis 3, 2, .LCPI30_1@toc@ha
496 ; CHECK-NEXT: addi 3, 3, .LCPI30_1@toc@l
497 ; CHECK-NEXT: vcmpgtuw 4, 3, 2
498 ; CHECK-NEXT: xxsel 34, 35, 34, 36
499 ; CHECK-NEXT: lvx 3, 0, 3
500 ; CHECK-NEXT: vadduwm 2, 2, 3
502 %c = icmp ult <4 x i32> %x, <i32 -43, i32 -43, i32 -43, i32 -43>
503 %s = select <4 x i1> %c, <4 x i32> %x, <4 x i32> <i32 -43, i32 -43, i32 -43, i32 -43>
504 %r = add <4 x i32> %s, <i32 42, i32 42, i32 42, i32 42>
508 define <4 x i32> @unsigned_sat_constant_v4i32_using_cmp_sum(<4 x i32> %x) {
509 ; CHECK-LABEL: unsigned_sat_constant_v4i32_using_cmp_sum:
511 ; CHECK-NEXT: addis 3, 2, .LCPI31_0@toc@ha
512 ; CHECK-NEXT: vspltisb 4, -1
513 ; CHECK-NEXT: addi 3, 3, .LCPI31_0@toc@l
514 ; CHECK-NEXT: lvx 3, 0, 3
515 ; CHECK-NEXT: vadduwm 3, 2, 3
516 ; CHECK-NEXT: vcmpgtuw 2, 2, 3
517 ; CHECK-NEXT: xxsel 34, 35, 36, 34
519 %a = add <4 x i32> %x, <i32 42, i32 42, i32 42, i32 42>
520 %c = icmp ugt <4 x i32> %x, %a
521 %r = select <4 x i1> %c, <4 x i32> <i32 -1, i32 -1, i32 -1, i32 -1>, <4 x i32> %a
525 define <4 x i32> @unsigned_sat_constant_v4i32_using_cmp_notval(<4 x i32> %x) {
526 ; CHECK-LABEL: unsigned_sat_constant_v4i32_using_cmp_notval:
528 ; CHECK-NEXT: addis 3, 2, .LCPI32_1@toc@ha
529 ; CHECK-NEXT: vspltisb 5, -1
530 ; CHECK-NEXT: addi 3, 3, .LCPI32_1@toc@l
531 ; CHECK-NEXT: lvx 3, 0, 3
532 ; CHECK-NEXT: addis 3, 2, .LCPI32_0@toc@ha
533 ; CHECK-NEXT: addi 3, 3, .LCPI32_0@toc@l
534 ; CHECK-NEXT: vcmpgtuw 3, 2, 3
535 ; CHECK-NEXT: lvx 4, 0, 3
536 ; CHECK-NEXT: vadduwm 2, 2, 4
537 ; CHECK-NEXT: xxsel 34, 34, 37, 35
539 %a = add <4 x i32> %x, <i32 42, i32 42, i32 42, i32 42>
540 %c = icmp ugt <4 x i32> %x, <i32 -43, i32 -43, i32 -43, i32 -43>
541 %r = select <4 x i1> %c, <4 x i32> <i32 -1, i32 -1, i32 -1, i32 -1>, <4 x i32> %a
545 define <2 x i64> @unsigned_sat_constant_v2i64_using_min(<2 x i64> %x) {
546 ; CHECK-LABEL: unsigned_sat_constant_v2i64_using_min:
548 ; CHECK-NEXT: addis 3, 2, .LCPI33_0@toc@ha
549 ; CHECK-NEXT: addi 3, 3, .LCPI33_0@toc@l
550 ; CHECK-NEXT: lxvd2x 0, 0, 3
551 ; CHECK-NEXT: addis 3, 2, .LCPI33_1@toc@ha
552 ; CHECK-NEXT: addi 3, 3, .LCPI33_1@toc@l
553 ; CHECK-NEXT: xxswapd 35, 0
554 ; CHECK-NEXT: lxvd2x 0, 0, 3
555 ; CHECK-NEXT: vcmpgtud 4, 3, 2
556 ; CHECK-NEXT: xxsel 34, 35, 34, 36
557 ; CHECK-NEXT: xxswapd 35, 0
558 ; CHECK-NEXT: vaddudm 2, 2, 3
560 %c = icmp ult <2 x i64> %x, <i64 -43, i64 -43>
561 %s = select <2 x i1> %c, <2 x i64> %x, <2 x i64> <i64 -43, i64 -43>
562 %r = add <2 x i64> %s, <i64 42, i64 42>
566 define <2 x i64> @unsigned_sat_constant_v2i64_using_cmp_sum(<2 x i64> %x) {
567 ; CHECK-LABEL: unsigned_sat_constant_v2i64_using_cmp_sum:
569 ; CHECK-NEXT: addis 3, 2, .LCPI34_0@toc@ha
570 ; CHECK-NEXT: vspltisb 4, -1
571 ; CHECK-NEXT: addi 3, 3, .LCPI34_0@toc@l
572 ; CHECK-NEXT: lxvd2x 0, 0, 3
573 ; CHECK-NEXT: xxswapd 35, 0
574 ; CHECK-NEXT: vaddudm 3, 2, 3
575 ; CHECK-NEXT: vcmpgtud 2, 2, 3
576 ; CHECK-NEXT: xxsel 34, 35, 36, 34
578 %a = add <2 x i64> %x, <i64 42, i64 42>
579 %c = icmp ugt <2 x i64> %x, %a
580 %r = select <2 x i1> %c, <2 x i64> <i64 -1, i64 -1>, <2 x i64> %a
584 define <2 x i64> @unsigned_sat_constant_v2i64_using_cmp_notval(<2 x i64> %x) {
585 ; CHECK-LABEL: unsigned_sat_constant_v2i64_using_cmp_notval:
587 ; CHECK-NEXT: addis 3, 2, .LCPI35_1@toc@ha
588 ; CHECK-NEXT: vspltisb 5, -1
589 ; CHECK-NEXT: addi 3, 3, .LCPI35_1@toc@l
590 ; CHECK-NEXT: lxvd2x 0, 0, 3
591 ; CHECK-NEXT: addis 3, 2, .LCPI35_0@toc@ha
592 ; CHECK-NEXT: addi 3, 3, .LCPI35_0@toc@l
593 ; CHECK-NEXT: xxswapd 35, 0
594 ; CHECK-NEXT: lxvd2x 0, 0, 3
595 ; CHECK-NEXT: vcmpgtud 3, 2, 3
596 ; CHECK-NEXT: xxswapd 36, 0
597 ; CHECK-NEXT: vaddudm 2, 2, 4
598 ; CHECK-NEXT: xxsel 34, 34, 37, 35
600 %a = add <2 x i64> %x, <i64 42, i64 42>
601 %c = icmp ugt <2 x i64> %x, <i64 -43, i64 -43>
602 %r = select <2 x i1> %c, <2 x i64> <i64 -1, i64 -1>, <2 x i64> %a
606 define <16 x i8> @unsigned_sat_variable_v16i8_using_min(<16 x i8> %x, <16 x i8> %y) {
607 ; CHECK-LABEL: unsigned_sat_variable_v16i8_using_min:
609 ; CHECK-NEXT: xxlnor 36, 35, 35
610 ; CHECK-NEXT: vcmpgtub 5, 4, 2
611 ; CHECK-NEXT: xxsel 34, 36, 34, 37
612 ; CHECK-NEXT: vaddubm 2, 2, 3
614 %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>
615 %c = icmp ult <16 x i8> %x, %noty
616 %s = select <16 x i1> %c, <16 x i8> %x, <16 x i8> %noty
617 %r = add <16 x i8> %s, %y
621 define <16 x i8> @unsigned_sat_variable_v16i8_using_cmp_sum(<16 x i8> %x, <16 x i8> %y) {
622 ; CHECK-LABEL: unsigned_sat_variable_v16i8_using_cmp_sum:
624 ; CHECK-NEXT: vaddubm 3, 2, 3
625 ; CHECK-NEXT: vspltisb 4, -1
626 ; CHECK-NEXT: vcmpgtub 2, 2, 3
627 ; CHECK-NEXT: xxsel 34, 35, 36, 34
629 %a = add <16 x i8> %x, %y
630 %c = icmp ugt <16 x i8> %x, %a
631 %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
635 define <16 x i8> @unsigned_sat_variable_v16i8_using_cmp_notval(<16 x i8> %x, <16 x i8> %y) {
636 ; CHECK-LABEL: unsigned_sat_variable_v16i8_using_cmp_notval:
638 ; CHECK-NEXT: xxlnor 36, 35, 35
639 ; CHECK-NEXT: vspltisb 5, -1
640 ; CHECK-NEXT: vcmpgtub 4, 2, 4
641 ; CHECK-NEXT: vaddubm 2, 2, 3
642 ; CHECK-NEXT: xxsel 34, 34, 37, 36
644 %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>
645 %a = add <16 x i8> %x, %y
646 %c = icmp ugt <16 x i8> %x, %noty
647 %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
651 define <8 x i16> @unsigned_sat_variable_v8i16_using_min(<8 x i16> %x, <8 x i16> %y) {
652 ; CHECK-LABEL: unsigned_sat_variable_v8i16_using_min:
654 ; CHECK-NEXT: xxlnor 36, 35, 35
655 ; CHECK-NEXT: vcmpgtuh 5, 4, 2
656 ; CHECK-NEXT: xxsel 34, 36, 34, 37
657 ; CHECK-NEXT: vadduhm 2, 2, 3
659 %noty = xor <8 x i16> %y, <i16 -1, i16 -1, i16 -1, i16 -1, i16 -1, i16 -1, i16 -1, i16 -1>
660 %c = icmp ult <8 x i16> %x, %noty
661 %s = select <8 x i1> %c, <8 x i16> %x, <8 x i16> %noty
662 %r = add <8 x i16> %s, %y
666 define <8 x i16> @unsigned_sat_variable_v8i16_using_cmp_sum(<8 x i16> %x, <8 x i16> %y) {
667 ; CHECK-LABEL: unsigned_sat_variable_v8i16_using_cmp_sum:
669 ; CHECK-NEXT: vadduhm 3, 2, 3
670 ; CHECK-NEXT: vspltisb 4, -1
671 ; CHECK-NEXT: vcmpgtuh 2, 2, 3
672 ; CHECK-NEXT: xxsel 34, 35, 36, 34
674 %a = add <8 x i16> %x, %y
675 %c = icmp ugt <8 x i16> %x, %a
676 %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
680 define <8 x i16> @unsigned_sat_variable_v8i16_using_cmp_notval(<8 x i16> %x, <8 x i16> %y) {
681 ; CHECK-LABEL: unsigned_sat_variable_v8i16_using_cmp_notval:
683 ; CHECK-NEXT: xxlnor 36, 35, 35
684 ; CHECK-NEXT: vspltisb 5, -1
685 ; CHECK-NEXT: vcmpgtuh 4, 2, 4
686 ; CHECK-NEXT: vadduhm 2, 2, 3
687 ; CHECK-NEXT: xxsel 34, 34, 37, 36
689 %noty = xor <8 x i16> %y, <i16 -1, i16 -1, i16 -1, i16 -1, i16 -1, i16 -1, i16 -1, i16 -1>
690 %a = add <8 x i16> %x, %y
691 %c = icmp ugt <8 x i16> %x, %noty
692 %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
696 define <4 x i32> @unsigned_sat_variable_v4i32_using_min(<4 x i32> %x, <4 x i32> %y) {
697 ; CHECK-LABEL: unsigned_sat_variable_v4i32_using_min:
699 ; CHECK-NEXT: xxlnor 36, 35, 35
700 ; CHECK-NEXT: vcmpgtuw 5, 4, 2
701 ; CHECK-NEXT: xxsel 34, 36, 34, 37
702 ; CHECK-NEXT: vadduwm 2, 2, 3
704 %noty = xor <4 x i32> %y, <i32 -1, i32 -1, i32 -1, i32 -1>
705 %c = icmp ult <4 x i32> %x, %noty
706 %s = select <4 x i1> %c, <4 x i32> %x, <4 x i32> %noty
707 %r = add <4 x i32> %s, %y
711 define <4 x i32> @unsigned_sat_variable_v4i32_using_cmp_sum(<4 x i32> %x, <4 x i32> %y) {
712 ; CHECK-LABEL: unsigned_sat_variable_v4i32_using_cmp_sum:
714 ; CHECK-NEXT: vadduwm 3, 2, 3
715 ; CHECK-NEXT: vspltisb 4, -1
716 ; CHECK-NEXT: vcmpgtuw 2, 2, 3
717 ; CHECK-NEXT: xxsel 34, 35, 36, 34
719 %a = add <4 x i32> %x, %y
720 %c = icmp ugt <4 x i32> %x, %a
721 %r = select <4 x i1> %c, <4 x i32> <i32 -1, i32 -1, i32 -1, i32 -1>, <4 x i32> %a
725 define <4 x i32> @unsigned_sat_variable_v4i32_using_cmp_notval(<4 x i32> %x, <4 x i32> %y) {
726 ; CHECK-LABEL: unsigned_sat_variable_v4i32_using_cmp_notval:
728 ; CHECK-NEXT: xxlnor 36, 35, 35
729 ; CHECK-NEXT: vspltisb 5, -1
730 ; CHECK-NEXT: vcmpgtuw 4, 2, 4
731 ; CHECK-NEXT: vadduwm 2, 2, 3
732 ; CHECK-NEXT: xxsel 34, 34, 37, 36
734 %noty = xor <4 x i32> %y, <i32 -1, i32 -1, i32 -1, i32 -1>
735 %a = add <4 x i32> %x, %y
736 %c = icmp ugt <4 x i32> %x, %noty
737 %r = select <4 x i1> %c, <4 x i32> <i32 -1, i32 -1, i32 -1, i32 -1>, <4 x i32> %a
741 define <2 x i64> @unsigned_sat_variable_v2i64_using_min(<2 x i64> %x, <2 x i64> %y) {
742 ; CHECK-LABEL: unsigned_sat_variable_v2i64_using_min:
744 ; CHECK-NEXT: xxlnor 36, 35, 35
745 ; CHECK-NEXT: vcmpgtud 5, 4, 2
746 ; CHECK-NEXT: xxsel 34, 36, 34, 37
747 ; CHECK-NEXT: vaddudm 2, 2, 3
749 %noty = xor <2 x i64> %y, <i64 -1, i64 -1>
750 %c = icmp ult <2 x i64> %x, %noty
751 %s = select <2 x i1> %c, <2 x i64> %x, <2 x i64> %noty
752 %r = add <2 x i64> %s, %y
756 define <2 x i64> @unsigned_sat_variable_v2i64_using_cmp_sum(<2 x i64> %x, <2 x i64> %y) {
757 ; CHECK-LABEL: unsigned_sat_variable_v2i64_using_cmp_sum:
759 ; CHECK-NEXT: vaddudm 3, 2, 3
760 ; CHECK-NEXT: vspltisb 4, -1
761 ; CHECK-NEXT: vcmpgtud 2, 2, 3
762 ; CHECK-NEXT: xxsel 34, 35, 36, 34
764 %a = add <2 x i64> %x, %y
765 %c = icmp ugt <2 x i64> %x, %a
766 %r = select <2 x i1> %c, <2 x i64> <i64 -1, i64 -1>, <2 x i64> %a
770 define <2 x i64> @unsigned_sat_variable_v2i64_using_cmp_notval(<2 x i64> %x, <2 x i64> %y) {
771 ; CHECK-LABEL: unsigned_sat_variable_v2i64_using_cmp_notval:
773 ; CHECK-NEXT: xxlnor 36, 35, 35
774 ; CHECK-NEXT: vspltisb 5, -1
775 ; CHECK-NEXT: vcmpgtud 4, 2, 4
776 ; CHECK-NEXT: vaddudm 2, 2, 3
777 ; CHECK-NEXT: xxsel 34, 34, 37, 36
779 %noty = xor <2 x i64> %y, <i64 -1, i64 -1>
780 %a = add <2 x i64> %x, %y
781 %c = icmp ugt <2 x i64> %x, %noty
782 %r = select <2 x i1> %c, <2 x i64> <i64 -1, i64 -1>, <2 x i64> %a