1 ; Test 32-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(i32 %dummy, i32 %a, i32 *%res) {
12 ; CHECK-DAG: st %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 {i32, i1} @llvm.sadd.with.overflow.i32(i32 %a, i32 1)
18 %val = extractvalue {i32, i1} %t, 0
19 %obit = extractvalue {i32, i1} %t, 1
20 store i32 %val, i32 *%res
24 ; Check the high end of the AHI range.
25 define zeroext i1 @f2(i32 %dummy, i32 %a, i32 *%res) {
27 ; CHECK: ahi %r3, 32767
28 ; CHECK-DAG: st %r3, 0(%r4)
29 ; CHECK-DAG: ipm [[REG:%r[0-5]]]
30 ; CHECK-DAG: afi [[REG]], 1342177280
31 ; CHECK-DAG: risbg %r2, [[REG]], 63, 191, 33
33 %t = call {i32, i1} @llvm.sadd.with.overflow.i32(i32 %a, i32 32767)
34 %val = extractvalue {i32, i1} %t, 0
35 %obit = extractvalue {i32, i1} %t, 1
36 store i32 %val, i32 *%res
40 ; Check the next value up, which must use AFI instead.
41 define zeroext i1 @f3(i32 %dummy, i32 %a, i32 *%res) {
43 ; CHECK: afi %r3, 32768
44 ; CHECK-DAG: st %r3, 0(%r4)
45 ; CHECK-DAG: ipm [[REG:%r[0-5]]]
46 ; CHECK-DAG: afi [[REG]], 1342177280
47 ; CHECK-DAG: risbg %r2, [[REG]], 63, 191, 33
49 %t = call {i32, i1} @llvm.sadd.with.overflow.i32(i32 %a, i32 32768)
50 %val = extractvalue {i32, i1} %t, 0
51 %obit = extractvalue {i32, i1} %t, 1
52 store i32 %val, i32 *%res
56 ; Check the high end of the signed 32-bit range.
57 define zeroext i1 @f4(i32 %dummy, i32 %a, i32 *%res) {
59 ; CHECK: afi %r3, 2147483647
60 ; CHECK-DAG: st %r3, 0(%r4)
61 ; CHECK-DAG: ipm [[REG:%r[0-5]]]
62 ; CHECK-DAG: afi [[REG]], 1342177280
63 ; CHECK-DAG: risbg %r2, [[REG]], 63, 191, 33
65 %t = call {i32, i1} @llvm.sadd.with.overflow.i32(i32 %a, i32 2147483647)
66 %val = extractvalue {i32, i1} %t, 0
67 %obit = extractvalue {i32, i1} %t, 1
68 store i32 %val, i32 *%res
72 ; Check the next value up, which is treated as a negative value.
73 define zeroext i1 @f5(i32 %dummy, i32 %a, i32 *%res) {
75 ; CHECK: afi %r3, -2147483648
76 ; CHECK-DAG: st %r3, 0(%r4)
77 ; CHECK-DAG: ipm [[REG:%r[0-5]]]
78 ; CHECK-DAG: afi [[REG]], 1342177280
79 ; CHECK-DAG: risbg %r2, [[REG]], 63, 191, 33
81 %t = call {i32, i1} @llvm.sadd.with.overflow.i32(i32 %a, i32 2147483648)
82 %val = extractvalue {i32, i1} %t, 0
83 %obit = extractvalue {i32, i1} %t, 1
84 store i32 %val, i32 *%res
88 ; Check the high end of the negative AHI range.
89 define zeroext i1 @f6(i32 %dummy, i32 %a, i32 *%res) {
92 ; CHECK-DAG: st %r3, 0(%r4)
93 ; CHECK-DAG: ipm [[REG:%r[0-5]]]
94 ; CHECK-DAG: afi [[REG]], 1342177280
95 ; CHECK-DAG: risbg %r2, [[REG]], 63, 191, 33
97 %t = call {i32, i1} @llvm.sadd.with.overflow.i32(i32 %a, i32 -1)
98 %val = extractvalue {i32, i1} %t, 0
99 %obit = extractvalue {i32, i1} %t, 1
100 store i32 %val, i32 *%res
104 ; Check the low end of the AHI range.
105 define zeroext i1 @f7(i32 %dummy, i32 %a, i32 *%res) {
107 ; CHECK: ahi %r3, -32768
108 ; CHECK-DAG: st %r3, 0(%r4)
109 ; CHECK-DAG: ipm [[REG:%r[0-5]]]
110 ; CHECK-DAG: afi [[REG]], 1342177280
111 ; CHECK-DAG: risbg %r2, [[REG]], 63, 191, 33
113 %t = call {i32, i1} @llvm.sadd.with.overflow.i32(i32 %a, i32 -32768)
114 %val = extractvalue {i32, i1} %t, 0
115 %obit = extractvalue {i32, i1} %t, 1
116 store i32 %val, i32 *%res
120 ; Check the next value down, which must use AFI instead.
121 define zeroext i1 @f8(i32 %dummy, i32 %a, i32 *%res) {
123 ; CHECK: afi %r3, -32769
124 ; CHECK-DAG: st %r3, 0(%r4)
125 ; CHECK-DAG: ipm [[REG:%r[0-5]]]
126 ; CHECK-DAG: afi [[REG]], 1342177280
127 ; CHECK-DAG: risbg %r2, [[REG]], 63, 191, 33
129 %t = call {i32, i1} @llvm.sadd.with.overflow.i32(i32 %a, i32 -32769)
130 %val = extractvalue {i32, i1} %t, 0
131 %obit = extractvalue {i32, i1} %t, 1
132 store i32 %val, i32 *%res
136 ; Check the low end of the signed 32-bit range.
137 define zeroext i1 @f9(i32 %dummy, i32 %a, i32 *%res) {
139 ; CHECK: afi %r3, -2147483648
140 ; CHECK-DAG: st %r3, 0(%r4)
141 ; CHECK-DAG: ipm [[REG:%r[0-5]]]
142 ; CHECK-DAG: afi [[REG]], 1342177280
143 ; CHECK-DAG: risbg %r2, [[REG]], 63, 191, 33
145 %t = call {i32, i1} @llvm.sadd.with.overflow.i32(i32 %a, i32 -2147483648)
146 %val = extractvalue {i32, i1} %t, 0
147 %obit = extractvalue {i32, i1} %t, 1
148 store i32 %val, i32 *%res
152 ; Check the next value down, which is treated as a positive value.
153 define zeroext i1 @f10(i32 %dummy, i32 %a, i32 *%res) {
155 ; CHECK: afi %r3, 2147483647
156 ; CHECK-DAG: st %r3, 0(%r4)
157 ; CHECK-DAG: ipm [[REG:%r[0-5]]]
158 ; CHECK-DAG: afi [[REG]], 1342177280
159 ; CHECK-DAG: risbg %r2, [[REG]], 63, 191, 33
161 %t = call {i32, i1} @llvm.sadd.with.overflow.i32(i32 %a, i32 -2147483649)
162 %val = extractvalue {i32, i1} %t, 0
163 %obit = extractvalue {i32, i1} %t, 1
164 store i32 %val, i32 *%res
168 ; Check using the overflow result for a branch.
169 define void @f11(i32 %dummy, i32 %a, i32 *%res) {
172 ; CHECK: st %r3, 0(%r4)
173 ; CHECK: {{jgo foo@PLT|bnor %r14}}
174 ; CHECK: {{br %r14|jg foo@PLT}}
175 %t = call {i32, i1} @llvm.sadd.with.overflow.i32(i32 %a, i32 1)
176 %val = extractvalue {i32, i1} %t, 0
177 %obit = extractvalue {i32, i1} %t, 1
178 store i32 %val, i32 *%res
179 br i1 %obit, label %call, label %exit
189 ; ... and the same with the inverted direction.
190 define void @f12(i32 %dummy, i32 %a, i32 *%res) {
193 ; CHECK: st %r3, 0(%r4)
194 ; CHECK: {{jgno foo@PLT|bor %r14}}
195 ; CHECK: {{br %r14|jg foo@PLT}}
196 %t = call {i32, i1} @llvm.sadd.with.overflow.i32(i32 %a, i32 1)
197 %val = extractvalue {i32, i1} %t, 0
198 %obit = extractvalue {i32, i1} %t, 1
199 store i32 %val, i32 *%res
200 br i1 %obit, label %exit, label %call
211 declare {i32, i1} @llvm.sadd.with.overflow.i32(i32, i32) nounwind readnone