1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc < %s -mtriple=aarch64-- | 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: and w8, w0, #0xff
13 ; CHECK-NEXT: cmp w8, #213 // =213
14 ; CHECK-NEXT: mov w8, #-43
15 ; CHECK-NEXT: csel w8, w0, w8, lo
16 ; CHECK-NEXT: add w0, w8, #42 // =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: and w8, w0, #0xff
28 ; CHECK-NEXT: add w8, w8, #42 // =42
29 ; CHECK-NEXT: tst w8, #0x100
30 ; CHECK-NEXT: csinv w0, w8, wzr, eq
33 %c = icmp ugt i8 %x, %a
34 %r = select i1 %c, i8 -1, i8 %a
38 define i8 @unsigned_sat_constant_i8_using_cmp_notval(i8 %x) {
39 ; CHECK-LABEL: unsigned_sat_constant_i8_using_cmp_notval:
41 ; CHECK-NEXT: and w8, w0, #0xff
42 ; CHECK-NEXT: add w9, w0, #42 // =42
43 ; CHECK-NEXT: cmp w8, #213 // =213
44 ; CHECK-NEXT: csinv w0, w9, wzr, ls
47 %c = icmp ugt i8 %x, -43
48 %r = select i1 %c, i8 -1, i8 %a
52 define i16 @unsigned_sat_constant_i16_using_min(i16 %x) {
53 ; CHECK-LABEL: unsigned_sat_constant_i16_using_min:
55 ; CHECK-NEXT: mov w8, #65493
56 ; CHECK-NEXT: cmp w8, w0, uxth
57 ; CHECK-NEXT: mov w8, #-43
58 ; CHECK-NEXT: csel w8, w0, w8, hi
59 ; CHECK-NEXT: add w0, w8, #42 // =42
61 %c = icmp ult i16 %x, -43
62 %s = select i1 %c, i16 %x, i16 -43
67 define i16 @unsigned_sat_constant_i16_using_cmp_sum(i16 %x) {
68 ; CHECK-LABEL: unsigned_sat_constant_i16_using_cmp_sum:
70 ; CHECK-NEXT: and w8, w0, #0xffff
71 ; CHECK-NEXT: add w8, w8, #42 // =42
72 ; CHECK-NEXT: tst w8, #0x10000
73 ; CHECK-NEXT: csinv w0, w8, wzr, eq
76 %c = icmp ugt i16 %x, %a
77 %r = select i1 %c, i16 -1, i16 %a
81 define i16 @unsigned_sat_constant_i16_using_cmp_notval(i16 %x) {
82 ; CHECK-LABEL: unsigned_sat_constant_i16_using_cmp_notval:
84 ; CHECK-NEXT: mov w9, #65493
85 ; CHECK-NEXT: add w8, w0, #42 // =42
86 ; CHECK-NEXT: cmp w9, w0, uxth
87 ; CHECK-NEXT: csinv w0, w8, wzr, hs
90 %c = icmp ugt i16 %x, -43
91 %r = select i1 %c, i16 -1, i16 %a
95 define i32 @unsigned_sat_constant_i32_using_min(i32 %x) {
96 ; CHECK-LABEL: unsigned_sat_constant_i32_using_min:
98 ; CHECK-NEXT: cmn w0, #43 // =43
99 ; CHECK-NEXT: mov w8, #-43
100 ; CHECK-NEXT: csel w8, w0, w8, lo
101 ; CHECK-NEXT: add w0, w8, #42 // =42
103 %c = icmp ult i32 %x, -43
104 %s = select i1 %c, i32 %x, i32 -43
109 define i32 @unsigned_sat_constant_i32_using_cmp_sum(i32 %x) {
110 ; CHECK-LABEL: unsigned_sat_constant_i32_using_cmp_sum:
112 ; CHECK-NEXT: adds w8, w0, #42 // =42
113 ; CHECK-NEXT: csinv w0, w8, wzr, lo
116 %c = icmp ugt i32 %x, %a
117 %r = select i1 %c, i32 -1, i32 %a
121 define i32 @unsigned_sat_constant_i32_using_cmp_notval(i32 %x) {
122 ; CHECK-LABEL: unsigned_sat_constant_i32_using_cmp_notval:
124 ; CHECK-NEXT: adds w8, w0, #42 // =42
125 ; CHECK-NEXT: csinv w0, w8, wzr, lo
128 %c = icmp ugt i32 %x, -43
129 %r = select i1 %c, i32 -1, i32 %a
133 define i64 @unsigned_sat_constant_i64_using_min(i64 %x) {
134 ; CHECK-LABEL: unsigned_sat_constant_i64_using_min:
136 ; CHECK-NEXT: cmn x0, #43 // =43
137 ; CHECK-NEXT: mov x8, #-43
138 ; CHECK-NEXT: csel x8, x0, x8, lo
139 ; CHECK-NEXT: add x0, x8, #42 // =42
141 %c = icmp ult i64 %x, -43
142 %s = select i1 %c, i64 %x, i64 -43
147 define i64 @unsigned_sat_constant_i64_using_cmp_sum(i64 %x) {
148 ; CHECK-LABEL: unsigned_sat_constant_i64_using_cmp_sum:
150 ; CHECK-NEXT: adds x8, x0, #42 // =42
151 ; CHECK-NEXT: csinv x0, x8, xzr, lo
154 %c = icmp ugt i64 %x, %a
155 %r = select i1 %c, i64 -1, i64 %a
159 define i64 @unsigned_sat_constant_i64_using_cmp_notval(i64 %x) {
160 ; CHECK-LABEL: unsigned_sat_constant_i64_using_cmp_notval:
162 ; CHECK-NEXT: adds x8, x0, #42 // =42
163 ; CHECK-NEXT: csinv x0, x8, xzr, lo
166 %c = icmp ugt i64 %x, -43
167 %r = select i1 %c, i64 -1, i64 %a
171 define i8 @unsigned_sat_variable_i8_using_min(i8 %x, i8 %y) {
172 ; CHECK-LABEL: unsigned_sat_variable_i8_using_min:
174 ; CHECK-NEXT: and w8, w0, #0xff
175 ; CHECK-NEXT: mvn w9, w1
176 ; CHECK-NEXT: cmp w8, w9, uxtb
177 ; CHECK-NEXT: csinv w8, w0, w1, lo
178 ; CHECK-NEXT: add w0, w8, w1
180 %noty = xor i8 %y, -1
181 %c = icmp ult i8 %x, %noty
182 %s = select i1 %c, i8 %x, i8 %noty
187 define i8 @unsigned_sat_variable_i8_using_cmp_sum(i8 %x, i8 %y) {
188 ; CHECK-LABEL: unsigned_sat_variable_i8_using_cmp_sum:
190 ; CHECK-NEXT: and w8, w0, #0xff
191 ; CHECK-NEXT: add w8, w8, w1, uxtb
192 ; CHECK-NEXT: tst w8, #0x100
193 ; CHECK-NEXT: csinv w0, w8, wzr, eq
196 %c = icmp ugt i8 %x, %a
197 %r = select i1 %c, i8 -1, i8 %a
201 define i8 @unsigned_sat_variable_i8_using_cmp_notval(i8 %x, i8 %y) {
202 ; CHECK-LABEL: unsigned_sat_variable_i8_using_cmp_notval:
204 ; CHECK-NEXT: and w8, w0, #0xff
205 ; CHECK-NEXT: mvn w9, w1
206 ; CHECK-NEXT: add w10, w0, w1
207 ; CHECK-NEXT: cmp w8, w9, uxtb
208 ; CHECK-NEXT: csinv w0, w10, wzr, ls
210 %noty = xor i8 %y, -1
212 %c = icmp ugt i8 %x, %noty
213 %r = select i1 %c, i8 -1, i8 %a
217 define i16 @unsigned_sat_variable_i16_using_min(i16 %x, i16 %y) {
218 ; CHECK-LABEL: unsigned_sat_variable_i16_using_min:
220 ; CHECK-NEXT: and w8, w0, #0xffff
221 ; CHECK-NEXT: mvn w9, w1
222 ; CHECK-NEXT: cmp w8, w9, uxth
223 ; CHECK-NEXT: csinv w8, w0, w1, lo
224 ; CHECK-NEXT: add w0, w8, w1
226 %noty = xor i16 %y, -1
227 %c = icmp ult i16 %x, %noty
228 %s = select i1 %c, i16 %x, i16 %noty
233 define i16 @unsigned_sat_variable_i16_using_cmp_sum(i16 %x, i16 %y) {
234 ; CHECK-LABEL: unsigned_sat_variable_i16_using_cmp_sum:
236 ; CHECK-NEXT: and w8, w0, #0xffff
237 ; CHECK-NEXT: add w8, w8, w1, uxth
238 ; CHECK-NEXT: tst w8, #0x10000
239 ; CHECK-NEXT: csinv w0, w8, wzr, eq
242 %c = icmp ugt i16 %x, %a
243 %r = select i1 %c, i16 -1, i16 %a
247 define i16 @unsigned_sat_variable_i16_using_cmp_notval(i16 %x, i16 %y) {
248 ; CHECK-LABEL: unsigned_sat_variable_i16_using_cmp_notval:
250 ; CHECK-NEXT: and w8, w0, #0xffff
251 ; CHECK-NEXT: mvn w9, w1
252 ; CHECK-NEXT: add w10, w0, w1
253 ; CHECK-NEXT: cmp w8, w9, uxth
254 ; CHECK-NEXT: csinv w0, w10, wzr, ls
256 %noty = xor i16 %y, -1
258 %c = icmp ugt i16 %x, %noty
259 %r = select i1 %c, i16 -1, i16 %a
263 define i32 @unsigned_sat_variable_i32_using_min(i32 %x, i32 %y) {
264 ; CHECK-LABEL: unsigned_sat_variable_i32_using_min:
266 ; CHECK-NEXT: mvn w8, w1
267 ; CHECK-NEXT: cmp w0, w8
268 ; CHECK-NEXT: csinv w8, w0, w1, lo
269 ; CHECK-NEXT: add w0, w8, w1
271 %noty = xor i32 %y, -1
272 %c = icmp ult i32 %x, %noty
273 %s = select i1 %c, i32 %x, i32 %noty
278 define i32 @unsigned_sat_variable_i32_using_cmp_sum(i32 %x, i32 %y) {
279 ; CHECK-LABEL: unsigned_sat_variable_i32_using_cmp_sum:
281 ; CHECK-NEXT: adds w8, w0, w1
282 ; CHECK-NEXT: csinv w0, w8, wzr, lo
285 %c = icmp ugt i32 %x, %a
286 %r = select i1 %c, i32 -1, i32 %a
290 define i32 @unsigned_sat_variable_i32_using_cmp_notval(i32 %x, i32 %y) {
291 ; CHECK-LABEL: unsigned_sat_variable_i32_using_cmp_notval:
293 ; CHECK-NEXT: mvn w8, w1
294 ; CHECK-NEXT: add w9, w0, w1
295 ; CHECK-NEXT: cmp w0, w8
296 ; CHECK-NEXT: csinv w0, w9, wzr, ls
298 %noty = xor i32 %y, -1
300 %c = icmp ugt i32 %x, %noty
301 %r = select i1 %c, i32 -1, i32 %a
305 define i64 @unsigned_sat_variable_i64_using_min(i64 %x, i64 %y) {
306 ; CHECK-LABEL: unsigned_sat_variable_i64_using_min:
308 ; CHECK-NEXT: mvn x8, x1
309 ; CHECK-NEXT: cmp x0, x8
310 ; CHECK-NEXT: csinv x8, x0, x1, lo
311 ; CHECK-NEXT: add x0, x8, x1
313 %noty = xor i64 %y, -1
314 %c = icmp ult i64 %x, %noty
315 %s = select i1 %c, i64 %x, i64 %noty
320 define i64 @unsigned_sat_variable_i64_using_cmp_sum(i64 %x, i64 %y) {
321 ; CHECK-LABEL: unsigned_sat_variable_i64_using_cmp_sum:
323 ; CHECK-NEXT: adds x8, x0, x1
324 ; CHECK-NEXT: csinv x0, x8, xzr, lo
327 %c = icmp ugt i64 %x, %a
328 %r = select i1 %c, i64 -1, i64 %a
332 define i64 @unsigned_sat_variable_i64_using_cmp_notval(i64 %x, i64 %y) {
333 ; CHECK-LABEL: unsigned_sat_variable_i64_using_cmp_notval:
335 ; CHECK-NEXT: mvn x8, x1
336 ; CHECK-NEXT: add x9, x0, x1
337 ; CHECK-NEXT: cmp x0, x8
338 ; CHECK-NEXT: csinv x0, x9, xzr, ls
340 %noty = xor i64 %y, -1
342 %c = icmp ugt i64 %x, %noty
343 %r = select i1 %c, i64 -1, i64 %a
347 define <16 x i8> @unsigned_sat_constant_v16i8_using_min(<16 x i8> %x) {
348 ; CHECK-LABEL: unsigned_sat_constant_v16i8_using_min:
350 ; CHECK-NEXT: movi v1.16b, #213
351 ; CHECK-NEXT: umin v0.16b, v0.16b, v1.16b
352 ; CHECK-NEXT: movi v1.16b, #42
353 ; CHECK-NEXT: add v0.16b, v0.16b, v1.16b
355 %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>
356 %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>
357 %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>
361 define <16 x i8> @unsigned_sat_constant_v16i8_using_cmp_sum(<16 x i8> %x) {
362 ; CHECK-LABEL: unsigned_sat_constant_v16i8_using_cmp_sum:
364 ; CHECK-NEXT: movi v1.16b, #42
365 ; CHECK-NEXT: add v1.16b, v0.16b, v1.16b
366 ; CHECK-NEXT: cmhi v0.16b, v0.16b, v1.16b
367 ; CHECK-NEXT: orr v0.16b, v1.16b, v0.16b
369 %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>
370 %c = icmp ugt <16 x i8> %x, %a
371 %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
375 define <16 x i8> @unsigned_sat_constant_v16i8_using_cmp_notval(<16 x i8> %x) {
376 ; CHECK-LABEL: unsigned_sat_constant_v16i8_using_cmp_notval:
378 ; CHECK-NEXT: movi v1.16b, #42
379 ; CHECK-NEXT: movi v2.16b, #213
380 ; CHECK-NEXT: add v1.16b, v0.16b, v1.16b
381 ; CHECK-NEXT: cmhi v0.16b, v0.16b, v2.16b
382 ; CHECK-NEXT: orr v0.16b, v1.16b, v0.16b
384 %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>
385 %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>
386 %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
390 define <8 x i16> @unsigned_sat_constant_v8i16_using_min(<8 x i16> %x) {
391 ; CHECK-LABEL: unsigned_sat_constant_v8i16_using_min:
393 ; CHECK-NEXT: mvni v1.8h, #42
394 ; CHECK-NEXT: umin v0.8h, v0.8h, v1.8h
395 ; CHECK-NEXT: movi v1.8h, #42
396 ; CHECK-NEXT: add v0.8h, v0.8h, v1.8h
398 %c = icmp ult <8 x i16> %x, <i16 -43, i16 -43, i16 -43, i16 -43, i16 -43, i16 -43, i16 -43, i16 -43>
399 %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>
400 %r = add <8 x i16> %s, <i16 42, i16 42, i16 42, i16 42, i16 42, i16 42, i16 42, i16 42>
404 define <8 x i16> @unsigned_sat_constant_v8i16_using_cmp_sum(<8 x i16> %x) {
405 ; CHECK-LABEL: unsigned_sat_constant_v8i16_using_cmp_sum:
407 ; CHECK-NEXT: movi v1.8h, #42
408 ; CHECK-NEXT: add v1.8h, v0.8h, v1.8h
409 ; CHECK-NEXT: cmhi v0.8h, v0.8h, v1.8h
410 ; CHECK-NEXT: orr v0.16b, v1.16b, v0.16b
412 %a = add <8 x i16> %x, <i16 42, i16 42, i16 42, i16 42, i16 42, i16 42, i16 42, i16 42>
413 %c = icmp ugt <8 x i16> %x, %a
414 %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
418 define <8 x i16> @unsigned_sat_constant_v8i16_using_cmp_notval(<8 x i16> %x) {
419 ; CHECK-LABEL: unsigned_sat_constant_v8i16_using_cmp_notval:
421 ; CHECK-NEXT: movi v1.8h, #42
422 ; CHECK-NEXT: mvni v2.8h, #42
423 ; CHECK-NEXT: add v1.8h, v0.8h, v1.8h
424 ; CHECK-NEXT: cmhi v0.8h, v0.8h, v2.8h
425 ; CHECK-NEXT: orr v0.16b, v1.16b, v0.16b
427 %a = add <8 x i16> %x, <i16 42, i16 42, i16 42, i16 42, i16 42, i16 42, i16 42, i16 42>
428 %c = icmp ugt <8 x i16> %x, <i16 -43, i16 -43, i16 -43, i16 -43, i16 -43, i16 -43, i16 -43, i16 -43>
429 %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
433 define <4 x i32> @unsigned_sat_constant_v4i32_using_min(<4 x i32> %x) {
434 ; CHECK-LABEL: unsigned_sat_constant_v4i32_using_min:
436 ; CHECK-NEXT: mvni v1.4s, #42
437 ; CHECK-NEXT: umin v0.4s, v0.4s, v1.4s
438 ; CHECK-NEXT: movi v1.4s, #42
439 ; CHECK-NEXT: add v0.4s, v0.4s, v1.4s
441 %c = icmp ult <4 x i32> %x, <i32 -43, i32 -43, i32 -43, i32 -43>
442 %s = select <4 x i1> %c, <4 x i32> %x, <4 x i32> <i32 -43, i32 -43, i32 -43, i32 -43>
443 %r = add <4 x i32> %s, <i32 42, i32 42, i32 42, i32 42>
447 define <4 x i32> @unsigned_sat_constant_v4i32_using_cmp_sum(<4 x i32> %x) {
448 ; CHECK-LABEL: unsigned_sat_constant_v4i32_using_cmp_sum:
450 ; CHECK-NEXT: movi v1.4s, #42
451 ; CHECK-NEXT: add v1.4s, v0.4s, v1.4s
452 ; CHECK-NEXT: cmhi v0.4s, v0.4s, v1.4s
453 ; CHECK-NEXT: orr v0.16b, v1.16b, v0.16b
455 %a = add <4 x i32> %x, <i32 42, i32 42, i32 42, i32 42>
456 %c = icmp ugt <4 x i32> %x, %a
457 %r = select <4 x i1> %c, <4 x i32> <i32 -1, i32 -1, i32 -1, i32 -1>, <4 x i32> %a
461 define <4 x i32> @unsigned_sat_constant_v4i32_using_cmp_notval(<4 x i32> %x) {
462 ; CHECK-LABEL: unsigned_sat_constant_v4i32_using_cmp_notval:
464 ; CHECK-NEXT: movi v1.4s, #42
465 ; CHECK-NEXT: mvni v2.4s, #42
466 ; CHECK-NEXT: add v1.4s, v0.4s, v1.4s
467 ; CHECK-NEXT: cmhi v0.4s, v0.4s, v2.4s
468 ; CHECK-NEXT: orr v0.16b, v1.16b, v0.16b
470 %a = add <4 x i32> %x, <i32 42, i32 42, i32 42, i32 42>
471 %c = icmp ugt <4 x i32> %x, <i32 -43, i32 -43, i32 -43, i32 -43>
472 %r = select <4 x i1> %c, <4 x i32> <i32 -1, i32 -1, i32 -1, i32 -1>, <4 x i32> %a
476 define <2 x i64> @unsigned_sat_constant_v2i64_using_min(<2 x i64> %x) {
477 ; CHECK-LABEL: unsigned_sat_constant_v2i64_using_min:
479 ; CHECK-NEXT: mov x8, #-43
480 ; CHECK-NEXT: dup v1.2d, x8
481 ; CHECK-NEXT: mov w9, #42
482 ; CHECK-NEXT: cmhi v2.2d, v1.2d, v0.2d
483 ; CHECK-NEXT: bsl v2.16b, v0.16b, v1.16b
484 ; CHECK-NEXT: dup v0.2d, x9
485 ; CHECK-NEXT: add v0.2d, v2.2d, v0.2d
487 %c = icmp ult <2 x i64> %x, <i64 -43, i64 -43>
488 %s = select <2 x i1> %c, <2 x i64> %x, <2 x i64> <i64 -43, i64 -43>
489 %r = add <2 x i64> %s, <i64 42, i64 42>
493 define <2 x i64> @unsigned_sat_constant_v2i64_using_cmp_sum(<2 x i64> %x) {
494 ; CHECK-LABEL: unsigned_sat_constant_v2i64_using_cmp_sum:
496 ; CHECK-NEXT: mov w8, #42
497 ; CHECK-NEXT: dup v1.2d, x8
498 ; CHECK-NEXT: add v1.2d, v0.2d, v1.2d
499 ; CHECK-NEXT: cmhi v0.2d, v0.2d, v1.2d
500 ; CHECK-NEXT: orr v0.16b, v1.16b, v0.16b
502 %a = add <2 x i64> %x, <i64 42, i64 42>
503 %c = icmp ugt <2 x i64> %x, %a
504 %r = select <2 x i1> %c, <2 x i64> <i64 -1, i64 -1>, <2 x i64> %a
508 define <2 x i64> @unsigned_sat_constant_v2i64_using_cmp_notval(<2 x i64> %x) {
509 ; CHECK-LABEL: unsigned_sat_constant_v2i64_using_cmp_notval:
511 ; CHECK-NEXT: mov w8, #42
512 ; CHECK-NEXT: mov x9, #-43
513 ; CHECK-NEXT: dup v1.2d, x8
514 ; CHECK-NEXT: dup v2.2d, x9
515 ; CHECK-NEXT: add v1.2d, v0.2d, v1.2d
516 ; CHECK-NEXT: cmhi v0.2d, v0.2d, v2.2d
517 ; CHECK-NEXT: orr v0.16b, v1.16b, v0.16b
519 %a = add <2 x i64> %x, <i64 42, i64 42>
520 %c = icmp ugt <2 x i64> %x, <i64 -43, i64 -43>
521 %r = select <2 x i1> %c, <2 x i64> <i64 -1, i64 -1>, <2 x i64> %a
525 define <16 x i8> @unsigned_sat_variable_v16i8_using_min(<16 x i8> %x, <16 x i8> %y) {
526 ; CHECK-LABEL: unsigned_sat_variable_v16i8_using_min:
528 ; CHECK-NEXT: mvn v2.16b, v1.16b
529 ; CHECK-NEXT: umin v0.16b, v0.16b, v2.16b
530 ; CHECK-NEXT: add v0.16b, v0.16b, v1.16b
532 %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>
533 %c = icmp ult <16 x i8> %x, %noty
534 %s = select <16 x i1> %c, <16 x i8> %x, <16 x i8> %noty
535 %r = add <16 x i8> %s, %y
539 define <16 x i8> @unsigned_sat_variable_v16i8_using_cmp_sum(<16 x i8> %x, <16 x i8> %y) {
540 ; CHECK-LABEL: unsigned_sat_variable_v16i8_using_cmp_sum:
542 ; CHECK-NEXT: add v1.16b, v0.16b, v1.16b
543 ; CHECK-NEXT: cmhi v0.16b, v0.16b, v1.16b
544 ; CHECK-NEXT: orr v0.16b, v1.16b, v0.16b
546 %a = add <16 x i8> %x, %y
547 %c = icmp ugt <16 x i8> %x, %a
548 %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
552 define <16 x i8> @unsigned_sat_variable_v16i8_using_cmp_notval(<16 x i8> %x, <16 x i8> %y) {
553 ; CHECK-LABEL: unsigned_sat_variable_v16i8_using_cmp_notval:
555 ; CHECK-NEXT: mvn v2.16b, v1.16b
556 ; CHECK-NEXT: add v1.16b, v0.16b, v1.16b
557 ; CHECK-NEXT: cmhi v0.16b, v0.16b, v2.16b
558 ; CHECK-NEXT: orr v0.16b, v1.16b, v0.16b
560 %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>
561 %a = add <16 x i8> %x, %y
562 %c = icmp ugt <16 x i8> %x, %noty
563 %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
567 define <8 x i16> @unsigned_sat_variable_v8i16_using_min(<8 x i16> %x, <8 x i16> %y) {
568 ; CHECK-LABEL: unsigned_sat_variable_v8i16_using_min:
570 ; CHECK-NEXT: mvn v2.16b, v1.16b
571 ; CHECK-NEXT: umin v0.8h, v0.8h, v2.8h
572 ; CHECK-NEXT: add v0.8h, v0.8h, v1.8h
574 %noty = xor <8 x i16> %y, <i16 -1, i16 -1, i16 -1, i16 -1, i16 -1, i16 -1, i16 -1, i16 -1>
575 %c = icmp ult <8 x i16> %x, %noty
576 %s = select <8 x i1> %c, <8 x i16> %x, <8 x i16> %noty
577 %r = add <8 x i16> %s, %y
581 define <8 x i16> @unsigned_sat_variable_v8i16_using_cmp_sum(<8 x i16> %x, <8 x i16> %y) {
582 ; CHECK-LABEL: unsigned_sat_variable_v8i16_using_cmp_sum:
584 ; CHECK-NEXT: add v1.8h, v0.8h, v1.8h
585 ; CHECK-NEXT: cmhi v0.8h, v0.8h, v1.8h
586 ; CHECK-NEXT: orr v0.16b, v1.16b, v0.16b
588 %a = add <8 x i16> %x, %y
589 %c = icmp ugt <8 x i16> %x, %a
590 %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
594 define <8 x i16> @unsigned_sat_variable_v8i16_using_cmp_notval(<8 x i16> %x, <8 x i16> %y) {
595 ; CHECK-LABEL: unsigned_sat_variable_v8i16_using_cmp_notval:
597 ; CHECK-NEXT: mvn v2.16b, v1.16b
598 ; CHECK-NEXT: add v1.8h, v0.8h, v1.8h
599 ; CHECK-NEXT: cmhi v0.8h, v0.8h, v2.8h
600 ; CHECK-NEXT: orr v0.16b, v1.16b, v0.16b
602 %noty = xor <8 x i16> %y, <i16 -1, i16 -1, i16 -1, i16 -1, i16 -1, i16 -1, i16 -1, i16 -1>
603 %a = add <8 x i16> %x, %y
604 %c = icmp ugt <8 x i16> %x, %noty
605 %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
609 define <4 x i32> @unsigned_sat_variable_v4i32_using_min(<4 x i32> %x, <4 x i32> %y) {
610 ; CHECK-LABEL: unsigned_sat_variable_v4i32_using_min:
612 ; CHECK-NEXT: mvn v2.16b, v1.16b
613 ; CHECK-NEXT: umin v0.4s, v0.4s, v2.4s
614 ; CHECK-NEXT: add v0.4s, v0.4s, v1.4s
616 %noty = xor <4 x i32> %y, <i32 -1, i32 -1, i32 -1, i32 -1>
617 %c = icmp ult <4 x i32> %x, %noty
618 %s = select <4 x i1> %c, <4 x i32> %x, <4 x i32> %noty
619 %r = add <4 x i32> %s, %y
623 define <4 x i32> @unsigned_sat_variable_v4i32_using_cmp_sum(<4 x i32> %x, <4 x i32> %y) {
624 ; CHECK-LABEL: unsigned_sat_variable_v4i32_using_cmp_sum:
626 ; CHECK-NEXT: add v1.4s, v0.4s, v1.4s
627 ; CHECK-NEXT: cmhi v0.4s, v0.4s, v1.4s
628 ; CHECK-NEXT: orr v0.16b, v1.16b, v0.16b
630 %a = add <4 x i32> %x, %y
631 %c = icmp ugt <4 x i32> %x, %a
632 %r = select <4 x i1> %c, <4 x i32> <i32 -1, i32 -1, i32 -1, i32 -1>, <4 x i32> %a
636 define <4 x i32> @unsigned_sat_variable_v4i32_using_cmp_notval(<4 x i32> %x, <4 x i32> %y) {
637 ; CHECK-LABEL: unsigned_sat_variable_v4i32_using_cmp_notval:
639 ; CHECK-NEXT: mvn v2.16b, v1.16b
640 ; CHECK-NEXT: add v1.4s, v0.4s, v1.4s
641 ; CHECK-NEXT: cmhi v0.4s, v0.4s, v2.4s
642 ; CHECK-NEXT: orr v0.16b, v1.16b, v0.16b
644 %noty = xor <4 x i32> %y, <i32 -1, i32 -1, i32 -1, i32 -1>
645 %a = add <4 x i32> %x, %y
646 %c = icmp ugt <4 x i32> %x, %noty
647 %r = select <4 x i1> %c, <4 x i32> <i32 -1, i32 -1, i32 -1, i32 -1>, <4 x i32> %a
651 define <2 x i64> @unsigned_sat_variable_v2i64_using_min(<2 x i64> %x, <2 x i64> %y) {
652 ; CHECK-LABEL: unsigned_sat_variable_v2i64_using_min:
654 ; CHECK-NEXT: mvn v2.16b, v1.16b
655 ; CHECK-NEXT: cmhi v3.2d, v2.2d, v0.2d
656 ; CHECK-NEXT: bsl v3.16b, v0.16b, v2.16b
657 ; CHECK-NEXT: add v0.2d, v3.2d, v1.2d
659 %noty = xor <2 x i64> %y, <i64 -1, i64 -1>
660 %c = icmp ult <2 x i64> %x, %noty
661 %s = select <2 x i1> %c, <2 x i64> %x, <2 x i64> %noty
662 %r = add <2 x i64> %s, %y
666 define <2 x i64> @unsigned_sat_variable_v2i64_using_cmp_sum(<2 x i64> %x, <2 x i64> %y) {
667 ; CHECK-LABEL: unsigned_sat_variable_v2i64_using_cmp_sum:
669 ; CHECK-NEXT: add v1.2d, v0.2d, v1.2d
670 ; CHECK-NEXT: cmhi v0.2d, v0.2d, v1.2d
671 ; CHECK-NEXT: orr v0.16b, v1.16b, v0.16b
673 %a = add <2 x i64> %x, %y
674 %c = icmp ugt <2 x i64> %x, %a
675 %r = select <2 x i1> %c, <2 x i64> <i64 -1, i64 -1>, <2 x i64> %a
679 define <2 x i64> @unsigned_sat_variable_v2i64_using_cmp_notval(<2 x i64> %x, <2 x i64> %y) {
680 ; CHECK-LABEL: unsigned_sat_variable_v2i64_using_cmp_notval:
682 ; CHECK-NEXT: mvn v2.16b, v1.16b
683 ; CHECK-NEXT: add v1.2d, v0.2d, v1.2d
684 ; CHECK-NEXT: cmhi v0.2d, v0.2d, v2.2d
685 ; CHECK-NEXT: orr v0.16b, v1.16b, v0.16b
687 %noty = xor <2 x i64> %y, <i64 -1, i64 -1>
688 %a = add <2 x i64> %x, %y
689 %c = icmp ugt <2 x i64> %x, %noty
690 %r = select <2 x i1> %c, <2 x i64> <i64 -1, i64 -1>, <2 x i64> %a