1 ; Test 64-bit signed division and remainder when the divisor is
2 ; a signed-extended i32.
4 ; RUN: llc < %s -mtriple=s390x-linux-gnu -asm-verbose=0 | FileCheck %s
8 ; Test register division. The result is in the second of the two registers.
9 define void @f1(i64 %dummy, i64 %a, i32 %b, i64 *%dest) {
11 ; CHECK-NOT: {{%r[234]}}
12 ; CHECK: dsgfr %r2, %r4
13 ; CHECK: stg %r3, 0(%r5)
15 %bext = sext i32 %b to i64
16 %div = sdiv i64 %a, %bext
17 store i64 %div, i64 *%dest
21 ; Test register remainder. The result is in the first of the two registers.
22 define void @f2(i64 %dummy, i64 %a, i32 %b, i64 *%dest) {
24 ; CHECK-NOT: {{%r[234]}}
25 ; CHECK: dsgfr %r2, %r4
26 ; CHECK: stg %r2, 0(%r5)
28 %bext = sext i32 %b to i64
29 %rem = srem i64 %a, %bext
30 store i64 %rem, i64 *%dest
34 ; Test that division and remainder use a single instruction.
35 define i64 @f3(i64 %dummy, i64 %a, i32 %b) {
37 ; CHECK-NOT: {{%r[234]}}
38 ; CHECK: dsgfr %r2, %r4
42 %bext = sext i32 %b to i64
43 %div = sdiv i64 %a, %bext
44 %rem = srem i64 %a, %bext
45 %or = or i64 %rem, %div
49 ; Test register division when the dividend is zero rather than sign extended.
50 ; We can't use dsgfr here
51 define void @f4(i64 %dummy, i64 %a, i32 %b, i64 *%dest) {
55 %bext = zext i32 %b to i64
56 %div = sdiv i64 %a, %bext
57 store i64 %div, i64 *%dest
61 ; ...likewise remainder.
62 define void @f5(i64 %dummy, i64 %a, i32 %b, i64 *%dest) {
66 %bext = zext i32 %b to i64
67 %rem = srem i64 %a, %bext
68 store i64 %rem, i64 *%dest
72 ; Test memory division with no displacement.
73 define void @f6(i64 %dummy, i64 %a, i32 *%src, i64 *%dest) {
75 ; CHECK-NOT: {{%r[234]}}
76 ; CHECK: dsgf %r2, 0(%r4)
77 ; CHECK: stg %r3, 0(%r5)
79 %b = load i32, i32 *%src
80 %bext = sext i32 %b to i64
81 %div = sdiv i64 %a, %bext
82 store i64 %div, i64 *%dest
86 ; Test memory remainder with no displacement.
87 define void @f7(i64 %dummy, i64 %a, i32 *%src, i64 *%dest) {
89 ; CHECK-NOT: {{%r[234]}}
90 ; CHECK: dsgf %r2, 0(%r4)
91 ; CHECK: stg %r2, 0(%r5)
93 %b = load i32, i32 *%src
94 %bext = sext i32 %b to i64
95 %rem = srem i64 %a, %bext
96 store i64 %rem, i64 *%dest
100 ; Test both memory division and memory remainder.
101 define i64 @f8(i64 %dummy, i64 %a, i32 *%src) {
103 ; CHECK-NOT: {{%r[234]}}
104 ; CHECK: dsgf %r2, 0(%r4)
105 ; CHECK-NOT: {{dsgf|dsgfr}}
106 ; CHECK: ogr %r3, %r2
107 ; CHECK: lgr %r2, %r3
109 %b = load i32, i32 *%src
110 %bext = sext i32 %b to i64
111 %div = sdiv i64 %a, %bext
112 %rem = srem i64 %a, %bext
113 %or = or i64 %rem, %div
117 ; Check the high end of the DSGF range.
118 define i64 @f9(i64 %dummy, i64 %a, i32 *%src) {
120 ; CHECK: dsgf %r2, 524284(%r4)
122 %ptr = getelementptr i32, i32 *%src, i64 131071
123 %b = load i32, i32 *%ptr
124 %bext = sext i32 %b to i64
125 %rem = srem i64 %a, %bext
129 ; Check the next word up, which needs separate address logic.
130 ; Other sequences besides this one would be OK.
131 define i64 @f10(i64 %dummy, i64 %a, i32 *%src) {
133 ; CHECK: agfi %r4, 524288
134 ; CHECK: dsgf %r2, 0(%r4)
136 %ptr = getelementptr i32, i32 *%src, i64 131072
137 %b = load i32, i32 *%ptr
138 %bext = sext i32 %b to i64
139 %rem = srem i64 %a, %bext
143 ; Check the high end of the negative aligned DSGF range.
144 define i64 @f11(i64 %dummy, i64 %a, i32 *%src) {
146 ; CHECK: dsgf %r2, -4(%r4)
148 %ptr = getelementptr i32, i32 *%src, i64 -1
149 %b = load i32, i32 *%ptr
150 %bext = sext i32 %b to i64
151 %rem = srem i64 %a, %bext
155 ; Check the low end of the DSGF range.
156 define i64 @f12(i64 %dummy, i64 %a, i32 *%src) {
158 ; CHECK: dsgf %r2, -524288(%r4)
160 %ptr = getelementptr i32, i32 *%src, i64 -131072
161 %b = load i32, i32 *%ptr
162 %bext = sext i32 %b to i64
163 %rem = srem i64 %a, %bext
167 ; Check the next word down, which needs separate address logic.
168 ; Other sequences besides this one would be OK.
169 define i64 @f13(i64 %dummy, i64 %a, i32 *%src) {
171 ; CHECK: agfi %r4, -524292
172 ; CHECK: dsgf %r2, 0(%r4)
174 %ptr = getelementptr i32, i32 *%src, i64 -131073
175 %b = load i32, i32 *%ptr
176 %bext = sext i32 %b to i64
177 %rem = srem i64 %a, %bext
181 ; Check that DSGF allows an index.
182 define i64 @f14(i64 %dummy, i64 %a, i64 %src, i64 %index) {
184 ; CHECK: dsgf %r2, 524287(%r5,%r4)
186 %add1 = add i64 %src, %index
187 %add2 = add i64 %add1, 524287
188 %ptr = inttoptr i64 %add2 to i32 *
189 %b = load i32, i32 *%ptr
190 %bext = sext i32 %b to i64
191 %rem = srem i64 %a, %bext
195 ; Make sure that we still use DSGFR rather than DSGR in cases where
196 ; a load and division cannot be combined.
197 define void @f15(i64 *%dest, i32 *%src) {
199 ; CHECK: l [[B:%r[0-9]+]], 0(%r3)
200 ; CHECK: brasl %r14, foo@PLT
201 ; CHECK: lgr %r1, %r2
202 ; CHECK: dsgfr %r0, [[B]]
204 %b = load i32, i32 *%src
206 %ext = sext i32 %b to i64
207 %div = sdiv i64 %a, %ext
208 store i64 %div, i64 *%dest