1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc < %s -mtriple=arm64-eabi -verify-machineinstrs | FileCheck %s --check-prefixes=CHECK,SDAG
3 ; RUN: llc < %s -mtriple=arm64-eabi -global-isel -global-isel-abort=2 -verify-machineinstrs | FileCheck %s --check-prefixes=CHECK,GISEL
6 define zeroext i1 @saddo1.i32.unused(i32 %v1, i32 %v2, ptr %res) {
7 ; CHECK-LABEL: saddo1.i32.unused:
8 ; CHECK: // %bb.0: // %entry
9 ; CHECK-NEXT: add w8, w0, w1
10 ; CHECK-NEXT: mov w0, #1 // =0x1
11 ; CHECK-NEXT: str w8, [x2]
14 %t = call {i32, i1} @llvm.sadd.with.overflow.i32(i32 %v1, i32 %v2)
15 %obit = extractvalue {i32, i1} %t, 1
16 %val = extractvalue {i32, i1} %t, 0
17 store i32 %val, ptr %res
21 define zeroext i1 @saddo1.i32.fold(i32 %v1, i32 %v2, ptr %res) {
22 ; CHECK-LABEL: saddo1.i32.fold:
23 ; CHECK: // %bb.0: // %entry
24 ; CHECK-NEXT: mov w8, #20 // =0x14
25 ; CHECK-NEXT: mov w0, wzr
26 ; CHECK-NEXT: str w8, [x2]
29 %t = call {i32, i1} @llvm.sadd.with.overflow.i32(i32 9, i32 11)
30 %val = extractvalue {i32, i1} %t, 0
31 %obit = extractvalue {i32, i1} %t, 1
32 store i32 %val, ptr %res
36 define zeroext i1 @saddo1.i32.addzero(i32 %v1, i32 %v2, ptr %res) {
37 ; CHECK-LABEL: saddo1.i32.addzero:
38 ; CHECK: // %bb.0: // %entry
39 ; CHECK-NEXT: mov w8, w0
40 ; CHECK-NEXT: mov w0, wzr
41 ; CHECK-NEXT: str w8, [x2]
44 %t = call {i32, i1} @llvm.sadd.with.overflow.i32(i32 %v1, i32 0)
45 %val = extractvalue {i32, i1} %t, 0
46 %obit = extractvalue {i32, i1} %t, 1
47 store i32 %val, ptr %res
51 define zeroext i1 @uaddo1.i32.addzero(i32 %v1, i32 %v2, ptr %res) {
52 ; CHECK-LABEL: uaddo1.i32.addzero:
53 ; CHECK: // %bb.0: // %entry
54 ; CHECK-NEXT: mov w8, w0
55 ; CHECK-NEXT: mov w0, wzr
56 ; CHECK-NEXT: str w8, [x2]
59 %t = call {i32, i1} @llvm.uadd.with.overflow.i32(i32 %v1, i32 0)
60 %val = extractvalue {i32, i1} %t, 0
61 %obit = extractvalue {i32, i1} %t, 1
62 store i32 %val, ptr %res
66 define i32 @saddo.select.i64(i32 %v1, i32 %v2, i1 %v3, i64 %v4, i64 %v5) {
67 ; CHECK-LABEL: saddo.select.i64:
68 ; CHECK: // %bb.0: // %entry
69 ; CHECK-NEXT: mov w0, w1
72 %lhs = and i64 %v4, 12
73 %rhs = and i64 %v5, 13
74 %t = call {i64, i1} @llvm.sadd.with.overflow.64(i64 %lhs, i64 %rhs)
75 %obit = extractvalue {i64, i1} %t, 1
76 %ret = select i1 %obit, i32 %v1, i32 %v2
80 define i32 @uaddo.select.i64(i32 %v1, i32 %v2, i1 %v3, i64 %v4, i64 %v5) {
81 ; CHECK-LABEL: uaddo.select.i64:
82 ; CHECK: // %bb.0: // %entry
83 ; CHECK-NEXT: mov w0, w1
87 %rhs = and i64 %v5, 10
88 %t = call {i64, i1} @llvm.uadd.with.overflow.64(i64 %lhs, i64 %rhs)
89 %obit = extractvalue {i64, i1} %t, 1
90 %ret = select i1 %obit, i32 %v1, i32 %v2
94 define zeroext i1 @saddo.canon.i32(i32 %v1, i32 %v2, i32 %v3, i32 %v4, i32 %v5, ptr %res) {
95 ; CHECK-LABEL: saddo.canon.i32:
96 ; CHECK: // %bb.0: // %entry
97 ; CHECK-NEXT: mov w0, wzr
98 ; CHECK-NEXT: str w4, [x5]
101 %t = call {i32, i1} @llvm.sadd.with.overflow.i32(i32 0, i32 %v5)
102 %val = extractvalue {i32, i1} %t, 0
103 %obit = extractvalue {i32, i1} %t, 1
104 store i32 %val, ptr %res
107 define zeroext i1 @saddo.add.i32(i32 %v1, i32 %v2, i32 %v3, i32 %v4, i32 %v5, ptr %res) {
108 ; SDAG-LABEL: saddo.add.i32:
109 ; SDAG: // %bb.0: // %entry
110 ; SDAG-NEXT: add w8, w4, #100
111 ; SDAG-NEXT: subs w8, w8, #100
112 ; SDAG-NEXT: cset w0, vs
113 ; SDAG-NEXT: str w8, [x5]
116 ; GISEL-LABEL: saddo.add.i32:
117 ; GISEL: // %bb.0: // %entry
118 ; GISEL-NEXT: mov w0, wzr
119 ; GISEL-NEXT: str w4, [x5]
122 %lhs = add nsw i32 %v5, 100
123 %t = call {i32, i1} @llvm.sadd.with.overflow.i32(i32 %lhs, i32 -100)
124 %val = extractvalue {i32, i1} %t, 0
125 %obit = extractvalue {i32, i1} %t, 1
126 store i32 %val, ptr %res
130 define zeroext i1 @uaddo.add.i32(i32 %v1, i32 %v2, i32 %v3, i32 %v4, i32 %v5, ptr %res) {
131 ; SDAG-LABEL: uaddo.add.i32:
132 ; SDAG: // %bb.0: // %entry
133 ; SDAG-NEXT: add w8, w4, #5
134 ; SDAG-NEXT: adds w8, w8, #5
135 ; SDAG-NEXT: cset w0, hs
136 ; SDAG-NEXT: str w8, [x5]
139 ; GISEL-LABEL: uaddo.add.i32:
140 ; GISEL: // %bb.0: // %entry
141 ; GISEL-NEXT: adds w8, w4, #10
142 ; GISEL-NEXT: cset w0, hs
143 ; GISEL-NEXT: str w8, [x5]
146 %lhs = add nuw i32 %v5, 5
147 %t = call {i32, i1} @llvm.uadd.with.overflow.i32(i32 %lhs, i32 5)
148 %val = extractvalue {i32, i1} %t, 0
149 %obit = extractvalue {i32, i1} %t, 1
150 store i32 %val, ptr %res
154 define zeroext i1 @uaddo.negative.i32(i32 %v1, i32 %v2, i32 %v3, i32 %v4, i32 %v5, ptr %res) {
155 ; CHECK-LABEL: uaddo.negative.i32:
156 ; CHECK: // %bb.0: // %entry
157 ; CHECK-NEXT: adds w8, w3, #5
158 ; CHECK-NEXT: cset w0, hs
159 ; CHECK-NEXT: str w8, [x5]
162 %t = call {i32, i1} @llvm.uadd.with.overflow.i32(i32 %v4, i32 5)
163 %val = extractvalue {i32, i1} %t, 0
164 %obit = extractvalue {i32, i1} %t, 1
165 store i32 %val, ptr %res
169 define i32 @saddo.always.i8(i32 %v1, i32 %v2, i32 %v3, i32 %v4, i32 %v5, ptr %res) {
170 ; CHECK-LABEL: saddo.always.i8:
171 ; CHECK: // %bb.0: // %entry
172 ; CHECK-NEXT: mov w0, w1
175 %t = call {i8, i1} @llvm.sadd.with.overflow.i8(i8 255, i8 254)
176 %obit = extractvalue {i8, i1} %t, 1
177 %ret = select i1 %obit, i32 %v1, i32 %v2
181 define i32 @uaddo.never.i8(i32 %v1, i32 %v2, i32 %v3, i32 %v4, i32 %v5, ptr %res) {
182 ; CHECK-LABEL: uaddo.never.i8:
183 ; CHECK: // %bb.0: // %entry
184 ; CHECK-NEXT: mov w0, w1
187 %t = call {i8, i1} @llvm.uadd.with.overflow.i8(i8 2, i8 1)
188 %obit = extractvalue {i8, i1} %t, 1
189 %ret = select i1 %obit, i32 %v1, i32 %v2
194 declare {i8, i1} @llvm.sadd.with.overflow.i8(i8, i8) nounwind readnone
195 declare {i16, i1} @llvm.sadd.with.overflow.i16(i16, i16) nounwind readnone
196 declare {i32, i1} @llvm.sadd.with.overflow.i32(i32, i32) nounwind readnone
197 declare {i64, i1} @llvm.sadd.with.overflow.i64(i64, i64) nounwind readnone
198 declare {i8, i1} @llvm.uadd.with.overflow.i8(i8, i8) nounwind readnone
199 declare {i16, i1} @llvm.uadd.with.overflow.i16(i16, i16) nounwind readnone
200 declare {i32, i1} @llvm.uadd.with.overflow.i32(i32, i32) nounwind readnone
201 declare {i64, i1} @llvm.uadd.with.overflow.i64(i64, i64) nounwind readnone
202 declare {i8, i1} @llvm.ssub.with.overflow.i8(i8, i8) nounwind readnone
203 declare {i16, i1} @llvm.ssub.with.overflow.i16(i16, i16) nounwind readnone
204 declare {i32, i1} @llvm.ssub.with.overflow.i32(i32, i32) nounwind readnone
205 declare {i64, i1} @llvm.ssub.with.overflow.i64(i64, i64) nounwind readnone
206 declare {i8, i1} @llvm.usub.with.overflow.i8(i8, i8) nounwind readnone
207 declare {i16, i1} @llvm.usub.with.overflow.i16(i16, i16) nounwind readnone
208 declare {i32, i1} @llvm.usub.with.overflow.i32(i32, i32) nounwind readnone
209 declare {i64, i1} @llvm.usub.with.overflow.i64(i64, i64) nounwind readnone
210 declare {i8, i1} @llvm.smul.with.overflow.i8(i8, i8) nounwind readnone
211 declare {i16, i1} @llvm.smul.with.overflow.i16(i16, i16) nounwind readnone
212 declare {i32, i1} @llvm.smul.with.overflow.i32(i32, i32) nounwind readnone
213 declare {i64, i1} @llvm.smul.with.overflow.i64(i64, i64) nounwind readnone
214 declare {i8, i1} @llvm.umul.with.overflow.i8(i8, i8) nounwind readnone
215 declare {i16, i1} @llvm.umul.with.overflow.i16(i16, i16) nounwind readnone
216 declare {i32, i1} @llvm.umul.with.overflow.i32(i32, i32) nounwind readnone
217 declare {i64, i1} @llvm.umul.with.overflow.i64(i64, i64) nounwind readnone