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-prefixes=CHECK,SDAG,GENERIC
3 ; RUN: llc -mtriple=x86_64-darwin-unknown -fast-isel -fast-isel-abort=1 < %s | FileCheck %s --check-prefixes=CHECK,FAST
4 ; RUN: llc -mtriple=x86_64-darwin-unknown -mcpu=knl < %s | FileCheck %s --check-prefixes=CHECK,SDAG,KNL
7 ; Get the actual value of the overflow bit.
10 define zeroext i1 @saddoi8(i8 signext %v1, i8 signext %v2, ptr %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, ptr %res
33 define zeroext i1 @saddoi16(i16 %v1, i16 %v2, ptr %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, ptr %res
56 define zeroext i1 @saddoi32(i32 %v1, i32 %v2, ptr %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, ptr %res
79 define zeroext i1 @saddoi64(i64 %v1, i64 %v2, ptr %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, ptr %res
103 define zeroext i1 @saddoinci8(i8 %v1, ptr %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, ptr %res
126 define zeroext i1 @saddoinci16(i16 %v1, ptr %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, ptr %res
149 define zeroext i1 @saddoinci32(i32 %v1, ptr %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, ptr %res
172 define zeroext i1 @saddoinci64(i64 %v1, ptr %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, ptr %res
195 ; SADDO reg, imm | imm, reg
196 define zeroext i1 @saddoi64imm1(i64 %v1, ptr %res) {
197 ; SDAG-LABEL: saddoi64imm1:
199 ; SDAG-NEXT: addq $2, %rdi
200 ; SDAG-NEXT: seto %al
201 ; SDAG-NEXT: movq %rdi, (%rsi)
204 ; FAST-LABEL: saddoi64imm1:
206 ; FAST-NEXT: addq $2, %rdi
207 ; FAST-NEXT: seto %al
208 ; FAST-NEXT: movq %rdi, (%rsi)
209 ; FAST-NEXT: andb $1, %al
210 ; FAST-NEXT: movzbl %al, %eax
212 %t = call {i64, i1} @llvm.sadd.with.overflow.i64(i64 2, i64 %v1)
213 %val = extractvalue {i64, i1} %t, 0
214 %obit = extractvalue {i64, i1} %t, 1
215 store i64 %val, ptr %res
219 ; Check boundary conditions for large immediates.
220 define zeroext i1 @saddoi64imm2(i64 %v1, ptr %res) {
221 ; SDAG-LABEL: saddoi64imm2:
223 ; SDAG-NEXT: addq $-2147483648, %rdi ## imm = 0x80000000
224 ; SDAG-NEXT: seto %al
225 ; SDAG-NEXT: movq %rdi, (%rsi)
228 ; FAST-LABEL: saddoi64imm2:
230 ; FAST-NEXT: addq $-2147483648, %rdi ## imm = 0x80000000
231 ; FAST-NEXT: seto %al
232 ; FAST-NEXT: movq %rdi, (%rsi)
233 ; FAST-NEXT: andb $1, %al
234 ; FAST-NEXT: movzbl %al, %eax
236 %t = call {i64, i1} @llvm.sadd.with.overflow.i64(i64 %v1, i64 -2147483648)
237 %val = extractvalue {i64, i1} %t, 0
238 %obit = extractvalue {i64, i1} %t, 1
239 store i64 %val, ptr %res
243 define zeroext i1 @saddoi64imm3(i64 %v1, ptr %res) {
244 ; SDAG-LABEL: saddoi64imm3:
246 ; SDAG-NEXT: movabsq $-21474836489, %rcx ## imm = 0xFFFFFFFAFFFFFFF7
247 ; SDAG-NEXT: addq %rdi, %rcx
248 ; SDAG-NEXT: seto %al
249 ; SDAG-NEXT: movq %rcx, (%rsi)
252 ; FAST-LABEL: saddoi64imm3:
254 ; FAST-NEXT: movabsq $-21474836489, %rax ## imm = 0xFFFFFFFAFFFFFFF7
255 ; FAST-NEXT: addq %rdi, %rax
256 ; FAST-NEXT: seto %cl
257 ; FAST-NEXT: movq %rax, (%rsi)
258 ; FAST-NEXT: andb $1, %cl
259 ; FAST-NEXT: movzbl %cl, %eax
261 %t = call {i64, i1} @llvm.sadd.with.overflow.i64(i64 %v1, i64 -21474836489)
262 %val = extractvalue {i64, i1} %t, 0
263 %obit = extractvalue {i64, i1} %t, 1
264 store i64 %val, ptr %res
268 define zeroext i1 @saddoi64imm4(i64 %v1, ptr %res) {
269 ; SDAG-LABEL: saddoi64imm4:
271 ; SDAG-NEXT: addq $2147483647, %rdi ## imm = 0x7FFFFFFF
272 ; SDAG-NEXT: seto %al
273 ; SDAG-NEXT: movq %rdi, (%rsi)
276 ; FAST-LABEL: saddoi64imm4:
278 ; FAST-NEXT: addq $2147483647, %rdi ## imm = 0x7FFFFFFF
279 ; FAST-NEXT: seto %al
280 ; FAST-NEXT: movq %rdi, (%rsi)
281 ; FAST-NEXT: andb $1, %al
282 ; FAST-NEXT: movzbl %al, %eax
284 %t = call {i64, i1} @llvm.sadd.with.overflow.i64(i64 %v1, i64 2147483647)
285 %val = extractvalue {i64, i1} %t, 0
286 %obit = extractvalue {i64, i1} %t, 1
287 store i64 %val, ptr %res
291 define zeroext i1 @saddoi64imm5(i64 %v1, ptr %res) {
292 ; SDAG-LABEL: saddoi64imm5:
294 ; SDAG-NEXT: subq $-2147483648, %rdi ## imm = 0x80000000
295 ; SDAG-NEXT: seto %al
296 ; SDAG-NEXT: movq %rdi, (%rsi)
299 ; FAST-LABEL: saddoi64imm5:
301 ; FAST-NEXT: movl $2147483648, %eax ## imm = 0x80000000
302 ; FAST-NEXT: addq %rdi, %rax
303 ; FAST-NEXT: seto %cl
304 ; FAST-NEXT: movq %rax, (%rsi)
305 ; FAST-NEXT: andb $1, %cl
306 ; FAST-NEXT: movzbl %cl, %eax
308 %t = call {i64, i1} @llvm.sadd.with.overflow.i64(i64 %v1, i64 2147483648)
309 %val = extractvalue {i64, i1} %t, 0
310 %obit = extractvalue {i64, i1} %t, 1
311 store i64 %val, ptr %res
316 define zeroext i1 @uaddoi32(i32 %v1, i32 %v2, ptr %res) {
317 ; SDAG-LABEL: uaddoi32:
319 ; SDAG-NEXT: addl %esi, %edi
320 ; SDAG-NEXT: setb %al
321 ; SDAG-NEXT: movl %edi, (%rdx)
324 ; FAST-LABEL: uaddoi32:
326 ; FAST-NEXT: addl %esi, %edi
327 ; FAST-NEXT: setb %al
328 ; FAST-NEXT: movl %edi, (%rdx)
329 ; FAST-NEXT: andb $1, %al
330 ; FAST-NEXT: movzbl %al, %eax
332 %t = call {i32, i1} @llvm.uadd.with.overflow.i32(i32 %v1, i32 %v2)
333 %val = extractvalue {i32, i1} %t, 0
334 %obit = extractvalue {i32, i1} %t, 1
335 store i32 %val, ptr %res
339 define zeroext i1 @uaddoi64(i64 %v1, i64 %v2, ptr %res) {
340 ; SDAG-LABEL: uaddoi64:
342 ; SDAG-NEXT: addq %rsi, %rdi
343 ; SDAG-NEXT: setb %al
344 ; SDAG-NEXT: movq %rdi, (%rdx)
347 ; FAST-LABEL: uaddoi64:
349 ; FAST-NEXT: addq %rsi, %rdi
350 ; FAST-NEXT: setb %al
351 ; FAST-NEXT: movq %rdi, (%rdx)
352 ; FAST-NEXT: andb $1, %al
353 ; FAST-NEXT: movzbl %al, %eax
355 %t = call {i64, i1} @llvm.uadd.with.overflow.i64(i64 %v1, i64 %v2)
356 %val = extractvalue {i64, i1} %t, 0
357 %obit = extractvalue {i64, i1} %t, 1
358 store i64 %val, ptr %res
362 ; UADDO reg, 1 | NOT INC
363 define zeroext i1 @uaddoinci8(i8 %v1, ptr %res) {
364 ; SDAG-LABEL: uaddoinci8:
366 ; SDAG-NEXT: incb %dil
367 ; SDAG-NEXT: sete %al
368 ; SDAG-NEXT: movb %dil, (%rsi)
371 ; FAST-LABEL: uaddoinci8:
373 ; FAST-NEXT: addb $1, %dil
374 ; FAST-NEXT: setb %al
375 ; FAST-NEXT: movb %dil, (%rsi)
376 ; FAST-NEXT: andb $1, %al
377 ; FAST-NEXT: movzbl %al, %eax
379 %t = call {i8, i1} @llvm.uadd.with.overflow.i8(i8 %v1, i8 1)
380 %val = extractvalue {i8, i1} %t, 0
381 %obit = extractvalue {i8, i1} %t, 1
382 store i8 %val, ptr %res
386 define zeroext i1 @uaddoinci16(i16 %v1, ptr %res) {
387 ; SDAG-LABEL: uaddoinci16:
389 ; SDAG-NEXT: incw %di
390 ; SDAG-NEXT: sete %al
391 ; SDAG-NEXT: movw %di, (%rsi)
394 ; FAST-LABEL: uaddoinci16:
396 ; FAST-NEXT: addw $1, %di
397 ; FAST-NEXT: setb %al
398 ; FAST-NEXT: movw %di, (%rsi)
399 ; FAST-NEXT: andb $1, %al
400 ; FAST-NEXT: movzbl %al, %eax
402 %t = call {i16, i1} @llvm.uadd.with.overflow.i16(i16 %v1, i16 1)
403 %val = extractvalue {i16, i1} %t, 0
404 %obit = extractvalue {i16, i1} %t, 1
405 store i16 %val, ptr %res
409 define zeroext i1 @uaddoinci32(i32 %v1, ptr %res) {
410 ; SDAG-LABEL: uaddoinci32:
412 ; SDAG-NEXT: incl %edi
413 ; SDAG-NEXT: sete %al
414 ; SDAG-NEXT: movl %edi, (%rsi)
417 ; FAST-LABEL: uaddoinci32:
419 ; FAST-NEXT: addl $1, %edi
420 ; FAST-NEXT: setb %al
421 ; FAST-NEXT: movl %edi, (%rsi)
422 ; FAST-NEXT: andb $1, %al
423 ; FAST-NEXT: movzbl %al, %eax
425 %t = call {i32, i1} @llvm.uadd.with.overflow.i32(i32 %v1, i32 1)
426 %val = extractvalue {i32, i1} %t, 0
427 %obit = extractvalue {i32, i1} %t, 1
428 store i32 %val, ptr %res
432 define zeroext i1 @uaddoinci64(i64 %v1, ptr %res) {
433 ; SDAG-LABEL: uaddoinci64:
435 ; SDAG-NEXT: incq %rdi
436 ; SDAG-NEXT: sete %al
437 ; SDAG-NEXT: movq %rdi, (%rsi)
440 ; FAST-LABEL: uaddoinci64:
442 ; FAST-NEXT: addq $1, %rdi
443 ; FAST-NEXT: setb %al
444 ; FAST-NEXT: movq %rdi, (%rsi)
445 ; FAST-NEXT: andb $1, %al
446 ; FAST-NEXT: movzbl %al, %eax
448 %t = call {i64, i1} @llvm.uadd.with.overflow.i64(i64 %v1, i64 1)
449 %val = extractvalue {i64, i1} %t, 0
450 %obit = extractvalue {i64, i1} %t, 1
451 store i64 %val, ptr %res
456 define zeroext i1 @ssuboi32(i32 %v1, i32 %v2, ptr %res) {
457 ; SDAG-LABEL: ssuboi32:
459 ; SDAG-NEXT: subl %esi, %edi
460 ; SDAG-NEXT: seto %al
461 ; SDAG-NEXT: movl %edi, (%rdx)
464 ; FAST-LABEL: ssuboi32:
466 ; FAST-NEXT: subl %esi, %edi
467 ; FAST-NEXT: seto %al
468 ; FAST-NEXT: movl %edi, (%rdx)
469 ; FAST-NEXT: andb $1, %al
470 ; FAST-NEXT: movzbl %al, %eax
472 %t = call {i32, i1} @llvm.ssub.with.overflow.i32(i32 %v1, i32 %v2)
473 %val = extractvalue {i32, i1} %t, 0
474 %obit = extractvalue {i32, i1} %t, 1
475 store i32 %val, ptr %res
479 define zeroext i1 @ssuboi64(i64 %v1, i64 %v2, ptr %res) {
480 ; SDAG-LABEL: ssuboi64:
482 ; SDAG-NEXT: subq %rsi, %rdi
483 ; SDAG-NEXT: seto %al
484 ; SDAG-NEXT: movq %rdi, (%rdx)
487 ; FAST-LABEL: ssuboi64:
489 ; FAST-NEXT: subq %rsi, %rdi
490 ; FAST-NEXT: seto %al
491 ; FAST-NEXT: movq %rdi, (%rdx)
492 ; FAST-NEXT: andb $1, %al
493 ; FAST-NEXT: movzbl %al, %eax
495 %t = call {i64, i1} @llvm.ssub.with.overflow.i64(i64 %v1, i64 %v2)
496 %val = extractvalue {i64, i1} %t, 0
497 %obit = extractvalue {i64, i1} %t, 1
498 store i64 %val, ptr %res
503 define zeroext i1 @usuboi32(i32 %v1, i32 %v2, ptr %res) {
504 ; SDAG-LABEL: usuboi32:
506 ; SDAG-NEXT: subl %esi, %edi
507 ; SDAG-NEXT: setb %al
508 ; SDAG-NEXT: movl %edi, (%rdx)
511 ; FAST-LABEL: usuboi32:
513 ; FAST-NEXT: subl %esi, %edi
514 ; FAST-NEXT: setb %al
515 ; FAST-NEXT: movl %edi, (%rdx)
516 ; FAST-NEXT: andb $1, %al
517 ; FAST-NEXT: movzbl %al, %eax
519 %t = call {i32, i1} @llvm.usub.with.overflow.i32(i32 %v1, i32 %v2)
520 %val = extractvalue {i32, i1} %t, 0
521 %obit = extractvalue {i32, i1} %t, 1
522 store i32 %val, ptr %res
526 define zeroext i1 @usuboi64(i64 %v1, i64 %v2, ptr %res) {
527 ; SDAG-LABEL: usuboi64:
529 ; SDAG-NEXT: subq %rsi, %rdi
530 ; SDAG-NEXT: setb %al
531 ; SDAG-NEXT: movq %rdi, (%rdx)
534 ; FAST-LABEL: usuboi64:
536 ; FAST-NEXT: subq %rsi, %rdi
537 ; FAST-NEXT: setb %al
538 ; FAST-NEXT: movq %rdi, (%rdx)
539 ; FAST-NEXT: andb $1, %al
540 ; FAST-NEXT: movzbl %al, %eax
542 %t = call {i64, i1} @llvm.usub.with.overflow.i64(i64 %v1, i64 %v2)
543 %val = extractvalue {i64, i1} %t, 0
544 %obit = extractvalue {i64, i1} %t, 1
545 store i64 %val, ptr %res
550 ; Check the use of the overflow bit in combination with a select instruction.
552 define i32 @saddoselecti32(i32 %v1, i32 %v2) {
553 ; CHECK-LABEL: saddoselecti32:
555 ; CHECK-NEXT: movl %esi, %eax
556 ; CHECK-NEXT: movl %edi, %ecx
557 ; CHECK-NEXT: addl %esi, %ecx
558 ; CHECK-NEXT: cmovol %edi, %eax
560 %t = call {i32, i1} @llvm.sadd.with.overflow.i32(i32 %v1, i32 %v2)
561 %obit = extractvalue {i32, i1} %t, 1
562 %ret = select i1 %obit, i32 %v1, i32 %v2
566 define i64 @saddoselecti64(i64 %v1, i64 %v2) {
567 ; CHECK-LABEL: saddoselecti64:
569 ; CHECK-NEXT: movq %rsi, %rax
570 ; CHECK-NEXT: movq %rdi, %rcx
571 ; CHECK-NEXT: addq %rsi, %rcx
572 ; CHECK-NEXT: cmovoq %rdi, %rax
574 %t = call {i64, i1} @llvm.sadd.with.overflow.i64(i64 %v1, i64 %v2)
575 %obit = extractvalue {i64, i1} %t, 1
576 %ret = select i1 %obit, i64 %v1, i64 %v2
580 define i32 @uaddoselecti32(i32 %v1, i32 %v2) {
581 ; CHECK-LABEL: uaddoselecti32:
583 ; CHECK-NEXT: movl %esi, %eax
584 ; CHECK-NEXT: movl %edi, %ecx
585 ; CHECK-NEXT: addl %esi, %ecx
586 ; CHECK-NEXT: cmovbl %edi, %eax
588 %t = call {i32, i1} @llvm.uadd.with.overflow.i32(i32 %v1, i32 %v2)
589 %obit = extractvalue {i32, i1} %t, 1
590 %ret = select i1 %obit, i32 %v1, i32 %v2
594 define i64 @uaddoselecti64(i64 %v1, i64 %v2) {
595 ; CHECK-LABEL: uaddoselecti64:
597 ; CHECK-NEXT: movq %rsi, %rax
598 ; CHECK-NEXT: movq %rdi, %rcx
599 ; CHECK-NEXT: addq %rsi, %rcx
600 ; CHECK-NEXT: cmovbq %rdi, %rax
602 %t = call {i64, i1} @llvm.uadd.with.overflow.i64(i64 %v1, i64 %v2)
603 %obit = extractvalue {i64, i1} %t, 1
604 %ret = select i1 %obit, i64 %v1, i64 %v2
608 define i32 @ssuboselecti32(i32 %v1, i32 %v2) {
609 ; CHECK-LABEL: ssuboselecti32:
611 ; CHECK-NEXT: movl %esi, %eax
612 ; CHECK-NEXT: cmpl %esi, %edi
613 ; CHECK-NEXT: cmovol %edi, %eax
615 %t = call {i32, i1} @llvm.ssub.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 @ssuboselecti64(i64 %v1, i64 %v2) {
622 ; CHECK-LABEL: ssuboselecti64:
624 ; CHECK-NEXT: movq %rsi, %rax
625 ; CHECK-NEXT: cmpq %rsi, %rdi
626 ; CHECK-NEXT: cmovoq %rdi, %rax
628 %t = call {i64, i1} @llvm.ssub.with.overflow.i64(i64 %v1, i64 %v2)
629 %obit = extractvalue {i64, i1} %t, 1
630 %ret = select i1 %obit, i64 %v1, i64 %v2
634 define i32 @usuboselecti32(i32 %v1, i32 %v2) {
635 ; CHECK-LABEL: usuboselecti32:
637 ; CHECK-NEXT: movl %esi, %eax
638 ; CHECK-NEXT: cmpl %esi, %edi
639 ; CHECK-NEXT: cmovbl %edi, %eax
641 %t = call {i32, i1} @llvm.usub.with.overflow.i32(i32 %v1, i32 %v2)
642 %obit = extractvalue {i32, i1} %t, 1
643 %ret = select i1 %obit, i32 %v1, i32 %v2
647 define i64 @usuboselecti64(i64 %v1, i64 %v2) {
648 ; CHECK-LABEL: usuboselecti64:
650 ; CHECK-NEXT: movq %rsi, %rax
651 ; CHECK-NEXT: cmpq %rsi, %rdi
652 ; CHECK-NEXT: cmovbq %rdi, %rax
654 %t = call {i64, i1} @llvm.usub.with.overflow.i64(i64 %v1, i64 %v2)
655 %obit = extractvalue {i64, i1} %t, 1
656 %ret = select i1 %obit, i64 %v1, i64 %v2
661 ; Check the use of the overflow bit in combination with a branch instruction.
663 define zeroext i1 @saddobri32(i32 %v1, i32 %v2) {
664 ; SDAG-LABEL: saddobri32:
666 ; SDAG-NEXT: addl %esi, %edi
667 ; SDAG-NEXT: jo LBB31_1
668 ; SDAG-NEXT: ## %bb.2: ## %continue
669 ; SDAG-NEXT: movb $1, %al
671 ; SDAG-NEXT: LBB31_1: ## %overflow
672 ; SDAG-NEXT: xorl %eax, %eax
675 ; FAST-LABEL: saddobri32:
677 ; FAST-NEXT: addl %esi, %edi
678 ; FAST-NEXT: jo LBB31_1
679 ; FAST-NEXT: ## %bb.2: ## %continue
680 ; FAST-NEXT: movb $1, %al
681 ; FAST-NEXT: andb $1, %al
682 ; FAST-NEXT: movzbl %al, %eax
684 ; FAST-NEXT: LBB31_1: ## %overflow
685 ; FAST-NEXT: xorl %eax, %eax
686 ; FAST-NEXT: andb $1, %al
687 ; FAST-NEXT: movzbl %al, %eax
689 %t = call {i32, i1} @llvm.sadd.with.overflow.i32(i32 %v1, i32 %v2)
690 %val = extractvalue {i32, i1} %t, 0
691 %obit = extractvalue {i32, i1} %t, 1
692 br i1 %obit, label %overflow, label %continue, !prof !0
701 define zeroext i1 @saddobri64(i64 %v1, i64 %v2) {
702 ; SDAG-LABEL: saddobri64:
704 ; SDAG-NEXT: addq %rsi, %rdi
705 ; SDAG-NEXT: jo LBB32_1
706 ; SDAG-NEXT: ## %bb.2: ## %continue
707 ; SDAG-NEXT: movb $1, %al
709 ; SDAG-NEXT: LBB32_1: ## %overflow
710 ; SDAG-NEXT: xorl %eax, %eax
713 ; FAST-LABEL: saddobri64:
715 ; FAST-NEXT: addq %rsi, %rdi
716 ; FAST-NEXT: jo LBB32_1
717 ; FAST-NEXT: ## %bb.2: ## %continue
718 ; FAST-NEXT: movb $1, %al
719 ; FAST-NEXT: andb $1, %al
720 ; FAST-NEXT: movzbl %al, %eax
722 ; FAST-NEXT: LBB32_1: ## %overflow
723 ; FAST-NEXT: xorl %eax, %eax
724 ; FAST-NEXT: andb $1, %al
725 ; FAST-NEXT: movzbl %al, %eax
727 %t = call {i64, i1} @llvm.sadd.with.overflow.i64(i64 %v1, i64 %v2)
728 %val = extractvalue {i64, i1} %t, 0
729 %obit = extractvalue {i64, i1} %t, 1
730 br i1 %obit, label %overflow, label %continue, !prof !0
739 define zeroext i1 @uaddobri32(i32 %v1, i32 %v2) {
740 ; SDAG-LABEL: uaddobri32:
742 ; SDAG-NEXT: addl %esi, %edi
743 ; SDAG-NEXT: jb LBB33_1
744 ; SDAG-NEXT: ## %bb.2: ## %continue
745 ; SDAG-NEXT: movb $1, %al
747 ; SDAG-NEXT: LBB33_1: ## %overflow
748 ; SDAG-NEXT: xorl %eax, %eax
751 ; FAST-LABEL: uaddobri32:
753 ; FAST-NEXT: addl %esi, %edi
754 ; FAST-NEXT: jb LBB33_1
755 ; FAST-NEXT: ## %bb.2: ## %continue
756 ; FAST-NEXT: movb $1, %al
757 ; FAST-NEXT: andb $1, %al
758 ; FAST-NEXT: movzbl %al, %eax
760 ; FAST-NEXT: LBB33_1: ## %overflow
761 ; FAST-NEXT: xorl %eax, %eax
762 ; FAST-NEXT: andb $1, %al
763 ; FAST-NEXT: movzbl %al, %eax
765 %t = call {i32, i1} @llvm.uadd.with.overflow.i32(i32 %v1, i32 %v2)
766 %val = extractvalue {i32, i1} %t, 0
767 %obit = extractvalue {i32, i1} %t, 1
768 br i1 %obit, label %overflow, label %continue, !prof !0
777 define zeroext i1 @uaddobri64(i64 %v1, i64 %v2) {
778 ; SDAG-LABEL: uaddobri64:
780 ; SDAG-NEXT: addq %rsi, %rdi
781 ; SDAG-NEXT: jb LBB34_1
782 ; SDAG-NEXT: ## %bb.2: ## %continue
783 ; SDAG-NEXT: movb $1, %al
785 ; SDAG-NEXT: LBB34_1: ## %overflow
786 ; SDAG-NEXT: xorl %eax, %eax
789 ; FAST-LABEL: uaddobri64:
791 ; FAST-NEXT: addq %rsi, %rdi
792 ; FAST-NEXT: jb LBB34_1
793 ; FAST-NEXT: ## %bb.2: ## %continue
794 ; FAST-NEXT: movb $1, %al
795 ; FAST-NEXT: andb $1, %al
796 ; FAST-NEXT: movzbl %al, %eax
798 ; FAST-NEXT: LBB34_1: ## %overflow
799 ; FAST-NEXT: xorl %eax, %eax
800 ; FAST-NEXT: andb $1, %al
801 ; FAST-NEXT: movzbl %al, %eax
803 %t = call {i64, i1} @llvm.uadd.with.overflow.i64(i64 %v1, i64 %v2)
804 %val = extractvalue {i64, i1} %t, 0
805 %obit = extractvalue {i64, i1} %t, 1
806 br i1 %obit, label %overflow, label %continue, !prof !0
815 define zeroext i1 @ssubobri32(i32 %v1, i32 %v2) {
816 ; SDAG-LABEL: ssubobri32:
818 ; SDAG-NEXT: cmpl %esi, %edi
819 ; SDAG-NEXT: jo LBB35_1
820 ; SDAG-NEXT: ## %bb.2: ## %continue
821 ; SDAG-NEXT: movb $1, %al
823 ; SDAG-NEXT: LBB35_1: ## %overflow
824 ; SDAG-NEXT: xorl %eax, %eax
827 ; FAST-LABEL: ssubobri32:
829 ; FAST-NEXT: cmpl %esi, %edi
830 ; FAST-NEXT: jo LBB35_1
831 ; FAST-NEXT: ## %bb.2: ## %continue
832 ; FAST-NEXT: movb $1, %al
833 ; FAST-NEXT: andb $1, %al
834 ; FAST-NEXT: movzbl %al, %eax
836 ; FAST-NEXT: LBB35_1: ## %overflow
837 ; FAST-NEXT: xorl %eax, %eax
838 ; FAST-NEXT: andb $1, %al
839 ; FAST-NEXT: movzbl %al, %eax
841 %t = call {i32, i1} @llvm.ssub.with.overflow.i32(i32 %v1, i32 %v2)
842 %val = extractvalue {i32, i1} %t, 0
843 %obit = extractvalue {i32, i1} %t, 1
844 br i1 %obit, label %overflow, label %continue, !prof !0
853 define zeroext i1 @ssubobri64(i64 %v1, i64 %v2) {
854 ; SDAG-LABEL: ssubobri64:
856 ; SDAG-NEXT: cmpq %rsi, %rdi
857 ; SDAG-NEXT: jo LBB36_1
858 ; SDAG-NEXT: ## %bb.2: ## %continue
859 ; SDAG-NEXT: movb $1, %al
861 ; SDAG-NEXT: LBB36_1: ## %overflow
862 ; SDAG-NEXT: xorl %eax, %eax
865 ; FAST-LABEL: ssubobri64:
867 ; FAST-NEXT: cmpq %rsi, %rdi
868 ; FAST-NEXT: jo LBB36_1
869 ; FAST-NEXT: ## %bb.2: ## %continue
870 ; FAST-NEXT: movb $1, %al
871 ; FAST-NEXT: andb $1, %al
872 ; FAST-NEXT: movzbl %al, %eax
874 ; FAST-NEXT: LBB36_1: ## %overflow
875 ; FAST-NEXT: xorl %eax, %eax
876 ; FAST-NEXT: andb $1, %al
877 ; FAST-NEXT: movzbl %al, %eax
879 %t = call {i64, i1} @llvm.ssub.with.overflow.i64(i64 %v1, i64 %v2)
880 %val = extractvalue {i64, i1} %t, 0
881 %obit = extractvalue {i64, i1} %t, 1
882 br i1 %obit, label %overflow, label %continue, !prof !0
891 define zeroext i1 @usubobri32(i32 %v1, i32 %v2) {
892 ; SDAG-LABEL: usubobri32:
894 ; SDAG-NEXT: cmpl %esi, %edi
895 ; SDAG-NEXT: jb LBB37_1
896 ; SDAG-NEXT: ## %bb.2: ## %continue
897 ; SDAG-NEXT: movb $1, %al
899 ; SDAG-NEXT: LBB37_1: ## %overflow
900 ; SDAG-NEXT: xorl %eax, %eax
903 ; FAST-LABEL: usubobri32:
905 ; FAST-NEXT: cmpl %esi, %edi
906 ; FAST-NEXT: jb LBB37_1
907 ; FAST-NEXT: ## %bb.2: ## %continue
908 ; FAST-NEXT: movb $1, %al
909 ; FAST-NEXT: andb $1, %al
910 ; FAST-NEXT: movzbl %al, %eax
912 ; FAST-NEXT: LBB37_1: ## %overflow
913 ; FAST-NEXT: xorl %eax, %eax
914 ; FAST-NEXT: andb $1, %al
915 ; FAST-NEXT: movzbl %al, %eax
917 %t = call {i32, i1} @llvm.usub.with.overflow.i32(i32 %v1, i32 %v2)
918 %val = extractvalue {i32, i1} %t, 0
919 %obit = extractvalue {i32, i1} %t, 1
920 br i1 %obit, label %overflow, label %continue, !prof !0
929 define zeroext i1 @usubobri64(i64 %v1, i64 %v2) {
930 ; SDAG-LABEL: usubobri64:
932 ; SDAG-NEXT: cmpq %rsi, %rdi
933 ; SDAG-NEXT: jb LBB38_1
934 ; SDAG-NEXT: ## %bb.2: ## %continue
935 ; SDAG-NEXT: movb $1, %al
937 ; SDAG-NEXT: LBB38_1: ## %overflow
938 ; SDAG-NEXT: xorl %eax, %eax
941 ; FAST-LABEL: usubobri64:
943 ; FAST-NEXT: cmpq %rsi, %rdi
944 ; FAST-NEXT: jb LBB38_1
945 ; FAST-NEXT: ## %bb.2: ## %continue
946 ; FAST-NEXT: movb $1, %al
947 ; FAST-NEXT: andb $1, %al
948 ; FAST-NEXT: movzbl %al, %eax
950 ; FAST-NEXT: LBB38_1: ## %overflow
951 ; FAST-NEXT: xorl %eax, %eax
952 ; FAST-NEXT: andb $1, %al
953 ; FAST-NEXT: movzbl %al, %eax
955 %t = call {i64, i1} @llvm.usub.with.overflow.i64(i64 %v1, i64 %v2)
956 %val = extractvalue {i64, i1} %t, 0
957 %obit = extractvalue {i64, i1} %t, 1
958 br i1 %obit, label %overflow, label %continue, !prof !0
967 define {i64, i1} @saddoovf(i64 %a, i64 %b) {
968 ; CHECK-LABEL: saddoovf:
970 ; CHECK-NEXT: sarq $17, %rdi
971 ; CHECK-NEXT: shrq $31, %rsi
972 ; CHECK-NEXT: leaq (%rsi,%rdi), %rax
973 ; CHECK-NEXT: xorl %edx, %edx
977 %t = call {i64, i1} @llvm.sadd.with.overflow.i64(i64 %1, i64 %2)
981 define {i64, i1} @ssuboovf(i64 %a, i64 %b) {
982 ; CHECK-LABEL: ssuboovf:
984 ; CHECK-NEXT: movzwl %di, %eax
985 ; CHECK-NEXT: shrq $22, %rsi
986 ; CHECK-NEXT: subq %rsi, %rax
987 ; CHECK-NEXT: xorl %edx, %edx
989 %1 = and i64 %a, 65535
991 %t = call {i64, i1} @llvm.ssub.with.overflow.i64(i64 %1, i64 %2)
995 define {i64, i1} @uaddoovf(i64 %a, i64 %b) {
996 ; CHECK-LABEL: uaddoovf:
998 ; CHECK-NEXT: movzbl %dil, %ecx
999 ; CHECK-NEXT: movzbl %sil, %eax
1000 ; CHECK-NEXT: addq %rcx, %rax
1001 ; CHECK-NEXT: xorl %edx, %edx
1003 %1 = and i64 %a, 255
1004 %2 = and i64 %b, 255
1005 %t = call {i64, i1} @llvm.uadd.with.overflow.i64(i64 %1, i64 %2)
1009 define {i64, i1} @usuboovf(i64 %a, i64 %b) {
1010 ; CHECK-LABEL: usuboovf:
1012 ; CHECK-NEXT: movq %rsi, %rax
1013 ; CHECK-NEXT: notq %rax
1014 ; CHECK-NEXT: xorl %edx, %edx
1016 %t0 = call {i64, i1} @llvm.usub.with.overflow.i64(i64 %a, i64 %a)
1017 %v0 = extractvalue {i64, i1} %t0, 0
1018 %o0 = extractvalue {i64, i1} %t0, 1
1019 %t1 = call {i64, i1} @llvm.usub.with.overflow.i64(i64 -1, i64 %b)
1020 %v1 = extractvalue {i64, i1} %t1, 0
1021 %o1 = extractvalue {i64, i1} %t1, 1
1022 %oo = or i1 %o0, %o1
1023 %t2 = call {i64, i1} @llvm.usub.with.overflow.i64(i64 %v1, i64 %v0)
1024 %v2 = extractvalue {i64, i1} %t2, 0
1025 %o2 = extractvalue {i64, i1} %t2, 1
1026 %ooo = or i1 %oo, %o2
1027 %t = insertvalue {i64, i1} %t2, i1 %ooo, 1
1031 ; Make sure we select an INC for both the data use and the flag use.
1032 define i32 @incovfselectstore(i32 %v1, i32 %v2, ptr %x) {
1033 ; CHECK-LABEL: incovfselectstore:
1035 ; CHECK-NEXT: movl %esi, %eax
1036 ; CHECK-NEXT: movl %edi, %ecx
1037 ; CHECK-NEXT: incl %ecx
1038 ; CHECK-NEXT: cmovol %edi, %eax
1039 ; CHECK-NEXT: movl %ecx, (%rdx)
1041 %t = call {i32, i1} @llvm.sadd.with.overflow.i32(i32 %v1, i32 1)
1042 %obit = extractvalue {i32, i1} %t, 1
1043 %ret = select i1 %obit, i32 %v1, i32 %v2
1044 %val = extractvalue {i32, i1} %t, 0
1045 store i32 %val, ptr %x
1049 ; Make sure we select a DEC for both the data use and the flag use.
1050 define i32 @decovfselectstore(i32 %v1, i32 %v2, ptr %x) {
1051 ; GENERIC-LABEL: decovfselectstore:
1052 ; GENERIC: ## %bb.0:
1053 ; GENERIC-NEXT: movl %esi, %eax
1054 ; GENERIC-NEXT: movl %edi, %ecx
1055 ; GENERIC-NEXT: decl %ecx
1056 ; GENERIC-NEXT: cmovol %edi, %eax
1057 ; GENERIC-NEXT: movl %ecx, (%rdx)
1058 ; GENERIC-NEXT: retq
1060 ; FAST-LABEL: decovfselectstore:
1062 ; FAST-NEXT: movl %esi, %eax
1063 ; FAST-NEXT: movl %edi, %ecx
1064 ; FAST-NEXT: decl %ecx
1065 ; FAST-NEXT: cmovol %edi, %eax
1066 ; FAST-NEXT: movl %ecx, (%rdx)
1069 ; KNL-LABEL: decovfselectstore:
1071 ; KNL-NEXT: movl %esi, %eax
1072 ; KNL-NEXT: movl %edi, %ecx
1073 ; KNL-NEXT: addl $-1, %ecx
1074 ; KNL-NEXT: cmovol %edi, %eax
1075 ; KNL-NEXT: movl %ecx, (%rdx)
1077 %t = call {i32, i1} @llvm.ssub.with.overflow.i32(i32 %v1, i32 1)
1078 %obit = extractvalue {i32, i1} %t, 1
1079 %ret = select i1 %obit, i32 %v1, i32 %v2
1080 %val = extractvalue {i32, i1} %t, 0
1081 store i32 %val, ptr %x
1085 declare {i8, i1} @llvm.sadd.with.overflow.i8 (i8, i8 ) nounwind readnone
1086 declare {i16, i1} @llvm.sadd.with.overflow.i16(i16, i16) nounwind readnone
1087 declare {i32, i1} @llvm.sadd.with.overflow.i32(i32, i32) nounwind readnone
1088 declare {i64, i1} @llvm.sadd.with.overflow.i64(i64, i64) nounwind readnone
1089 declare {i8, i1} @llvm.uadd.with.overflow.i8 (i8, i8 ) nounwind readnone
1090 declare {i16, i1} @llvm.uadd.with.overflow.i16(i16, i16) nounwind readnone
1091 declare {i32, i1} @llvm.uadd.with.overflow.i32(i32, i32) nounwind readnone
1092 declare {i64, i1} @llvm.uadd.with.overflow.i64(i64, i64) nounwind readnone
1093 declare {i32, i1} @llvm.ssub.with.overflow.i32(i32, i32) nounwind readnone
1094 declare {i64, i1} @llvm.ssub.with.overflow.i64(i64, i64) nounwind readnone
1095 declare {i32, i1} @llvm.usub.with.overflow.i32(i32, i32) nounwind readnone
1096 declare {i64, i1} @llvm.usub.with.overflow.i64(i64, i64) nounwind readnone
1098 !0 = !{!"branch_weights", i32 0, i32 2147483647}