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 --check-prefix=GENERIC
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 --check-prefix=KNL
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 define zeroext i1 @saddoi64imm1(i64 %v1, i64* %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, i64* %res
219 ; Check boundary conditions for large immediates.
220 define zeroext i1 @saddoi64imm2(i64 %v1, i64* %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, i64* %res
243 define zeroext i1 @saddoi64imm3(i64 %v1, i64* %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, i64* %res
268 define zeroext i1 @saddoi64imm4(i64 %v1, i64* %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, i64* %res
291 define zeroext i1 @saddoi64imm5(i64 %v1, i64* %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, i64* %res
316 define zeroext i1 @uaddoi32(i32 %v1, i32 %v2, i32* %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, i32* %res
339 define zeroext i1 @uaddoi64(i64 %v1, i64 %v2, i64* %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, i64* %res
362 ; UADDO reg, 1 | NOT INC
363 define zeroext i1 @uaddoinci8(i8 %v1, i8* %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, i8* %res
386 define zeroext i1 @uaddoinci16(i16 %v1, i16* %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, i16* %res
409 define zeroext i1 @uaddoinci32(i32 %v1, i32* %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, i32* %res
432 define zeroext i1 @uaddoinci64(i64 %v1, i64* %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, i64* %res
456 define zeroext i1 @ssuboi32(i32 %v1, i32 %v2, i32* %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, i32* %res
479 define zeroext i1 @ssuboi64(i64 %v1, i64 %v2, i64* %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, i64* %res
503 define zeroext i1 @usuboi32(i32 %v1, i32 %v2, i32* %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, i32* %res
526 define zeroext i1 @usuboi64(i64 %v1, i64 %v2, i64* %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, i64* %res
550 ; Check the use of the overflow bit in combination with a select instruction.
552 define i32 @saddoselecti32(i32 %v1, i32 %v2) {
553 ; SDAG-LABEL: saddoselecti32:
555 ; SDAG-NEXT: movl %esi, %eax
556 ; SDAG-NEXT: movl %edi, %ecx
557 ; SDAG-NEXT: addl %esi, %ecx
558 ; SDAG-NEXT: cmovol %edi, %eax
561 ; FAST-LABEL: saddoselecti32:
563 ; FAST-NEXT: movl %esi, %eax
564 ; FAST-NEXT: movl %edi, %ecx
565 ; FAST-NEXT: addl %esi, %ecx
566 ; FAST-NEXT: cmovol %edi, %eax
568 %t = call {i32, i1} @llvm.sadd.with.overflow.i32(i32 %v1, i32 %v2)
569 %obit = extractvalue {i32, i1} %t, 1
570 %ret = select i1 %obit, i32 %v1, i32 %v2
574 define i64 @saddoselecti64(i64 %v1, i64 %v2) {
575 ; SDAG-LABEL: saddoselecti64:
577 ; SDAG-NEXT: movq %rsi, %rax
578 ; SDAG-NEXT: movq %rdi, %rcx
579 ; SDAG-NEXT: addq %rsi, %rcx
580 ; SDAG-NEXT: cmovoq %rdi, %rax
583 ; FAST-LABEL: saddoselecti64:
585 ; FAST-NEXT: movq %rsi, %rax
586 ; FAST-NEXT: movq %rdi, %rcx
587 ; FAST-NEXT: addq %rsi, %rcx
588 ; FAST-NEXT: cmovoq %rdi, %rax
590 %t = call {i64, i1} @llvm.sadd.with.overflow.i64(i64 %v1, i64 %v2)
591 %obit = extractvalue {i64, i1} %t, 1
592 %ret = select i1 %obit, i64 %v1, i64 %v2
596 define i32 @uaddoselecti32(i32 %v1, i32 %v2) {
597 ; SDAG-LABEL: uaddoselecti32:
599 ; SDAG-NEXT: movl %esi, %eax
600 ; SDAG-NEXT: movl %edi, %ecx
601 ; SDAG-NEXT: addl %esi, %ecx
602 ; SDAG-NEXT: cmovbl %edi, %eax
605 ; FAST-LABEL: uaddoselecti32:
607 ; FAST-NEXT: movl %esi, %eax
608 ; FAST-NEXT: movl %edi, %ecx
609 ; FAST-NEXT: addl %esi, %ecx
610 ; FAST-NEXT: cmovbl %edi, %eax
612 %t = call {i32, i1} @llvm.uadd.with.overflow.i32(i32 %v1, i32 %v2)
613 %obit = extractvalue {i32, i1} %t, 1
614 %ret = select i1 %obit, i32 %v1, i32 %v2
618 define i64 @uaddoselecti64(i64 %v1, i64 %v2) {
619 ; SDAG-LABEL: uaddoselecti64:
621 ; SDAG-NEXT: movq %rsi, %rax
622 ; SDAG-NEXT: movq %rdi, %rcx
623 ; SDAG-NEXT: addq %rsi, %rcx
624 ; SDAG-NEXT: cmovbq %rdi, %rax
627 ; FAST-LABEL: uaddoselecti64:
629 ; FAST-NEXT: movq %rsi, %rax
630 ; FAST-NEXT: movq %rdi, %rcx
631 ; FAST-NEXT: addq %rsi, %rcx
632 ; FAST-NEXT: cmovbq %rdi, %rax
634 %t = call {i64, i1} @llvm.uadd.with.overflow.i64(i64 %v1, i64 %v2)
635 %obit = extractvalue {i64, i1} %t, 1
636 %ret = select i1 %obit, i64 %v1, i64 %v2
640 define i32 @ssuboselecti32(i32 %v1, i32 %v2) {
641 ; SDAG-LABEL: ssuboselecti32:
643 ; SDAG-NEXT: movl %esi, %eax
644 ; SDAG-NEXT: cmpl %esi, %edi
645 ; SDAG-NEXT: cmovol %edi, %eax
648 ; FAST-LABEL: ssuboselecti32:
650 ; FAST-NEXT: movl %esi, %eax
651 ; FAST-NEXT: cmpl %esi, %edi
652 ; FAST-NEXT: cmovol %edi, %eax
654 %t = call {i32, i1} @llvm.ssub.with.overflow.i32(i32 %v1, i32 %v2)
655 %obit = extractvalue {i32, i1} %t, 1
656 %ret = select i1 %obit, i32 %v1, i32 %v2
660 define i64 @ssuboselecti64(i64 %v1, i64 %v2) {
661 ; SDAG-LABEL: ssuboselecti64:
663 ; SDAG-NEXT: movq %rsi, %rax
664 ; SDAG-NEXT: cmpq %rsi, %rdi
665 ; SDAG-NEXT: cmovoq %rdi, %rax
668 ; FAST-LABEL: ssuboselecti64:
670 ; FAST-NEXT: movq %rsi, %rax
671 ; FAST-NEXT: cmpq %rsi, %rdi
672 ; FAST-NEXT: cmovoq %rdi, %rax
674 %t = call {i64, i1} @llvm.ssub.with.overflow.i64(i64 %v1, i64 %v2)
675 %obit = extractvalue {i64, i1} %t, 1
676 %ret = select i1 %obit, i64 %v1, i64 %v2
680 define i32 @usuboselecti32(i32 %v1, i32 %v2) {
681 ; SDAG-LABEL: usuboselecti32:
683 ; SDAG-NEXT: movl %esi, %eax
684 ; SDAG-NEXT: cmpl %esi, %edi
685 ; SDAG-NEXT: cmovbl %edi, %eax
688 ; FAST-LABEL: usuboselecti32:
690 ; FAST-NEXT: movl %esi, %eax
691 ; FAST-NEXT: cmpl %esi, %edi
692 ; FAST-NEXT: cmovbl %edi, %eax
694 %t = call {i32, i1} @llvm.usub.with.overflow.i32(i32 %v1, i32 %v2)
695 %obit = extractvalue {i32, i1} %t, 1
696 %ret = select i1 %obit, i32 %v1, i32 %v2
700 define i64 @usuboselecti64(i64 %v1, i64 %v2) {
701 ; SDAG-LABEL: usuboselecti64:
703 ; SDAG-NEXT: movq %rsi, %rax
704 ; SDAG-NEXT: cmpq %rsi, %rdi
705 ; SDAG-NEXT: cmovbq %rdi, %rax
708 ; FAST-LABEL: usuboselecti64:
710 ; FAST-NEXT: movq %rsi, %rax
711 ; FAST-NEXT: cmpq %rsi, %rdi
712 ; FAST-NEXT: cmovbq %rdi, %rax
714 %t = call {i64, i1} @llvm.usub.with.overflow.i64(i64 %v1, i64 %v2)
715 %obit = extractvalue {i64, i1} %t, 1
716 %ret = select i1 %obit, i64 %v1, i64 %v2
721 ; Check the use of the overflow bit in combination with a branch instruction.
723 define zeroext i1 @saddobri32(i32 %v1, i32 %v2) {
724 ; SDAG-LABEL: saddobri32:
726 ; SDAG-NEXT: addl %esi, %edi
727 ; SDAG-NEXT: jo LBB31_1
728 ; SDAG-NEXT: ## %bb.2: ## %continue
729 ; SDAG-NEXT: movb $1, %al
731 ; SDAG-NEXT: LBB31_1: ## %overflow
732 ; SDAG-NEXT: xorl %eax, %eax
735 ; FAST-LABEL: saddobri32:
737 ; FAST-NEXT: addl %esi, %edi
738 ; FAST-NEXT: jo LBB31_1
739 ; FAST-NEXT: ## %bb.2: ## %continue
740 ; FAST-NEXT: movb $1, %al
741 ; FAST-NEXT: andb $1, %al
742 ; FAST-NEXT: movzbl %al, %eax
744 ; FAST-NEXT: LBB31_1: ## %overflow
745 ; FAST-NEXT: xorl %eax, %eax
746 ; FAST-NEXT: andb $1, %al
747 ; FAST-NEXT: movzbl %al, %eax
749 %t = call {i32, i1} @llvm.sadd.with.overflow.i32(i32 %v1, i32 %v2)
750 %val = extractvalue {i32, i1} %t, 0
751 %obit = extractvalue {i32, i1} %t, 1
752 br i1 %obit, label %overflow, label %continue, !prof !0
761 define zeroext i1 @saddobri64(i64 %v1, i64 %v2) {
762 ; SDAG-LABEL: saddobri64:
764 ; SDAG-NEXT: addq %rsi, %rdi
765 ; SDAG-NEXT: jo LBB32_1
766 ; SDAG-NEXT: ## %bb.2: ## %continue
767 ; SDAG-NEXT: movb $1, %al
769 ; SDAG-NEXT: LBB32_1: ## %overflow
770 ; SDAG-NEXT: xorl %eax, %eax
773 ; FAST-LABEL: saddobri64:
775 ; FAST-NEXT: addq %rsi, %rdi
776 ; FAST-NEXT: jo LBB32_1
777 ; FAST-NEXT: ## %bb.2: ## %continue
778 ; FAST-NEXT: movb $1, %al
779 ; FAST-NEXT: andb $1, %al
780 ; FAST-NEXT: movzbl %al, %eax
782 ; FAST-NEXT: LBB32_1: ## %overflow
783 ; FAST-NEXT: xorl %eax, %eax
784 ; FAST-NEXT: andb $1, %al
785 ; FAST-NEXT: movzbl %al, %eax
787 %t = call {i64, i1} @llvm.sadd.with.overflow.i64(i64 %v1, i64 %v2)
788 %val = extractvalue {i64, i1} %t, 0
789 %obit = extractvalue {i64, i1} %t, 1
790 br i1 %obit, label %overflow, label %continue, !prof !0
799 define zeroext i1 @uaddobri32(i32 %v1, i32 %v2) {
800 ; SDAG-LABEL: uaddobri32:
802 ; SDAG-NEXT: addl %esi, %edi
803 ; SDAG-NEXT: jb LBB33_1
804 ; SDAG-NEXT: ## %bb.2: ## %continue
805 ; SDAG-NEXT: movb $1, %al
807 ; SDAG-NEXT: LBB33_1: ## %overflow
808 ; SDAG-NEXT: xorl %eax, %eax
811 ; FAST-LABEL: uaddobri32:
813 ; FAST-NEXT: addl %esi, %edi
814 ; FAST-NEXT: jb LBB33_1
815 ; FAST-NEXT: ## %bb.2: ## %continue
816 ; FAST-NEXT: movb $1, %al
817 ; FAST-NEXT: andb $1, %al
818 ; FAST-NEXT: movzbl %al, %eax
820 ; FAST-NEXT: LBB33_1: ## %overflow
821 ; FAST-NEXT: xorl %eax, %eax
822 ; FAST-NEXT: andb $1, %al
823 ; FAST-NEXT: movzbl %al, %eax
825 %t = call {i32, i1} @llvm.uadd.with.overflow.i32(i32 %v1, i32 %v2)
826 %val = extractvalue {i32, i1} %t, 0
827 %obit = extractvalue {i32, i1} %t, 1
828 br i1 %obit, label %overflow, label %continue, !prof !0
837 define zeroext i1 @uaddobri64(i64 %v1, i64 %v2) {
838 ; SDAG-LABEL: uaddobri64:
840 ; SDAG-NEXT: addq %rsi, %rdi
841 ; SDAG-NEXT: jb LBB34_1
842 ; SDAG-NEXT: ## %bb.2: ## %continue
843 ; SDAG-NEXT: movb $1, %al
845 ; SDAG-NEXT: LBB34_1: ## %overflow
846 ; SDAG-NEXT: xorl %eax, %eax
849 ; FAST-LABEL: uaddobri64:
851 ; FAST-NEXT: addq %rsi, %rdi
852 ; FAST-NEXT: jb LBB34_1
853 ; FAST-NEXT: ## %bb.2: ## %continue
854 ; FAST-NEXT: movb $1, %al
855 ; FAST-NEXT: andb $1, %al
856 ; FAST-NEXT: movzbl %al, %eax
858 ; FAST-NEXT: LBB34_1: ## %overflow
859 ; FAST-NEXT: xorl %eax, %eax
860 ; FAST-NEXT: andb $1, %al
861 ; FAST-NEXT: movzbl %al, %eax
863 %t = call {i64, i1} @llvm.uadd.with.overflow.i64(i64 %v1, i64 %v2)
864 %val = extractvalue {i64, i1} %t, 0
865 %obit = extractvalue {i64, i1} %t, 1
866 br i1 %obit, label %overflow, label %continue, !prof !0
875 define zeroext i1 @ssubobri32(i32 %v1, i32 %v2) {
876 ; SDAG-LABEL: ssubobri32:
878 ; SDAG-NEXT: cmpl %esi, %edi
879 ; SDAG-NEXT: jo LBB35_1
880 ; SDAG-NEXT: ## %bb.2: ## %continue
881 ; SDAG-NEXT: movb $1, %al
883 ; SDAG-NEXT: LBB35_1: ## %overflow
884 ; SDAG-NEXT: xorl %eax, %eax
887 ; FAST-LABEL: ssubobri32:
889 ; FAST-NEXT: cmpl %esi, %edi
890 ; FAST-NEXT: jo LBB35_1
891 ; FAST-NEXT: ## %bb.2: ## %continue
892 ; FAST-NEXT: movb $1, %al
893 ; FAST-NEXT: andb $1, %al
894 ; FAST-NEXT: movzbl %al, %eax
896 ; FAST-NEXT: LBB35_1: ## %overflow
897 ; FAST-NEXT: xorl %eax, %eax
898 ; FAST-NEXT: andb $1, %al
899 ; FAST-NEXT: movzbl %al, %eax
901 %t = call {i32, i1} @llvm.ssub.with.overflow.i32(i32 %v1, i32 %v2)
902 %val = extractvalue {i32, i1} %t, 0
903 %obit = extractvalue {i32, i1} %t, 1
904 br i1 %obit, label %overflow, label %continue, !prof !0
913 define zeroext i1 @ssubobri64(i64 %v1, i64 %v2) {
914 ; SDAG-LABEL: ssubobri64:
916 ; SDAG-NEXT: cmpq %rsi, %rdi
917 ; SDAG-NEXT: jo LBB36_1
918 ; SDAG-NEXT: ## %bb.2: ## %continue
919 ; SDAG-NEXT: movb $1, %al
921 ; SDAG-NEXT: LBB36_1: ## %overflow
922 ; SDAG-NEXT: xorl %eax, %eax
925 ; FAST-LABEL: ssubobri64:
927 ; FAST-NEXT: cmpq %rsi, %rdi
928 ; FAST-NEXT: jo LBB36_1
929 ; FAST-NEXT: ## %bb.2: ## %continue
930 ; FAST-NEXT: movb $1, %al
931 ; FAST-NEXT: andb $1, %al
932 ; FAST-NEXT: movzbl %al, %eax
934 ; FAST-NEXT: LBB36_1: ## %overflow
935 ; FAST-NEXT: xorl %eax, %eax
936 ; FAST-NEXT: andb $1, %al
937 ; FAST-NEXT: movzbl %al, %eax
939 %t = call {i64, i1} @llvm.ssub.with.overflow.i64(i64 %v1, i64 %v2)
940 %val = extractvalue {i64, i1} %t, 0
941 %obit = extractvalue {i64, i1} %t, 1
942 br i1 %obit, label %overflow, label %continue, !prof !0
951 define zeroext i1 @usubobri32(i32 %v1, i32 %v2) {
952 ; SDAG-LABEL: usubobri32:
954 ; SDAG-NEXT: cmpl %esi, %edi
955 ; SDAG-NEXT: jb LBB37_1
956 ; SDAG-NEXT: ## %bb.2: ## %continue
957 ; SDAG-NEXT: movb $1, %al
959 ; SDAG-NEXT: LBB37_1: ## %overflow
960 ; SDAG-NEXT: xorl %eax, %eax
963 ; FAST-LABEL: usubobri32:
965 ; FAST-NEXT: cmpl %esi, %edi
966 ; FAST-NEXT: jb LBB37_1
967 ; FAST-NEXT: ## %bb.2: ## %continue
968 ; FAST-NEXT: movb $1, %al
969 ; FAST-NEXT: andb $1, %al
970 ; FAST-NEXT: movzbl %al, %eax
972 ; FAST-NEXT: LBB37_1: ## %overflow
973 ; FAST-NEXT: xorl %eax, %eax
974 ; FAST-NEXT: andb $1, %al
975 ; FAST-NEXT: movzbl %al, %eax
977 %t = call {i32, i1} @llvm.usub.with.overflow.i32(i32 %v1, i32 %v2)
978 %val = extractvalue {i32, i1} %t, 0
979 %obit = extractvalue {i32, i1} %t, 1
980 br i1 %obit, label %overflow, label %continue, !prof !0
989 define zeroext i1 @usubobri64(i64 %v1, i64 %v2) {
990 ; SDAG-LABEL: usubobri64:
992 ; SDAG-NEXT: cmpq %rsi, %rdi
993 ; SDAG-NEXT: jb LBB38_1
994 ; SDAG-NEXT: ## %bb.2: ## %continue
995 ; SDAG-NEXT: movb $1, %al
997 ; SDAG-NEXT: LBB38_1: ## %overflow
998 ; SDAG-NEXT: xorl %eax, %eax
1001 ; FAST-LABEL: usubobri64:
1003 ; FAST-NEXT: cmpq %rsi, %rdi
1004 ; FAST-NEXT: jb LBB38_1
1005 ; FAST-NEXT: ## %bb.2: ## %continue
1006 ; FAST-NEXT: movb $1, %al
1007 ; FAST-NEXT: andb $1, %al
1008 ; FAST-NEXT: movzbl %al, %eax
1010 ; FAST-NEXT: LBB38_1: ## %overflow
1011 ; FAST-NEXT: xorl %eax, %eax
1012 ; FAST-NEXT: andb $1, %al
1013 ; FAST-NEXT: movzbl %al, %eax
1015 %t = call {i64, i1} @llvm.usub.with.overflow.i64(i64 %v1, i64 %v2)
1016 %val = extractvalue {i64, i1} %t, 0
1017 %obit = extractvalue {i64, i1} %t, 1
1018 br i1 %obit, label %overflow, label %continue, !prof !0
1027 define {i64, i1} @uaddoovf(i64 %a, i64 %b) {
1028 ; SDAG-LABEL: uaddoovf:
1030 ; SDAG-NEXT: movzbl %dil, %ecx
1031 ; SDAG-NEXT: movzbl %sil, %eax
1032 ; SDAG-NEXT: addq %rcx, %rax
1033 ; SDAG-NEXT: xorl %edx, %edx
1036 ; FAST-LABEL: uaddoovf:
1038 ; FAST-NEXT: movzbl %dil, %ecx
1039 ; FAST-NEXT: movzbl %sil, %eax
1040 ; FAST-NEXT: addq %rcx, %rax
1041 ; FAST-NEXT: xorl %edx, %edx
1043 %1 = and i64 %a, 255
1044 %2 = and i64 %b, 255
1045 %t = call {i64, i1} @llvm.uadd.with.overflow.i64(i64 %1, i64 %2)
1049 define {i64, i1} @usuboovf(i64 %a, i64 %b) {
1050 ; SDAG-LABEL: usuboovf:
1052 ; SDAG-NEXT: movq %rsi, %rax
1053 ; SDAG-NEXT: notq %rax
1054 ; SDAG-NEXT: xorl %edx, %edx
1057 ; FAST-LABEL: usuboovf:
1059 ; FAST-NEXT: movq %rsi, %rax
1060 ; FAST-NEXT: notq %rax
1061 ; FAST-NEXT: xorl %edx, %edx
1063 %t0 = call {i64, i1} @llvm.usub.with.overflow.i64(i64 %a, i64 %a)
1064 %v0 = extractvalue {i64, i1} %t0, 0
1065 %o0 = extractvalue {i64, i1} %t0, 1
1066 %t1 = call {i64, i1} @llvm.usub.with.overflow.i64(i64 -1, i64 %b)
1067 %v1 = extractvalue {i64, i1} %t1, 0
1068 %o1 = extractvalue {i64, i1} %t1, 1
1069 %oo = or i1 %o0, %o1
1070 %t2 = call {i64, i1} @llvm.usub.with.overflow.i64(i64 %v1, i64 %v0)
1071 %v2 = extractvalue {i64, i1} %t2, 0
1072 %o2 = extractvalue {i64, i1} %t2, 1
1073 %ooo = or i1 %oo, %o2
1074 %t = insertvalue {i64, i1} %t2, i1 %ooo, 1
1078 ; Make sure we select an INC for both the data use and the flag use.
1079 define i32 @incovfselectstore(i32 %v1, i32 %v2, i32* %x) {
1080 ; SDAG-LABEL: incovfselectstore:
1082 ; SDAG-NEXT: movl %esi, %eax
1083 ; SDAG-NEXT: movl %edi, %ecx
1084 ; SDAG-NEXT: incl %ecx
1085 ; SDAG-NEXT: cmovol %edi, %eax
1086 ; SDAG-NEXT: movl %ecx, (%rdx)
1089 ; FAST-LABEL: incovfselectstore:
1091 ; FAST-NEXT: movl %esi, %eax
1092 ; FAST-NEXT: movl %edi, %ecx
1093 ; FAST-NEXT: incl %ecx
1094 ; FAST-NEXT: cmovol %edi, %eax
1095 ; FAST-NEXT: movl %ecx, (%rdx)
1097 %t = call {i32, i1} @llvm.sadd.with.overflow.i32(i32 %v1, i32 1)
1098 %obit = extractvalue {i32, i1} %t, 1
1099 %ret = select i1 %obit, i32 %v1, i32 %v2
1100 %val = extractvalue {i32, i1} %t, 0
1101 store i32 %val, i32* %x
1105 ; Make sure we select a DEC for both the data use and the flag use.
1106 define i32 @decovfselectstore(i32 %v1, i32 %v2, i32* %x) {
1107 ; GENERIC-LABEL: decovfselectstore:
1108 ; GENERIC: ## %bb.0:
1109 ; GENERIC-NEXT: movl %esi, %eax
1110 ; GENERIC-NEXT: movl %edi, %ecx
1111 ; GENERIC-NEXT: decl %ecx
1112 ; GENERIC-NEXT: cmovol %edi, %eax
1113 ; GENERIC-NEXT: movl %ecx, (%rdx)
1114 ; GENERIC-NEXT: retq
1116 ; FAST-LABEL: decovfselectstore:
1118 ; FAST-NEXT: movl %esi, %eax
1119 ; FAST-NEXT: movl %edi, %ecx
1120 ; FAST-NEXT: decl %ecx
1121 ; FAST-NEXT: cmovol %edi, %eax
1122 ; FAST-NEXT: movl %ecx, (%rdx)
1125 ; KNL-LABEL: decovfselectstore:
1127 ; KNL-NEXT: movl %esi, %eax
1128 ; KNL-NEXT: movl %edi, %ecx
1129 ; KNL-NEXT: addl $-1, %ecx
1130 ; KNL-NEXT: cmovol %edi, %eax
1131 ; KNL-NEXT: movl %ecx, (%rdx)
1133 %t = call {i32, i1} @llvm.ssub.with.overflow.i32(i32 %v1, i32 1)
1134 %obit = extractvalue {i32, i1} %t, 1
1135 %ret = select i1 %obit, i32 %v1, i32 %v2
1136 %val = extractvalue {i32, i1} %t, 0
1137 store i32 %val, i32* %x
1141 declare {i8, i1} @llvm.sadd.with.overflow.i8 (i8, i8 ) nounwind readnone
1142 declare {i16, i1} @llvm.sadd.with.overflow.i16(i16, i16) nounwind readnone
1143 declare {i32, i1} @llvm.sadd.with.overflow.i32(i32, i32) nounwind readnone
1144 declare {i64, i1} @llvm.sadd.with.overflow.i64(i64, i64) nounwind readnone
1145 declare {i8, i1} @llvm.uadd.with.overflow.i8 (i8, i8 ) nounwind readnone
1146 declare {i16, i1} @llvm.uadd.with.overflow.i16(i16, i16) nounwind readnone
1147 declare {i32, i1} @llvm.uadd.with.overflow.i32(i32, i32) nounwind readnone
1148 declare {i64, i1} @llvm.uadd.with.overflow.i64(i64, i64) nounwind readnone
1149 declare {i32, i1} @llvm.ssub.with.overflow.i32(i32, i32) nounwind readnone
1150 declare {i64, i1} @llvm.ssub.with.overflow.i64(i64, i64) nounwind readnone
1151 declare {i32, i1} @llvm.usub.with.overflow.i32(i32, i32) nounwind readnone
1152 declare {i64, i1} @llvm.usub.with.overflow.i64(i64, i64) nounwind readnone
1154 !0 = !{!"branch_weights", i32 0, i32 2147483647}