1 ; RUN: llc < %s -mtriple=arm-linux -mcpu=generic -verify-machineinstrs | FileCheck %s --check-prefix=CHECK --check-prefix=ARM
2 ; RUN: llc < %s -mtriple=thumbv6m-eabi -verify-machineinstrs | FileCheck %s --check-prefix=CHECK --check-prefix=THUMBV6
3 ; RUN: llc < %s -mtriple=thumbv7-eabi -verify-machineinstrs | FileCheck %s --check-prefix=CHECK --check-prefix=THUMBV7
5 define i32 @uadd_overflow(i32 %a, i32 %b) #0 {
6 %sadd = tail call { i32, i1 } @llvm.uadd.with.overflow.i32(i32 %a, i32 %b)
7 %1 = extractvalue { i32, i1 } %sadd, 1
11 ; CHECK-LABEL: uadd_overflow:
13 ; ARM: adds r[[R0:[0-9]+]], r[[R0]], r[[R1:[0-9]+]]
14 ; ARM: mov r[[R2:[0-9]+]], #0
15 ; ARM: adc r[[R0]], r[[R2]], #0
17 ; THUMBV6: movs r[[R2:[0-9]+]], #0
18 ; THUMBV6: adds r[[R0:[0-9]+]], r[[R0]], r[[R1:[0-9]+]]
19 ; THUMBV6: adcs r[[R2]], r[[R2]]
20 ; THUMBV6: mov r[[R0]], r[[R2]]
22 ; THUMBV7: adds r[[R0:[0-9]+]], r[[R0]], r[[R1:[0-9]+]]
23 ; THUMBV7: mov.w r[[R2:[0-9]+]], #0
24 ; THUMBV7: adc r[[R0]], r[[R2]], #0
28 define i32 @sadd_overflow(i32 %a, i32 %b) #0 {
29 %sadd = tail call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 %a, i32 %b)
30 %1 = extractvalue { i32, i1 } %sadd, 1
31 %2 = zext i1 %1 to i32
34 ; CHECK-LABEL: sadd_overflow:
36 ; ARM: adds r[[R2:[0-9]+]], r[[R0:[0-9]+]], r[[R1:[0-9]+]]
37 ; ARM: mov r[[R0]], #1
38 ; ARM: movvc r[[R0]], #0
41 ; THUMBV6: adds r0, r0, r1
42 ; THUMBV6: bvc .LBB1_2
44 ; THUMBV7: adds r[[R2:[0-9]+]], r[[R0]], r[[R1:[0-9]+]]
45 ; THUMBV7: mov.w r[[R0:[0-9]+]], #1
47 ; THUMBV7: movvc r[[R0]], #0
50 define i32 @usub_overflow(i32 %a, i32 %b) #0 {
51 %sadd = tail call { i32, i1 } @llvm.usub.with.overflow.i32(i32 %a, i32 %b)
52 %1 = extractvalue { i32, i1 } %sadd, 1
53 %2 = zext i1 %1 to i32
56 ; CHECK-LABEL: usub_overflow:
58 ; ARM: subs r[[R0:[0-9]+]], r[[R0]], r[[R1:[0-9]+]]
59 ; ARM: mov r[[R2:[0-9]+]], #0
60 ; ARM: adc r[[R0]], r[[R2]], #0
61 ; ARM: rsb r[[R0]], r[[R0]], #1
63 ; THUMBV6: movs r[[R2:[0-9]+]], #0
64 ; THUMBV6: subs r[[R0:[0-9]+]], r[[R0]], r[[R1:[0-9]+]]
65 ; THUMBV6: adcs r[[R2]], r[[R2]]
66 ; THUMBV6: movs r[[R0]], #1
67 ; THUMBV6: subs r[[R0]], r[[R0]], r[[R2]]
69 ; THUMBV7: subs r[[R0:[0-9]+]], r[[R0]], r[[R1:[0-9]+]]
70 ; THUMBV7: mov.w r[[R2:[0-9]+]], #0
71 ; THUMBV7: adc r[[R0]], r[[R2]], #0
72 ; THUMBV7: rsb.w r[[R0]], r[[R0]], #1
74 ; We should know that the overflow is just 1 bit,
75 ; no need to clear any other bit
79 define i32 @ssub_overflow(i32 %a, i32 %b) #0 {
80 %sadd = tail call { i32, i1 } @llvm.ssub.with.overflow.i32(i32 %a, i32 %b)
81 %1 = extractvalue { i32, i1 } %sadd, 1
82 %2 = zext i1 %1 to i32
85 ; CHECK-LABEL: ssub_overflow:
87 ; ARM: mov r[[R2]], #1
88 ; ARM: cmp r[[R0]], r[[R1]]
89 ; ARM: movvc r[[R2]], #0
92 ; THUMBV6: bvc .LBB3_2
94 ; THUMBV7: movs r[[R2:[0-9]+]], #1
95 ; THUMBV7: cmp r[[R0:[0-9]+]], r[[R1:[0-9]+]]
97 ; THUMBV7: movvc r[[R2]], #0
98 ; THUMBV7: mov r[[R0]], r[[R2]]
101 declare { i32, i1 } @llvm.uadd.with.overflow.i32(i32, i32) #1
102 declare { i32, i1 } @llvm.sadd.with.overflow.i32(i32, i32) #2
103 declare { i32, i1 } @llvm.usub.with.overflow.i32(i32, i32) #3
104 declare { i32, i1 } @llvm.ssub.with.overflow.i32(i32, i32) #4