1 ; Test 32-bit unsigned division and remainder.
3 ; RUN: llc < %s -mtriple=s390x-linux-gnu -asm-verbose=0 | FileCheck %s
7 ; Test register division. The result is in the second of the two registers.
8 define void @f1(i32 %dummy, i32 %a, i32 %b, ptr %dest) {
11 ; CHECK: {{llill|lhi}} %r2, 0
14 ; CHECK: st %r3, 0(%r5)
16 %div = udiv i32 %a, %b
17 store i32 %div, ptr %dest
21 ; Test register remainder. The result is in the first of the two registers.
22 define void @f2(i32 %dummy, i32 %a, i32 %b, ptr %dest) {
25 ; CHECK: {{llill|lhi}} %r2, 0
28 ; CHECK: st %r2, 0(%r5)
30 %rem = urem i32 %a, %b
31 store i32 %rem, ptr %dest
35 ; Test that division and remainder use a single instruction.
36 define i32 @f3(i32 %dummy1, i32 %a, i32 %b) {
39 ; CHECK: {{llill|lhi}} %r2, 0
45 %div = udiv i32 %a, %b
46 %rem = urem i32 %a, %b
47 %or = or i32 %rem, %div
51 ; Test memory division with no displacement.
52 define void @f4(i32 %dummy, i32 %a, ptr %src, ptr %dest) {
55 ; CHECK: {{llill|lhi}} %r2, 0
57 ; CHECK: dl %r2, 0(%r4)
58 ; CHECK: st %r3, 0(%r5)
60 %b = load i32, ptr %src
61 %div = udiv i32 %a, %b
62 store i32 %div, ptr %dest
66 ; Test memory remainder with no displacement.
67 define void @f5(i32 %dummy, i32 %a, ptr %src, ptr %dest) {
70 ; CHECK: {{llill|lhi}} %r2, 0
72 ; CHECK: dl %r2, 0(%r4)
73 ; CHECK: st %r2, 0(%r5)
75 %b = load i32, ptr %src
76 %rem = urem i32 %a, %b
77 store i32 %rem, ptr %dest
81 ; Test both memory division and memory remainder.
82 define i32 @f6(i32 %dummy, i32 %a, ptr %src) {
85 ; CHECK: {{llill|lhi}} %r2, 0
87 ; CHECK: dl %r2, 0(%r4)
88 ; CHECK-NOT: {{dl|dlr}}
91 %b = load i32, ptr %src
92 %div = udiv i32 %a, %b
93 %rem = urem i32 %a, %b
94 %or = or i32 %rem, %div
98 ; Check the high end of the DL range.
99 define i32 @f7(i32 %dummy, i32 %a, ptr %src) {
101 ; CHECK: dl %r2, 524284(%r4)
103 %ptr = getelementptr i32, ptr %src, i64 131071
104 %b = load i32, ptr %ptr
105 %rem = urem i32 %a, %b
109 ; Check the next word up, which needs separate address logic.
110 ; Other sequences besides this one would be OK.
111 define i32 @f8(i32 %dummy, i32 %a, ptr %src) {
113 ; CHECK: agfi %r4, 524288
114 ; CHECK: dl %r2, 0(%r4)
116 %ptr = getelementptr i32, ptr %src, i64 131072
117 %b = load i32, ptr %ptr
118 %rem = urem i32 %a, %b
122 ; Check the high end of the negative aligned DL range.
123 define i32 @f9(i32 %dummy, i32 %a, ptr %src) {
125 ; CHECK: dl %r2, -4(%r4)
127 %ptr = getelementptr i32, ptr %src, i64 -1
128 %b = load i32, ptr %ptr
129 %rem = urem i32 %a, %b
133 ; Check the low end of the DL range.
134 define i32 @f10(i32 %dummy, i32 %a, ptr %src) {
136 ; CHECK: dl %r2, -524288(%r4)
138 %ptr = getelementptr i32, ptr %src, i64 -131072
139 %b = load i32, ptr %ptr
140 %rem = urem i32 %a, %b
144 ; Check the next word down, which needs separate address logic.
145 ; Other sequences besides this one would be OK.
146 define i32 @f11(i32 %dummy, i32 %a, ptr %src) {
148 ; CHECK: agfi %r4, -524292
149 ; CHECK: dl %r2, 0(%r4)
151 %ptr = getelementptr i32, ptr %src, i64 -131073
152 %b = load i32, ptr %ptr
153 %rem = urem i32 %a, %b
157 ; Check that DL allows an index.
158 define i32 @f12(i32 %dummy, i32 %a, i64 %src, i64 %index) {
160 ; CHECK: dl %r2, 524287(%r5,%r4)
162 %add1 = add i64 %src, %index
163 %add2 = add i64 %add1, 524287
164 %ptr = inttoptr i64 %add2 to ptr
165 %b = load i32, ptr %ptr
166 %rem = urem i32 %a, %b
170 ; Check that divisions of spilled values can use DL rather than DLR.
171 define i32 @f13(ptr %ptr0) {
173 ; CHECK: brasl %r14, foo@PLT
174 ; CHECK: dl {{%r[0-9]+}}, 16{{[04]}}(%r15)
176 %ptr1 = getelementptr i32, ptr %ptr0, i64 2
177 %ptr2 = getelementptr i32, ptr %ptr0, i64 4
178 %ptr3 = getelementptr i32, ptr %ptr0, i64 6
179 %ptr4 = getelementptr i32, ptr %ptr0, i64 8
180 %ptr5 = getelementptr i32, ptr %ptr0, i64 10
181 %ptr6 = getelementptr i32, ptr %ptr0, i64 12
182 %ptr7 = getelementptr i32, ptr %ptr0, i64 14
183 %ptr8 = getelementptr i32, ptr %ptr0, i64 16
184 %ptr9 = getelementptr i32, ptr %ptr0, i64 18
186 %val0 = load i32, ptr %ptr0
187 %val1 = load i32, ptr %ptr1
188 %val2 = load i32, ptr %ptr2
189 %val3 = load i32, ptr %ptr3
190 %val4 = load i32, ptr %ptr4
191 %val5 = load i32, ptr %ptr5
192 %val6 = load i32, ptr %ptr6
193 %val7 = load i32, ptr %ptr7
194 %val8 = load i32, ptr %ptr8
195 %val9 = load i32, ptr %ptr9
197 %ret = call i32 @foo()
199 %div0 = udiv i32 %ret, %val0
200 %div1 = udiv i32 %div0, %val1
201 %div2 = udiv i32 %div1, %val2
202 %div3 = udiv i32 %div2, %val3
203 %div4 = udiv i32 %div3, %val4
204 %div5 = udiv i32 %div4, %val5
205 %div6 = udiv i32 %div5, %val6
206 %div7 = udiv i32 %div6, %val7
207 %div8 = udiv i32 %div7, %val8
208 %div9 = udiv i32 %div8, %val9