1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=x86_64-darwin-unknown < %s | FileCheck %s --check-prefix=SDAG
3 ; RUN: llc -mtriple=x86_64-darwin-unknown -fast-isel -fast-isel-abort=1 < %s | FileCheck %s --check-prefix=FAST
4 ; RUN: llc -mtriple=x86_64-darwin-unknown -mcpu=knl < %s | FileCheck %s --check-prefix=SDAG
7 ; Get the actual value of the overflow bit.
10 define zeroext i1 @saddoi8(i8 signext %v1, i8 signext %v2, i8* %res) {
11 ; SDAG-LABEL: saddoi8:
13 ; SDAG-NEXT: addb %sil, %dil
15 ; SDAG-NEXT: movb %dil, (%rdx)
18 ; FAST-LABEL: saddoi8:
20 ; FAST-NEXT: addb %sil, %dil
22 ; FAST-NEXT: movb %dil, (%rdx)
23 ; FAST-NEXT: andb $1, %al
24 ; FAST-NEXT: movzbl %al, %eax
26 %t = call {i8, i1} @llvm.sadd.with.overflow.i8(i8 %v1, i8 %v2)
27 %val = extractvalue {i8, i1} %t, 0
28 %obit = extractvalue {i8, i1} %t, 1
29 store i8 %val, i8* %res
33 define zeroext i1 @saddoi16(i16 %v1, i16 %v2, i16* %res) {
34 ; SDAG-LABEL: saddoi16:
36 ; SDAG-NEXT: addw %si, %di
38 ; SDAG-NEXT: movw %di, (%rdx)
41 ; FAST-LABEL: saddoi16:
43 ; FAST-NEXT: addw %si, %di
45 ; FAST-NEXT: movw %di, (%rdx)
46 ; FAST-NEXT: andb $1, %al
47 ; FAST-NEXT: movzbl %al, %eax
49 %t = call {i16, i1} @llvm.sadd.with.overflow.i16(i16 %v1, i16 %v2)
50 %val = extractvalue {i16, i1} %t, 0
51 %obit = extractvalue {i16, i1} %t, 1
52 store i16 %val, i16* %res
56 define zeroext i1 @saddoi32(i32 %v1, i32 %v2, i32* %res) {
57 ; SDAG-LABEL: saddoi32:
59 ; SDAG-NEXT: addl %esi, %edi
61 ; SDAG-NEXT: movl %edi, (%rdx)
64 ; FAST-LABEL: saddoi32:
66 ; FAST-NEXT: addl %esi, %edi
68 ; FAST-NEXT: movl %edi, (%rdx)
69 ; FAST-NEXT: andb $1, %al
70 ; FAST-NEXT: movzbl %al, %eax
72 %t = call {i32, i1} @llvm.sadd.with.overflow.i32(i32 %v1, i32 %v2)
73 %val = extractvalue {i32, i1} %t, 0
74 %obit = extractvalue {i32, i1} %t, 1
75 store i32 %val, i32* %res
79 define zeroext i1 @saddoi64(i64 %v1, i64 %v2, i64* %res) {
80 ; SDAG-LABEL: saddoi64:
82 ; SDAG-NEXT: addq %rsi, %rdi
84 ; SDAG-NEXT: movq %rdi, (%rdx)
87 ; FAST-LABEL: saddoi64:
89 ; FAST-NEXT: addq %rsi, %rdi
91 ; FAST-NEXT: movq %rdi, (%rdx)
92 ; FAST-NEXT: andb $1, %al
93 ; FAST-NEXT: movzbl %al, %eax
95 %t = call {i64, i1} @llvm.sadd.with.overflow.i64(i64 %v1, i64 %v2)
96 %val = extractvalue {i64, i1} %t, 0
97 %obit = extractvalue {i64, i1} %t, 1
98 store i64 %val, i64* %res
103 define zeroext i1 @saddoinci8(i8 %v1, i8* %res) {
104 ; SDAG-LABEL: saddoinci8:
106 ; SDAG-NEXT: incb %dil
107 ; SDAG-NEXT: seto %al
108 ; SDAG-NEXT: movb %dil, (%rsi)
111 ; FAST-LABEL: saddoinci8:
113 ; FAST-NEXT: incb %dil
114 ; FAST-NEXT: seto %al
115 ; FAST-NEXT: movb %dil, (%rsi)
116 ; FAST-NEXT: andb $1, %al
117 ; FAST-NEXT: movzbl %al, %eax
119 %t = call {i8, i1} @llvm.sadd.with.overflow.i8(i8 %v1, i8 1)
120 %val = extractvalue {i8, i1} %t, 0
121 %obit = extractvalue {i8, i1} %t, 1
122 store i8 %val, i8* %res
126 define zeroext i1 @saddoinci16(i16 %v1, i16* %res) {
127 ; SDAG-LABEL: saddoinci16:
129 ; SDAG-NEXT: incw %di
130 ; SDAG-NEXT: seto %al
131 ; SDAG-NEXT: movw %di, (%rsi)
134 ; FAST-LABEL: saddoinci16:
136 ; FAST-NEXT: incw %di
137 ; FAST-NEXT: seto %al
138 ; FAST-NEXT: movw %di, (%rsi)
139 ; FAST-NEXT: andb $1, %al
140 ; FAST-NEXT: movzbl %al, %eax
142 %t = call {i16, i1} @llvm.sadd.with.overflow.i16(i16 %v1, i16 1)
143 %val = extractvalue {i16, i1} %t, 0
144 %obit = extractvalue {i16, i1} %t, 1
145 store i16 %val, i16* %res
149 define zeroext i1 @saddoinci32(i32 %v1, i32* %res) {
150 ; SDAG-LABEL: saddoinci32:
152 ; SDAG-NEXT: incl %edi
153 ; SDAG-NEXT: seto %al
154 ; SDAG-NEXT: movl %edi, (%rsi)
157 ; FAST-LABEL: saddoinci32:
159 ; FAST-NEXT: incl %edi
160 ; FAST-NEXT: seto %al
161 ; FAST-NEXT: movl %edi, (%rsi)
162 ; FAST-NEXT: andb $1, %al
163 ; FAST-NEXT: movzbl %al, %eax
165 %t = call {i32, i1} @llvm.sadd.with.overflow.i32(i32 %v1, i32 1)
166 %val = extractvalue {i32, i1} %t, 0
167 %obit = extractvalue {i32, i1} %t, 1
168 store i32 %val, i32* %res
172 define zeroext i1 @saddoinci64(i64 %v1, i64* %res) {
173 ; SDAG-LABEL: saddoinci64:
175 ; SDAG-NEXT: incq %rdi
176 ; SDAG-NEXT: seto %al
177 ; SDAG-NEXT: movq %rdi, (%rsi)
180 ; FAST-LABEL: saddoinci64:
182 ; FAST-NEXT: incq %rdi
183 ; FAST-NEXT: seto %al
184 ; FAST-NEXT: movq %rdi, (%rsi)
185 ; FAST-NEXT: andb $1, %al
186 ; FAST-NEXT: movzbl %al, %eax
188 %t = call {i64, i1} @llvm.sadd.with.overflow.i64(i64 %v1, i64 1)
189 %val = extractvalue {i64, i1} %t, 0
190 %obit = extractvalue {i64, i1} %t, 1
191 store i64 %val, i64* %res
195 ; SADDO reg, imm | imm, reg
196 ; FIXME: DAG doesn't optimize immediates on the LHS.
197 define zeroext i1 @saddoi64imm1(i64 %v1, i64* %res) {
198 ; SDAG-LABEL: saddoi64imm1:
200 ; SDAG-NEXT: movl $2, %ecx
201 ; SDAG-NEXT: addq %rdi, %rcx
202 ; SDAG-NEXT: seto %al
203 ; SDAG-NEXT: movq %rcx, (%rsi)
206 ; FAST-LABEL: saddoi64imm1:
208 ; FAST-NEXT: addq $2, %rdi
209 ; FAST-NEXT: seto %al
210 ; FAST-NEXT: movq %rdi, (%rsi)
211 ; FAST-NEXT: andb $1, %al
212 ; FAST-NEXT: movzbl %al, %eax
214 %t = call {i64, i1} @llvm.sadd.with.overflow.i64(i64 2, i64 %v1)
215 %val = extractvalue {i64, i1} %t, 0
216 %obit = extractvalue {i64, i1} %t, 1
217 store i64 %val, i64* %res
221 ; Check boundary conditions for large immediates.
222 define zeroext i1 @saddoi64imm2(i64 %v1, i64* %res) {
223 ; SDAG-LABEL: saddoi64imm2:
225 ; SDAG-NEXT: addq $-2147483648, %rdi ## imm = 0x80000000
226 ; SDAG-NEXT: seto %al
227 ; SDAG-NEXT: movq %rdi, (%rsi)
230 ; FAST-LABEL: saddoi64imm2:
232 ; FAST-NEXT: addq $-2147483648, %rdi ## imm = 0x80000000
233 ; FAST-NEXT: seto %al
234 ; FAST-NEXT: movq %rdi, (%rsi)
235 ; FAST-NEXT: andb $1, %al
236 ; FAST-NEXT: movzbl %al, %eax
238 %t = call {i64, i1} @llvm.sadd.with.overflow.i64(i64 %v1, i64 -2147483648)
239 %val = extractvalue {i64, i1} %t, 0
240 %obit = extractvalue {i64, i1} %t, 1
241 store i64 %val, i64* %res
245 define zeroext i1 @saddoi64imm3(i64 %v1, i64* %res) {
246 ; SDAG-LABEL: saddoi64imm3:
248 ; SDAG-NEXT: movabsq $-21474836489, %rcx ## imm = 0xFFFFFFFAFFFFFFF7
249 ; SDAG-NEXT: addq %rdi, %rcx
250 ; SDAG-NEXT: seto %al
251 ; SDAG-NEXT: movq %rcx, (%rsi)
254 ; FAST-LABEL: saddoi64imm3:
256 ; FAST-NEXT: movabsq $-21474836489, %rax ## imm = 0xFFFFFFFAFFFFFFF7
257 ; FAST-NEXT: addq %rdi, %rax
258 ; FAST-NEXT: seto %cl
259 ; FAST-NEXT: movq %rax, (%rsi)
260 ; FAST-NEXT: andb $1, %cl
261 ; FAST-NEXT: movzbl %cl, %eax
263 %t = call {i64, i1} @llvm.sadd.with.overflow.i64(i64 %v1, i64 -21474836489)
264 %val = extractvalue {i64, i1} %t, 0
265 %obit = extractvalue {i64, i1} %t, 1
266 store i64 %val, i64* %res
270 define zeroext i1 @saddoi64imm4(i64 %v1, i64* %res) {
271 ; SDAG-LABEL: saddoi64imm4:
273 ; SDAG-NEXT: addq $2147483647, %rdi ## imm = 0x7FFFFFFF
274 ; SDAG-NEXT: seto %al
275 ; SDAG-NEXT: movq %rdi, (%rsi)
278 ; FAST-LABEL: saddoi64imm4:
280 ; FAST-NEXT: addq $2147483647, %rdi ## imm = 0x7FFFFFFF
281 ; FAST-NEXT: seto %al
282 ; FAST-NEXT: movq %rdi, (%rsi)
283 ; FAST-NEXT: andb $1, %al
284 ; FAST-NEXT: movzbl %al, %eax
286 %t = call {i64, i1} @llvm.sadd.with.overflow.i64(i64 %v1, i64 2147483647)
287 %val = extractvalue {i64, i1} %t, 0
288 %obit = extractvalue {i64, i1} %t, 1
289 store i64 %val, i64* %res
293 define zeroext i1 @saddoi64imm5(i64 %v1, i64* %res) {
294 ; SDAG-LABEL: saddoi64imm5:
296 ; SDAG-NEXT: movl $2147483648, %ecx ## imm = 0x80000000
297 ; SDAG-NEXT: addq %rdi, %rcx
298 ; SDAG-NEXT: seto %al
299 ; SDAG-NEXT: movq %rcx, (%rsi)
302 ; FAST-LABEL: saddoi64imm5:
304 ; FAST-NEXT: movl $2147483648, %eax ## imm = 0x80000000
305 ; FAST-NEXT: addq %rdi, %rax
306 ; FAST-NEXT: seto %cl
307 ; FAST-NEXT: movq %rax, (%rsi)
308 ; FAST-NEXT: andb $1, %cl
309 ; FAST-NEXT: movzbl %cl, %eax
311 %t = call {i64, i1} @llvm.sadd.with.overflow.i64(i64 %v1, i64 2147483648)
312 %val = extractvalue {i64, i1} %t, 0
313 %obit = extractvalue {i64, i1} %t, 1
314 store i64 %val, i64* %res
319 define zeroext i1 @uaddoi32(i32 %v1, i32 %v2, i32* %res) {
320 ; SDAG-LABEL: uaddoi32:
322 ; SDAG-NEXT: addl %esi, %edi
323 ; SDAG-NEXT: setb %al
324 ; SDAG-NEXT: movl %edi, (%rdx)
327 ; FAST-LABEL: uaddoi32:
329 ; FAST-NEXT: addl %esi, %edi
330 ; FAST-NEXT: setb %al
331 ; FAST-NEXT: movl %edi, (%rdx)
332 ; FAST-NEXT: andb $1, %al
333 ; FAST-NEXT: movzbl %al, %eax
335 %t = call {i32, i1} @llvm.uadd.with.overflow.i32(i32 %v1, i32 %v2)
336 %val = extractvalue {i32, i1} %t, 0
337 %obit = extractvalue {i32, i1} %t, 1
338 store i32 %val, i32* %res
342 define zeroext i1 @uaddoi64(i64 %v1, i64 %v2, i64* %res) {
343 ; SDAG-LABEL: uaddoi64:
345 ; SDAG-NEXT: addq %rsi, %rdi
346 ; SDAG-NEXT: setb %al
347 ; SDAG-NEXT: movq %rdi, (%rdx)
350 ; FAST-LABEL: uaddoi64:
352 ; FAST-NEXT: addq %rsi, %rdi
353 ; FAST-NEXT: setb %al
354 ; FAST-NEXT: movq %rdi, (%rdx)
355 ; FAST-NEXT: andb $1, %al
356 ; FAST-NEXT: movzbl %al, %eax
358 %t = call {i64, i1} @llvm.uadd.with.overflow.i64(i64 %v1, i64 %v2)
359 %val = extractvalue {i64, i1} %t, 0
360 %obit = extractvalue {i64, i1} %t, 1
361 store i64 %val, i64* %res
365 ; UADDO reg, 1 | NOT INC
366 define zeroext i1 @uaddoinci8(i8 %v1, i8* %res) {
367 ; SDAG-LABEL: uaddoinci8:
369 ; SDAG-NEXT: incb %dil
370 ; SDAG-NEXT: sete %al
371 ; SDAG-NEXT: movb %dil, (%rsi)
374 ; FAST-LABEL: uaddoinci8:
376 ; FAST-NEXT: addb $1, %dil
377 ; FAST-NEXT: setb %al
378 ; FAST-NEXT: movb %dil, (%rsi)
379 ; FAST-NEXT: andb $1, %al
380 ; FAST-NEXT: movzbl %al, %eax
382 %t = call {i8, i1} @llvm.uadd.with.overflow.i8(i8 %v1, i8 1)
383 %val = extractvalue {i8, i1} %t, 0
384 %obit = extractvalue {i8, i1} %t, 1
385 store i8 %val, i8* %res
389 define zeroext i1 @uaddoinci16(i16 %v1, i16* %res) {
390 ; SDAG-LABEL: uaddoinci16:
392 ; SDAG-NEXT: incw %di
393 ; SDAG-NEXT: sete %al
394 ; SDAG-NEXT: movw %di, (%rsi)
397 ; FAST-LABEL: uaddoinci16:
399 ; FAST-NEXT: addw $1, %di
400 ; FAST-NEXT: setb %al
401 ; FAST-NEXT: movw %di, (%rsi)
402 ; FAST-NEXT: andb $1, %al
403 ; FAST-NEXT: movzbl %al, %eax
405 %t = call {i16, i1} @llvm.uadd.with.overflow.i16(i16 %v1, i16 1)
406 %val = extractvalue {i16, i1} %t, 0
407 %obit = extractvalue {i16, i1} %t, 1
408 store i16 %val, i16* %res
412 define zeroext i1 @uaddoinci32(i32 %v1, i32* %res) {
413 ; SDAG-LABEL: uaddoinci32:
415 ; SDAG-NEXT: incl %edi
416 ; SDAG-NEXT: sete %al
417 ; SDAG-NEXT: movl %edi, (%rsi)
420 ; FAST-LABEL: uaddoinci32:
422 ; FAST-NEXT: addl $1, %edi
423 ; FAST-NEXT: setb %al
424 ; FAST-NEXT: movl %edi, (%rsi)
425 ; FAST-NEXT: andb $1, %al
426 ; FAST-NEXT: movzbl %al, %eax
428 %t = call {i32, i1} @llvm.uadd.with.overflow.i32(i32 %v1, i32 1)
429 %val = extractvalue {i32, i1} %t, 0
430 %obit = extractvalue {i32, i1} %t, 1
431 store i32 %val, i32* %res
435 define zeroext i1 @uaddoinci64(i64 %v1, i64* %res) {
436 ; SDAG-LABEL: uaddoinci64:
438 ; SDAG-NEXT: incq %rdi
439 ; SDAG-NEXT: sete %al
440 ; SDAG-NEXT: movq %rdi, (%rsi)
443 ; FAST-LABEL: uaddoinci64:
445 ; FAST-NEXT: addq $1, %rdi
446 ; FAST-NEXT: setb %al
447 ; FAST-NEXT: movq %rdi, (%rsi)
448 ; FAST-NEXT: andb $1, %al
449 ; FAST-NEXT: movzbl %al, %eax
451 %t = call {i64, i1} @llvm.uadd.with.overflow.i64(i64 %v1, i64 1)
452 %val = extractvalue {i64, i1} %t, 0
453 %obit = extractvalue {i64, i1} %t, 1
454 store i64 %val, i64* %res
459 define zeroext i1 @ssuboi32(i32 %v1, i32 %v2, i32* %res) {
460 ; SDAG-LABEL: ssuboi32:
462 ; SDAG-NEXT: subl %esi, %edi
463 ; SDAG-NEXT: seto %al
464 ; SDAG-NEXT: movl %edi, (%rdx)
467 ; FAST-LABEL: ssuboi32:
469 ; FAST-NEXT: subl %esi, %edi
470 ; FAST-NEXT: seto %al
471 ; FAST-NEXT: movl %edi, (%rdx)
472 ; FAST-NEXT: andb $1, %al
473 ; FAST-NEXT: movzbl %al, %eax
475 %t = call {i32, i1} @llvm.ssub.with.overflow.i32(i32 %v1, i32 %v2)
476 %val = extractvalue {i32, i1} %t, 0
477 %obit = extractvalue {i32, i1} %t, 1
478 store i32 %val, i32* %res
482 define zeroext i1 @ssuboi64(i64 %v1, i64 %v2, i64* %res) {
483 ; SDAG-LABEL: ssuboi64:
485 ; SDAG-NEXT: subq %rsi, %rdi
486 ; SDAG-NEXT: seto %al
487 ; SDAG-NEXT: movq %rdi, (%rdx)
490 ; FAST-LABEL: ssuboi64:
492 ; FAST-NEXT: subq %rsi, %rdi
493 ; FAST-NEXT: seto %al
494 ; FAST-NEXT: movq %rdi, (%rdx)
495 ; FAST-NEXT: andb $1, %al
496 ; FAST-NEXT: movzbl %al, %eax
498 %t = call {i64, i1} @llvm.ssub.with.overflow.i64(i64 %v1, i64 %v2)
499 %val = extractvalue {i64, i1} %t, 0
500 %obit = extractvalue {i64, i1} %t, 1
501 store i64 %val, i64* %res
506 define zeroext i1 @usuboi32(i32 %v1, i32 %v2, i32* %res) {
507 ; SDAG-LABEL: usuboi32:
509 ; SDAG-NEXT: subl %esi, %edi
510 ; SDAG-NEXT: setb %al
511 ; SDAG-NEXT: movl %edi, (%rdx)
514 ; FAST-LABEL: usuboi32:
516 ; FAST-NEXT: subl %esi, %edi
517 ; FAST-NEXT: setb %al
518 ; FAST-NEXT: movl %edi, (%rdx)
519 ; FAST-NEXT: andb $1, %al
520 ; FAST-NEXT: movzbl %al, %eax
522 %t = call {i32, i1} @llvm.usub.with.overflow.i32(i32 %v1, i32 %v2)
523 %val = extractvalue {i32, i1} %t, 0
524 %obit = extractvalue {i32, i1} %t, 1
525 store i32 %val, i32* %res
529 define zeroext i1 @usuboi64(i64 %v1, i64 %v2, i64* %res) {
530 ; SDAG-LABEL: usuboi64:
532 ; SDAG-NEXT: subq %rsi, %rdi
533 ; SDAG-NEXT: setb %al
534 ; SDAG-NEXT: movq %rdi, (%rdx)
537 ; FAST-LABEL: usuboi64:
539 ; FAST-NEXT: subq %rsi, %rdi
540 ; FAST-NEXT: setb %al
541 ; FAST-NEXT: movq %rdi, (%rdx)
542 ; FAST-NEXT: andb $1, %al
543 ; FAST-NEXT: movzbl %al, %eax
545 %t = call {i64, i1} @llvm.usub.with.overflow.i64(i64 %v1, i64 %v2)
546 %val = extractvalue {i64, i1} %t, 0
547 %obit = extractvalue {i64, i1} %t, 1
548 store i64 %val, i64* %res
553 ; Check the use of the overflow bit in combination with a select instruction.
555 define i32 @saddoselecti32(i32 %v1, i32 %v2) {
556 ; SDAG-LABEL: saddoselecti32:
558 ; SDAG-NEXT: movl %esi, %eax
559 ; SDAG-NEXT: movl %edi, %ecx
560 ; SDAG-NEXT: addl %esi, %ecx
561 ; SDAG-NEXT: cmovol %edi, %eax
564 ; FAST-LABEL: saddoselecti32:
566 ; FAST-NEXT: movl %esi, %eax
567 ; FAST-NEXT: movl %edi, %ecx
568 ; FAST-NEXT: addl %esi, %ecx
569 ; FAST-NEXT: cmovol %edi, %eax
571 %t = call {i32, i1} @llvm.sadd.with.overflow.i32(i32 %v1, i32 %v2)
572 %obit = extractvalue {i32, i1} %t, 1
573 %ret = select i1 %obit, i32 %v1, i32 %v2
577 define i64 @saddoselecti64(i64 %v1, i64 %v2) {
578 ; SDAG-LABEL: saddoselecti64:
580 ; SDAG-NEXT: movq %rsi, %rax
581 ; SDAG-NEXT: movq %rdi, %rcx
582 ; SDAG-NEXT: addq %rsi, %rcx
583 ; SDAG-NEXT: cmovoq %rdi, %rax
586 ; FAST-LABEL: saddoselecti64:
588 ; FAST-NEXT: movq %rsi, %rax
589 ; FAST-NEXT: movq %rdi, %rcx
590 ; FAST-NEXT: addq %rsi, %rcx
591 ; FAST-NEXT: cmovoq %rdi, %rax
593 %t = call {i64, i1} @llvm.sadd.with.overflow.i64(i64 %v1, i64 %v2)
594 %obit = extractvalue {i64, i1} %t, 1
595 %ret = select i1 %obit, i64 %v1, i64 %v2
599 define i32 @uaddoselecti32(i32 %v1, i32 %v2) {
600 ; SDAG-LABEL: uaddoselecti32:
602 ; SDAG-NEXT: movl %esi, %eax
603 ; SDAG-NEXT: movl %edi, %ecx
604 ; SDAG-NEXT: addl %esi, %ecx
605 ; SDAG-NEXT: cmovbl %edi, %eax
608 ; FAST-LABEL: uaddoselecti32:
610 ; FAST-NEXT: movl %esi, %eax
611 ; FAST-NEXT: movl %edi, %ecx
612 ; FAST-NEXT: addl %esi, %ecx
613 ; FAST-NEXT: cmovbl %edi, %eax
615 %t = call {i32, i1} @llvm.uadd.with.overflow.i32(i32 %v1, i32 %v2)
616 %obit = extractvalue {i32, i1} %t, 1
617 %ret = select i1 %obit, i32 %v1, i32 %v2
621 define i64 @uaddoselecti64(i64 %v1, i64 %v2) {
622 ; SDAG-LABEL: uaddoselecti64:
624 ; SDAG-NEXT: movq %rsi, %rax
625 ; SDAG-NEXT: movq %rdi, %rcx
626 ; SDAG-NEXT: addq %rsi, %rcx
627 ; SDAG-NEXT: cmovbq %rdi, %rax
630 ; FAST-LABEL: uaddoselecti64:
632 ; FAST-NEXT: movq %rsi, %rax
633 ; FAST-NEXT: movq %rdi, %rcx
634 ; FAST-NEXT: addq %rsi, %rcx
635 ; FAST-NEXT: cmovbq %rdi, %rax
637 %t = call {i64, i1} @llvm.uadd.with.overflow.i64(i64 %v1, i64 %v2)
638 %obit = extractvalue {i64, i1} %t, 1
639 %ret = select i1 %obit, i64 %v1, i64 %v2
643 define i32 @ssuboselecti32(i32 %v1, i32 %v2) {
644 ; SDAG-LABEL: ssuboselecti32:
646 ; SDAG-NEXT: movl %esi, %eax
647 ; SDAG-NEXT: cmpl %esi, %edi
648 ; SDAG-NEXT: cmovol %edi, %eax
651 ; FAST-LABEL: ssuboselecti32:
653 ; FAST-NEXT: movl %esi, %eax
654 ; FAST-NEXT: cmpl %esi, %edi
655 ; FAST-NEXT: cmovol %edi, %eax
657 %t = call {i32, i1} @llvm.ssub.with.overflow.i32(i32 %v1, i32 %v2)
658 %obit = extractvalue {i32, i1} %t, 1
659 %ret = select i1 %obit, i32 %v1, i32 %v2
663 define i64 @ssuboselecti64(i64 %v1, i64 %v2) {
664 ; SDAG-LABEL: ssuboselecti64:
666 ; SDAG-NEXT: movq %rsi, %rax
667 ; SDAG-NEXT: cmpq %rsi, %rdi
668 ; SDAG-NEXT: cmovoq %rdi, %rax
671 ; FAST-LABEL: ssuboselecti64:
673 ; FAST-NEXT: movq %rsi, %rax
674 ; FAST-NEXT: cmpq %rsi, %rdi
675 ; FAST-NEXT: cmovoq %rdi, %rax
677 %t = call {i64, i1} @llvm.ssub.with.overflow.i64(i64 %v1, i64 %v2)
678 %obit = extractvalue {i64, i1} %t, 1
679 %ret = select i1 %obit, i64 %v1, i64 %v2
683 define i32 @usuboselecti32(i32 %v1, i32 %v2) {
684 ; SDAG-LABEL: usuboselecti32:
686 ; SDAG-NEXT: movl %esi, %eax
687 ; SDAG-NEXT: cmpl %esi, %edi
688 ; SDAG-NEXT: cmovbl %edi, %eax
691 ; FAST-LABEL: usuboselecti32:
693 ; FAST-NEXT: movl %esi, %eax
694 ; FAST-NEXT: cmpl %esi, %edi
695 ; FAST-NEXT: cmovbl %edi, %eax
697 %t = call {i32, i1} @llvm.usub.with.overflow.i32(i32 %v1, i32 %v2)
698 %obit = extractvalue {i32, i1} %t, 1
699 %ret = select i1 %obit, i32 %v1, i32 %v2
703 define i64 @usuboselecti64(i64 %v1, i64 %v2) {
704 ; SDAG-LABEL: usuboselecti64:
706 ; SDAG-NEXT: movq %rsi, %rax
707 ; SDAG-NEXT: cmpq %rsi, %rdi
708 ; SDAG-NEXT: cmovbq %rdi, %rax
711 ; FAST-LABEL: usuboselecti64:
713 ; FAST-NEXT: movq %rsi, %rax
714 ; FAST-NEXT: cmpq %rsi, %rdi
715 ; FAST-NEXT: cmovbq %rdi, %rax
717 %t = call {i64, i1} @llvm.usub.with.overflow.i64(i64 %v1, i64 %v2)
718 %obit = extractvalue {i64, i1} %t, 1
719 %ret = select i1 %obit, i64 %v1, i64 %v2
724 ; Check the use of the overflow bit in combination with a branch instruction.
726 define zeroext i1 @saddobri32(i32 %v1, i32 %v2) {
727 ; SDAG-LABEL: saddobri32:
729 ; SDAG-NEXT: addl %esi, %edi
730 ; SDAG-NEXT: jo LBB31_1
731 ; SDAG-NEXT: ## %bb.2: ## %continue
732 ; SDAG-NEXT: movb $1, %al
734 ; SDAG-NEXT: LBB31_1: ## %overflow
735 ; SDAG-NEXT: xorl %eax, %eax
738 ; FAST-LABEL: saddobri32:
740 ; FAST-NEXT: addl %esi, %edi
741 ; FAST-NEXT: jo LBB31_1
742 ; FAST-NEXT: ## %bb.2: ## %continue
743 ; FAST-NEXT: movb $1, %al
744 ; FAST-NEXT: andb $1, %al
745 ; FAST-NEXT: movzbl %al, %eax
747 ; FAST-NEXT: LBB31_1: ## %overflow
748 ; FAST-NEXT: xorl %eax, %eax
749 ; FAST-NEXT: andb $1, %al
750 ; FAST-NEXT: movzbl %al, %eax
752 %t = call {i32, i1} @llvm.sadd.with.overflow.i32(i32 %v1, i32 %v2)
753 %val = extractvalue {i32, i1} %t, 0
754 %obit = extractvalue {i32, i1} %t, 1
755 br i1 %obit, label %overflow, label %continue, !prof !0
764 define zeroext i1 @saddobri64(i64 %v1, i64 %v2) {
765 ; SDAG-LABEL: saddobri64:
767 ; SDAG-NEXT: addq %rsi, %rdi
768 ; SDAG-NEXT: jo LBB32_1
769 ; SDAG-NEXT: ## %bb.2: ## %continue
770 ; SDAG-NEXT: movb $1, %al
772 ; SDAG-NEXT: LBB32_1: ## %overflow
773 ; SDAG-NEXT: xorl %eax, %eax
776 ; FAST-LABEL: saddobri64:
778 ; FAST-NEXT: addq %rsi, %rdi
779 ; FAST-NEXT: jo LBB32_1
780 ; FAST-NEXT: ## %bb.2: ## %continue
781 ; FAST-NEXT: movb $1, %al
782 ; FAST-NEXT: andb $1, %al
783 ; FAST-NEXT: movzbl %al, %eax
785 ; FAST-NEXT: LBB32_1: ## %overflow
786 ; FAST-NEXT: xorl %eax, %eax
787 ; FAST-NEXT: andb $1, %al
788 ; FAST-NEXT: movzbl %al, %eax
790 %t = call {i64, i1} @llvm.sadd.with.overflow.i64(i64 %v1, i64 %v2)
791 %val = extractvalue {i64, i1} %t, 0
792 %obit = extractvalue {i64, i1} %t, 1
793 br i1 %obit, label %overflow, label %continue, !prof !0
802 define zeroext i1 @uaddobri32(i32 %v1, i32 %v2) {
803 ; SDAG-LABEL: uaddobri32:
805 ; SDAG-NEXT: addl %esi, %edi
806 ; SDAG-NEXT: jb LBB33_1
807 ; SDAG-NEXT: ## %bb.2: ## %continue
808 ; SDAG-NEXT: movb $1, %al
810 ; SDAG-NEXT: LBB33_1: ## %overflow
811 ; SDAG-NEXT: xorl %eax, %eax
814 ; FAST-LABEL: uaddobri32:
816 ; FAST-NEXT: addl %esi, %edi
817 ; FAST-NEXT: jb LBB33_1
818 ; FAST-NEXT: ## %bb.2: ## %continue
819 ; FAST-NEXT: movb $1, %al
820 ; FAST-NEXT: andb $1, %al
821 ; FAST-NEXT: movzbl %al, %eax
823 ; FAST-NEXT: LBB33_1: ## %overflow
824 ; FAST-NEXT: xorl %eax, %eax
825 ; FAST-NEXT: andb $1, %al
826 ; FAST-NEXT: movzbl %al, %eax
828 %t = call {i32, i1} @llvm.uadd.with.overflow.i32(i32 %v1, i32 %v2)
829 %val = extractvalue {i32, i1} %t, 0
830 %obit = extractvalue {i32, i1} %t, 1
831 br i1 %obit, label %overflow, label %continue, !prof !0
840 define zeroext i1 @uaddobri64(i64 %v1, i64 %v2) {
841 ; SDAG-LABEL: uaddobri64:
843 ; SDAG-NEXT: addq %rsi, %rdi
844 ; SDAG-NEXT: jb LBB34_1
845 ; SDAG-NEXT: ## %bb.2: ## %continue
846 ; SDAG-NEXT: movb $1, %al
848 ; SDAG-NEXT: LBB34_1: ## %overflow
849 ; SDAG-NEXT: xorl %eax, %eax
852 ; FAST-LABEL: uaddobri64:
854 ; FAST-NEXT: addq %rsi, %rdi
855 ; FAST-NEXT: jb LBB34_1
856 ; FAST-NEXT: ## %bb.2: ## %continue
857 ; FAST-NEXT: movb $1, %al
858 ; FAST-NEXT: andb $1, %al
859 ; FAST-NEXT: movzbl %al, %eax
861 ; FAST-NEXT: LBB34_1: ## %overflow
862 ; FAST-NEXT: xorl %eax, %eax
863 ; FAST-NEXT: andb $1, %al
864 ; FAST-NEXT: movzbl %al, %eax
866 %t = call {i64, i1} @llvm.uadd.with.overflow.i64(i64 %v1, i64 %v2)
867 %val = extractvalue {i64, i1} %t, 0
868 %obit = extractvalue {i64, i1} %t, 1
869 br i1 %obit, label %overflow, label %continue, !prof !0
878 define zeroext i1 @ssubobri32(i32 %v1, i32 %v2) {
879 ; SDAG-LABEL: ssubobri32:
881 ; SDAG-NEXT: cmpl %esi, %edi
882 ; SDAG-NEXT: jo LBB35_1
883 ; SDAG-NEXT: ## %bb.2: ## %continue
884 ; SDAG-NEXT: movb $1, %al
886 ; SDAG-NEXT: LBB35_1: ## %overflow
887 ; SDAG-NEXT: xorl %eax, %eax
890 ; FAST-LABEL: ssubobri32:
892 ; FAST-NEXT: cmpl %esi, %edi
893 ; FAST-NEXT: jo LBB35_1
894 ; FAST-NEXT: ## %bb.2: ## %continue
895 ; FAST-NEXT: movb $1, %al
896 ; FAST-NEXT: andb $1, %al
897 ; FAST-NEXT: movzbl %al, %eax
899 ; FAST-NEXT: LBB35_1: ## %overflow
900 ; FAST-NEXT: xorl %eax, %eax
901 ; FAST-NEXT: andb $1, %al
902 ; FAST-NEXT: movzbl %al, %eax
904 %t = call {i32, i1} @llvm.ssub.with.overflow.i32(i32 %v1, i32 %v2)
905 %val = extractvalue {i32, i1} %t, 0
906 %obit = extractvalue {i32, i1} %t, 1
907 br i1 %obit, label %overflow, label %continue, !prof !0
916 define zeroext i1 @ssubobri64(i64 %v1, i64 %v2) {
917 ; SDAG-LABEL: ssubobri64:
919 ; SDAG-NEXT: cmpq %rsi, %rdi
920 ; SDAG-NEXT: jo LBB36_1
921 ; SDAG-NEXT: ## %bb.2: ## %continue
922 ; SDAG-NEXT: movb $1, %al
924 ; SDAG-NEXT: LBB36_1: ## %overflow
925 ; SDAG-NEXT: xorl %eax, %eax
928 ; FAST-LABEL: ssubobri64:
930 ; FAST-NEXT: cmpq %rsi, %rdi
931 ; FAST-NEXT: jo LBB36_1
932 ; FAST-NEXT: ## %bb.2: ## %continue
933 ; FAST-NEXT: movb $1, %al
934 ; FAST-NEXT: andb $1, %al
935 ; FAST-NEXT: movzbl %al, %eax
937 ; FAST-NEXT: LBB36_1: ## %overflow
938 ; FAST-NEXT: xorl %eax, %eax
939 ; FAST-NEXT: andb $1, %al
940 ; FAST-NEXT: movzbl %al, %eax
942 %t = call {i64, i1} @llvm.ssub.with.overflow.i64(i64 %v1, i64 %v2)
943 %val = extractvalue {i64, i1} %t, 0
944 %obit = extractvalue {i64, i1} %t, 1
945 br i1 %obit, label %overflow, label %continue, !prof !0
954 define zeroext i1 @usubobri32(i32 %v1, i32 %v2) {
955 ; SDAG-LABEL: usubobri32:
957 ; SDAG-NEXT: cmpl %esi, %edi
958 ; SDAG-NEXT: jb LBB37_1
959 ; SDAG-NEXT: ## %bb.2: ## %continue
960 ; SDAG-NEXT: movb $1, %al
962 ; SDAG-NEXT: LBB37_1: ## %overflow
963 ; SDAG-NEXT: xorl %eax, %eax
966 ; FAST-LABEL: usubobri32:
968 ; FAST-NEXT: cmpl %esi, %edi
969 ; FAST-NEXT: jb LBB37_1
970 ; FAST-NEXT: ## %bb.2: ## %continue
971 ; FAST-NEXT: movb $1, %al
972 ; FAST-NEXT: andb $1, %al
973 ; FAST-NEXT: movzbl %al, %eax
975 ; FAST-NEXT: LBB37_1: ## %overflow
976 ; FAST-NEXT: xorl %eax, %eax
977 ; FAST-NEXT: andb $1, %al
978 ; FAST-NEXT: movzbl %al, %eax
980 %t = call {i32, i1} @llvm.usub.with.overflow.i32(i32 %v1, i32 %v2)
981 %val = extractvalue {i32, i1} %t, 0
982 %obit = extractvalue {i32, i1} %t, 1
983 br i1 %obit, label %overflow, label %continue, !prof !0
992 define zeroext i1 @usubobri64(i64 %v1, i64 %v2) {
993 ; SDAG-LABEL: usubobri64:
995 ; SDAG-NEXT: cmpq %rsi, %rdi
996 ; SDAG-NEXT: jb LBB38_1
997 ; SDAG-NEXT: ## %bb.2: ## %continue
998 ; SDAG-NEXT: movb $1, %al
1000 ; SDAG-NEXT: LBB38_1: ## %overflow
1001 ; SDAG-NEXT: xorl %eax, %eax
1004 ; FAST-LABEL: usubobri64:
1006 ; FAST-NEXT: cmpq %rsi, %rdi
1007 ; FAST-NEXT: jb LBB38_1
1008 ; FAST-NEXT: ## %bb.2: ## %continue
1009 ; FAST-NEXT: movb $1, %al
1010 ; FAST-NEXT: andb $1, %al
1011 ; FAST-NEXT: movzbl %al, %eax
1013 ; FAST-NEXT: LBB38_1: ## %overflow
1014 ; FAST-NEXT: xorl %eax, %eax
1015 ; FAST-NEXT: andb $1, %al
1016 ; FAST-NEXT: movzbl %al, %eax
1018 %t = call {i64, i1} @llvm.usub.with.overflow.i64(i64 %v1, i64 %v2)
1019 %val = extractvalue {i64, i1} %t, 0
1020 %obit = extractvalue {i64, i1} %t, 1
1021 br i1 %obit, label %overflow, label %continue, !prof !0
1030 define {i64, i1} @uaddoovf(i64 %a, i64 %b) {
1031 ; SDAG-LABEL: uaddoovf:
1033 ; SDAG-NEXT: movzbl %dil, %ecx
1034 ; SDAG-NEXT: movzbl %sil, %eax
1035 ; SDAG-NEXT: addq %rcx, %rax
1036 ; SDAG-NEXT: xorl %edx, %edx
1039 ; FAST-LABEL: uaddoovf:
1041 ; FAST-NEXT: movzbl %dil, %ecx
1042 ; FAST-NEXT: movzbl %sil, %eax
1043 ; FAST-NEXT: addq %rcx, %rax
1044 ; FAST-NEXT: xorl %edx, %edx
1046 %1 = and i64 %a, 255
1047 %2 = and i64 %b, 255
1048 %t = call {i64, i1} @llvm.uadd.with.overflow.i64(i64 %1, i64 %2)
1052 define {i64, i1} @usuboovf(i64 %a, i64 %b) {
1053 ; SDAG-LABEL: usuboovf:
1055 ; SDAG-NEXT: movq %rsi, %rax
1056 ; SDAG-NEXT: notq %rax
1057 ; SDAG-NEXT: xorl %edx, %edx
1060 ; FAST-LABEL: usuboovf:
1062 ; FAST-NEXT: movq %rsi, %rax
1063 ; FAST-NEXT: notq %rax
1064 ; FAST-NEXT: xorl %edx, %edx
1066 %t0 = call {i64, i1} @llvm.usub.with.overflow.i64(i64 %a, i64 %a)
1067 %v0 = extractvalue {i64, i1} %t0, 0
1068 %o0 = extractvalue {i64, i1} %t0, 1
1069 %t1 = call {i64, i1} @llvm.usub.with.overflow.i64(i64 -1, i64 %b)
1070 %v1 = extractvalue {i64, i1} %t1, 0
1071 %o1 = extractvalue {i64, i1} %t1, 1
1072 %oo = or i1 %o0, %o1
1073 %t2 = call {i64, i1} @llvm.usub.with.overflow.i64(i64 %v1, i64 %v0)
1074 %v2 = extractvalue {i64, i1} %t2, 0
1075 %o2 = extractvalue {i64, i1} %t2, 1
1076 %ooo = or i1 %oo, %o2
1077 %t = insertvalue {i64, i1} %t2, i1 %ooo, 1
1081 ; Make sure we select an INC for both the data use and the flag use.
1082 define i32 @incovfselectstore(i32 %v1, i32 %v2, i32* %x) {
1083 ; SDAG-LABEL: incovfselectstore:
1085 ; SDAG-NEXT: movl %esi, %eax
1086 ; SDAG-NEXT: movl %edi, %ecx
1087 ; SDAG-NEXT: incl %ecx
1088 ; SDAG-NEXT: cmovol %edi, %eax
1089 ; SDAG-NEXT: movl %ecx, (%rdx)
1092 ; FAST-LABEL: incovfselectstore:
1094 ; FAST-NEXT: movl %esi, %eax
1095 ; FAST-NEXT: movl %edi, %ecx
1096 ; FAST-NEXT: incl %ecx
1097 ; FAST-NEXT: cmovol %edi, %eax
1098 ; FAST-NEXT: movl %ecx, (%rdx)
1100 %t = call {i32, i1} @llvm.sadd.with.overflow.i32(i32 %v1, i32 1)
1101 %obit = extractvalue {i32, i1} %t, 1
1102 %ret = select i1 %obit, i32 %v1, i32 %v2
1103 %val = extractvalue {i32, i1} %t, 0
1104 store i32 %val, i32* %x
1108 ; Make sure we select a DEC for both the data use and the flag use.
1109 define i32 @decovfselectstore(i32 %v1, i32 %v2, i32* %x) {
1110 ; SDAG-LABEL: decovfselectstore:
1112 ; SDAG-NEXT: movl %esi, %eax
1113 ; SDAG-NEXT: movl %edi, %ecx
1114 ; SDAG-NEXT: decl %ecx
1115 ; SDAG-NEXT: cmovol %edi, %eax
1116 ; SDAG-NEXT: movl %ecx, (%rdx)
1119 ; FAST-LABEL: decovfselectstore:
1121 ; FAST-NEXT: movl %esi, %eax
1122 ; FAST-NEXT: movl %edi, %ecx
1123 ; FAST-NEXT: decl %ecx
1124 ; FAST-NEXT: cmovol %edi, %eax
1125 ; FAST-NEXT: movl %ecx, (%rdx)
1127 %t = call {i32, i1} @llvm.ssub.with.overflow.i32(i32 %v1, i32 1)
1128 %obit = extractvalue {i32, i1} %t, 1
1129 %ret = select i1 %obit, i32 %v1, i32 %v2
1130 %val = extractvalue {i32, i1} %t, 0
1131 store i32 %val, i32* %x
1135 declare {i8, i1} @llvm.sadd.with.overflow.i8 (i8, i8 ) nounwind readnone
1136 declare {i16, i1} @llvm.sadd.with.overflow.i16(i16, i16) nounwind readnone
1137 declare {i32, i1} @llvm.sadd.with.overflow.i32(i32, i32) nounwind readnone
1138 declare {i64, i1} @llvm.sadd.with.overflow.i64(i64, i64) nounwind readnone
1139 declare {i8, i1} @llvm.uadd.with.overflow.i8 (i8, i8 ) nounwind readnone
1140 declare {i16, i1} @llvm.uadd.with.overflow.i16(i16, i16) nounwind readnone
1141 declare {i32, i1} @llvm.uadd.with.overflow.i32(i32, i32) nounwind readnone
1142 declare {i64, i1} @llvm.uadd.with.overflow.i64(i64, i64) nounwind readnone
1143 declare {i32, i1} @llvm.ssub.with.overflow.i32(i32, i32) nounwind readnone
1144 declare {i64, i1} @llvm.ssub.with.overflow.i64(i64, i64) nounwind readnone
1145 declare {i32, i1} @llvm.usub.with.overflow.i32(i32, i32) nounwind readnone
1146 declare {i64, i1} @llvm.usub.with.overflow.i64(i64, i64) nounwind readnone
1148 !0 = !{!"branch_weights", i32 0, i32 2147483647}