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