1 ; Test 64-bit addition in which the second operand is constant.
3 ; RUN: llc < %s -mtriple=s390x-linux-gnu -mcpu=z10 | FileCheck %s
4 ; RUN: llc < %s -mtriple=s390x-linux-gnu -mcpu=z196 | FileCheck %s
8 ; Check additions of 1.
9 define zeroext i1 @f1(i64 %dummy, i64 %a, ptr %res) {
12 ; CHECK-DAG: stg %r3, 0(%r4)
13 ; CHECK-DAG: ipm [[REG:%r[0-5]]]
14 ; CHECK-DAG: afi [[REG]], 1342177280
15 ; CHECK-DAG: risbg %r2, [[REG]], 63, 191, 33
17 %t = call {i64, i1} @llvm.sadd.with.overflow.i64(i64 %a, i64 1)
18 %val = extractvalue {i64, i1} %t, 0
19 %obit = extractvalue {i64, i1} %t, 1
20 store i64 %val, ptr %res
25 ; Check the high end of the AGHI range.
26 define zeroext i1 @f2(i64 %dummy, i64 %a, ptr %res) {
28 ; CHECK: aghi %r3, 32767
29 ; CHECK-DAG: stg %r3, 0(%r4)
30 ; CHECK-DAG: ipm [[REG:%r[0-5]]]
31 ; CHECK-DAG: afi [[REG]], 1342177280
32 ; CHECK-DAG: risbg %r2, [[REG]], 63, 191, 33
34 %t = call {i64, i1} @llvm.sadd.with.overflow.i64(i64 %a, i64 32767)
35 %val = extractvalue {i64, i1} %t, 0
36 %obit = extractvalue {i64, i1} %t, 1
37 store i64 %val, ptr %res
41 ; Check the next value up, which must use AGFI instead.
42 define zeroext i1 @f3(i64 %dummy, i64 %a, ptr %res) {
44 ; CHECK: agfi %r3, 32768
45 ; CHECK-DAG: stg %r3, 0(%r4)
46 ; CHECK-DAG: ipm [[REG:%r[0-5]]]
47 ; CHECK-DAG: afi [[REG]], 1342177280
48 ; CHECK-DAG: risbg %r2, [[REG]], 63, 191, 33
50 %t = call {i64, i1} @llvm.sadd.with.overflow.i64(i64 %a, i64 32768)
51 %val = extractvalue {i64, i1} %t, 0
52 %obit = extractvalue {i64, i1} %t, 1
53 store i64 %val, ptr %res
57 ; Check the high end of the AGFI range.
58 define zeroext i1 @f4(i64 %dummy, i64 %a, ptr %res) {
60 ; CHECK: agfi %r3, 2147483647
61 ; CHECK-DAG: stg %r3, 0(%r4)
62 ; CHECK-DAG: ipm [[REG:%r[0-5]]]
63 ; CHECK-DAG: afi [[REG]], 1342177280
64 ; CHECK-DAG: risbg %r2, [[REG]], 63, 191, 33
66 %t = call {i64, i1} @llvm.sadd.with.overflow.i64(i64 %a, i64 2147483647)
67 %val = extractvalue {i64, i1} %t, 0
68 %obit = extractvalue {i64, i1} %t, 1
69 store i64 %val, ptr %res
73 ; Check the next value up, which must be loaded into a register first.
74 define zeroext i1 @f5(i64 %dummy, i64 %a, ptr %res) {
76 ; CHECK: llilh [[REG1:%r[0-9]+]], 32768
77 ; CHECK: agr [[REG1]], %r3
78 ; CHECK-DAG: stg [[REG1]], 0(%r4)
79 ; CHECK-DAG: ipm [[REG:%r[0-5]]]
80 ; CHECK-DAG: afi [[REG]], 1342177280
81 ; CHECK-DAG: risbg %r2, [[REG]], 63, 191, 33
83 %t = call {i64, i1} @llvm.sadd.with.overflow.i64(i64 %a, i64 2147483648)
84 %val = extractvalue {i64, i1} %t, 0
85 %obit = extractvalue {i64, i1} %t, 1
86 store i64 %val, ptr %res
90 ; Check the high end of the negative AGHI range.
91 define zeroext i1 @f6(i64 %dummy, i64 %a, ptr %res) {
94 ; CHECK-DAG: stg %r3, 0(%r4)
95 ; CHECK-DAG: ipm [[REG:%r[0-5]]]
96 ; CHECK-DAG: afi [[REG]], 1342177280
97 ; CHECK-DAG: risbg %r2, [[REG]], 63, 191, 33
99 %t = call {i64, i1} @llvm.sadd.with.overflow.i64(i64 %a, i64 -1)
100 %val = extractvalue {i64, i1} %t, 0
101 %obit = extractvalue {i64, i1} %t, 1
102 store i64 %val, ptr %res
106 ; Check the low end of the AGHI range.
107 define zeroext i1 @f7(i64 %dummy, i64 %a, ptr %res) {
109 ; CHECK: aghi %r3, -32768
110 ; CHECK-DAG: stg %r3, 0(%r4)
111 ; CHECK-DAG: ipm [[REG:%r[0-5]]]
112 ; CHECK-DAG: afi [[REG]], 1342177280
113 ; CHECK-DAG: risbg %r2, [[REG]], 63, 191, 33
115 %t = call {i64, i1} @llvm.sadd.with.overflow.i64(i64 %a, i64 -32768)
116 %val = extractvalue {i64, i1} %t, 0
117 %obit = extractvalue {i64, i1} %t, 1
118 store i64 %val, ptr %res
122 ; Check the next value down, which must use AGFI instead.
123 define zeroext i1 @f8(i64 %dummy, i64 %a, ptr %res) {
125 ; CHECK: agfi %r3, -32769
126 ; CHECK-DAG: stg %r3, 0(%r4)
127 ; CHECK-DAG: ipm [[REG:%r[0-5]]]
128 ; CHECK-DAG: afi [[REG]], 1342177280
129 ; CHECK-DAG: risbg %r2, [[REG]], 63, 191, 33
131 %t = call {i64, i1} @llvm.sadd.with.overflow.i64(i64 %a, i64 -32769)
132 %val = extractvalue {i64, i1} %t, 0
133 %obit = extractvalue {i64, i1} %t, 1
134 store i64 %val, ptr %res
138 ; Check the low end of the AGFI range.
139 define zeroext i1 @f9(i64 %dummy, i64 %a, ptr %res) {
141 ; CHECK: agfi %r3, -2147483648
142 ; CHECK-DAG: stg %r3, 0(%r4)
143 ; CHECK-DAG: ipm [[REG:%r[0-5]]]
144 ; CHECK-DAG: afi [[REG]], 1342177280
145 ; CHECK-DAG: risbg %r2, [[REG]], 63, 191, 33
147 %t = call {i64, i1} @llvm.sadd.with.overflow.i64(i64 %a, i64 -2147483648)
148 %val = extractvalue {i64, i1} %t, 0
149 %obit = extractvalue {i64, i1} %t, 1
150 store i64 %val, ptr %res
154 ; Check the next value down, which can use register subtraction instead.
155 define zeroext i1 @f10(i64 %dummy, i64 %a, ptr %res) {
157 ; CHECK: llilf [[REG1:%r[0-9]+]], 2147483649
158 ; CHECK: sgr %r3, [[REG1]]
159 ; CHECK-DAG: stg %r3, 0(%r4)
160 ; CHECK-DAG: ipm [[REG:%r[0-5]]]
161 ; CHECK-DAG: afi [[REG]], 1342177280
162 ; CHECK-DAG: risbg %r2, [[REG]], 63, 191, 33
164 %t = call {i64, i1} @llvm.sadd.with.overflow.i64(i64 %a, i64 -2147483649)
165 %val = extractvalue {i64, i1} %t, 0
166 %obit = extractvalue {i64, i1} %t, 1
167 store i64 %val, ptr %res
171 ; We may be able to use LLILH instead of LLILF.
172 define zeroext i1 @f11(i64 %dummy, i64 %a, ptr %res) {
174 ; CHECK: llilh [[REG1:%r[0-9]+]], 32769
175 ; CHECK: sgr %r3, [[REG1]]
176 ; CHECK-DAG: stg %r3, 0(%r4)
177 ; CHECK-DAG: ipm [[REG:%r[0-5]]]
178 ; CHECK-DAG: afi [[REG]], 1342177280
179 ; CHECK-DAG: risbg %r2, [[REG]], 63, 191, 33
181 %t = call {i64, i1} @llvm.sadd.with.overflow.i64(i64 %a, i64 -2147549184)
182 %val = extractvalue {i64, i1} %t, 0
183 %obit = extractvalue {i64, i1} %t, 1
184 store i64 %val, ptr %res
188 ; Check low end of the LLILF/SGR range.
189 define zeroext i1 @f12(i64 %dummy, i64 %a, ptr %res) {
191 ; CHECK: llilf [[REG1:%r[0-9]+]], 4294967295
192 ; CHECK: sgr %r3, [[REG1]]
193 ; CHECK-DAG: stg %r3, 0(%r4)
194 ; CHECK-DAG: ipm [[REG:%r[0-5]]]
195 ; CHECK-DAG: afi [[REG]], 1342177280
196 ; CHECK-DAG: risbg %r2, [[REG]], 63, 191, 33
198 %t = call {i64, i1} @llvm.sadd.with.overflow.i64(i64 %a, i64 -4294967295)
199 %val = extractvalue {i64, i1} %t, 0
200 %obit = extractvalue {i64, i1} %t, 1
201 store i64 %val, ptr %res
205 ; Check the next value down, which must use register addition instead.
206 define zeroext i1 @f13(i64 %dummy, i64 %a, ptr %res) {
208 ; CHECK: llihf [[REG1:%r[0-9]+]], 4294967295
209 ; CHECK: agr [[REG1]], %r3
210 ; CHECK-DAG: stg [[REG1]], 0(%r4)
211 ; CHECK-DAG: ipm [[REG:%r[0-5]]]
212 ; CHECK-DAG: afi [[REG]], 1342177280
213 ; CHECK-DAG: risbg %r2, [[REG]], 63, 191, 33
215 %t = call {i64, i1} @llvm.sadd.with.overflow.i64(i64 %a, i64 -4294967296)
216 %val = extractvalue {i64, i1} %t, 0
217 %obit = extractvalue {i64, i1} %t, 1
218 store i64 %val, ptr %res
222 ; Check using the overflow result for a branch.
223 define void @f14(i64 %dummy, i64 %a, ptr %res) {
226 ; CHECK: stg %r3, 0(%r4)
227 ; CHECK: {{jgo foo@PLT|bnor %r14}}
228 ; CHECK: {{br %r14|jg foo@PLT}}
229 %t = call {i64, i1} @llvm.sadd.with.overflow.i64(i64 %a, i64 1)
230 %val = extractvalue {i64, i1} %t, 0
231 %obit = extractvalue {i64, i1} %t, 1
232 store i64 %val, ptr %res
233 br i1 %obit, label %call, label %exit
243 ; ... and the same with the inverted direction.
244 define void @f15(i64 %dummy, i64 %a, ptr %res) {
247 ; CHECK: stg %r3, 0(%r4)
248 ; CHECK: {{jgno foo@PLT|bor %r14}}
249 ; CHECK: {{br %r14|jg foo@PLT}}
250 %t = call {i64, i1} @llvm.sadd.with.overflow.i64(i64 %a, i64 1)
251 %val = extractvalue {i64, i1} %t, 0
252 %obit = extractvalue {i64, i1} %t, 1
253 store i64 %val, ptr %res
254 br i1 %obit, label %exit, label %call
264 declare {i64, i1} @llvm.sadd.with.overflow.i64(i64, i64) nounwind readnone