blob: 29fab98604ee8fbdf6fee69a7dfd88aad877197e [file] [log] [blame]
Ulrich Weigand9e3577f2013-05-06 16:17:29 +00001; Test the handling of base + displacement addresses for large frames,
2; in cases where both 12-bit and 20-bit displacements are allowed.
3;
4; RUN: llc < %s -mtriple=s390x-linux-gnu | FileCheck -check-prefix=CHECK-NOFP %s
5; RUN: llc < %s -mtriple=s390x-linux-gnu -disable-fp-elim | FileCheck -check-prefix=CHECK-FP %s
6
7; This file tests what happens when a displacement is converted from
8; being relative to the start of a frame object to being relative to
9; the frame itself. In some cases the test is only possible if two
10; objects are allocated.
11;
12; Rather than rely on a particular order for those objects, the tests
13; instead allocate two objects of the same size and apply the test to
14; both of them. For consistency, all tests follow this model, even if
15; one object would actually be enough.
16
17; First check the highest offset that is in range of the 12-bit form.
18;
Richard Sandiford23943222013-07-05 13:11:52 +000019; The last in-range doubleword offset is 4088. Since the frame has two
20; emergency spill slots at 160(%r15), the amount that we need to allocate
21; in order to put another object at offset 4088 is 4088 - 176 = 3912 bytes.
Ulrich Weigand9e3577f2013-05-06 16:17:29 +000022define void @f1() {
23; CHECK-NOFP: f1:
24; CHECK-NOFP: mvi 4095(%r15), 42
25; CHECK-NOFP: br %r14
26;
27; CHECK-FP: f1:
28; CHECK-FP: mvi 4095(%r11), 42
29; CHECK-FP: br %r14
Richard Sandiford23943222013-07-05 13:11:52 +000030 %region1 = alloca [3912 x i8], align 8
31 %region2 = alloca [3912 x i8], align 8
32 %ptr1 = getelementptr inbounds [3912 x i8]* %region1, i64 0, i64 7
33 %ptr2 = getelementptr inbounds [3912 x i8]* %region2, i64 0, i64 7
Ulrich Weigand9e3577f2013-05-06 16:17:29 +000034 store volatile i8 42, i8 *%ptr1
35 store volatile i8 42, i8 *%ptr2
36 ret void
37}
38
39; Test the first offset that is out-of-range of the 12-bit form.
40define void @f2() {
41; CHECK-NOFP: f2:
42; CHECK-NOFP: mviy 4096(%r15), 42
43; CHECK-NOFP: br %r14
44;
45; CHECK-FP: f2:
46; CHECK-FP: mviy 4096(%r11), 42
47; CHECK-FP: br %r14
Richard Sandiford23943222013-07-05 13:11:52 +000048 %region1 = alloca [3912 x i8], align 8
49 %region2 = alloca [3912 x i8], align 8
50 %ptr1 = getelementptr inbounds [3912 x i8]* %region1, i64 0, i64 8
51 %ptr2 = getelementptr inbounds [3912 x i8]* %region2, i64 0, i64 8
Ulrich Weigand9e3577f2013-05-06 16:17:29 +000052 store volatile i8 42, i8 *%ptr1
53 store volatile i8 42, i8 *%ptr2
54 ret void
55}
56
57; Test the last offset that is in range of the 20-bit form.
58;
59; The last in-range doubleword offset is 524280, so by the same reasoning
Richard Sandiford23943222013-07-05 13:11:52 +000060; as above, we need to allocate objects of 524280 - 176 = 524104 bytes.
Ulrich Weigand9e3577f2013-05-06 16:17:29 +000061define void @f3() {
62; CHECK-NOFP: f3:
63; CHECK-NOFP: mviy 524287(%r15), 42
64; CHECK-NOFP: br %r14
65;
66; CHECK-FP: f3:
67; CHECK-FP: mviy 524287(%r11), 42
68; CHECK-FP: br %r14
Richard Sandiford23943222013-07-05 13:11:52 +000069 %region1 = alloca [524104 x i8], align 8
70 %region2 = alloca [524104 x i8], align 8
71 %ptr1 = getelementptr inbounds [524104 x i8]* %region1, i64 0, i64 7
72 %ptr2 = getelementptr inbounds [524104 x i8]* %region2, i64 0, i64 7
Ulrich Weigand9e3577f2013-05-06 16:17:29 +000073 store volatile i8 42, i8 *%ptr1
74 store volatile i8 42, i8 *%ptr2
75 ret void
76}
77
78; Test the first out-of-range offset. We can't use an index register here,
79; and the offset is also out of LAY's range, so expect a constant load
80; followed by an addition.
81define void @f4() {
82; CHECK-NOFP: f4:
83; CHECK-NOFP: llilh %r1, 8
84; CHECK-NOFP: agr %r1, %r15
85; CHECK-NOFP: mvi 0(%r1), 42
86; CHECK-NOFP: br %r14
87;
88; CHECK-FP: f4:
89; CHECK-FP: llilh %r1, 8
90; CHECK-FP: agr %r1, %r11
91; CHECK-FP: mvi 0(%r1), 42
92; CHECK-FP: br %r14
Richard Sandiford23943222013-07-05 13:11:52 +000093 %region1 = alloca [524104 x i8], align 8
94 %region2 = alloca [524104 x i8], align 8
95 %ptr1 = getelementptr inbounds [524104 x i8]* %region1, i64 0, i64 8
96 %ptr2 = getelementptr inbounds [524104 x i8]* %region2, i64 0, i64 8
Ulrich Weigand9e3577f2013-05-06 16:17:29 +000097 store volatile i8 42, i8 *%ptr1
98 store volatile i8 42, i8 *%ptr2
99 ret void
100}
101
102; Add 4095 to the previous offset, to test the other end of the MVI range.
103; The instruction will actually be STCY before frame lowering.
104define void @f5() {
105; CHECK-NOFP: f5:
106; CHECK-NOFP: llilh %r1, 8
107; CHECK-NOFP: agr %r1, %r15
108; CHECK-NOFP: mvi 4095(%r1), 42
109; CHECK-NOFP: br %r14
110;
111; CHECK-FP: f5:
112; CHECK-FP: llilh %r1, 8
113; CHECK-FP: agr %r1, %r11
114; CHECK-FP: mvi 4095(%r1), 42
115; CHECK-FP: br %r14
Richard Sandiford23943222013-07-05 13:11:52 +0000116 %region1 = alloca [524104 x i8], align 8
117 %region2 = alloca [524104 x i8], align 8
118 %ptr1 = getelementptr inbounds [524104 x i8]* %region1, i64 0, i64 4103
119 %ptr2 = getelementptr inbounds [524104 x i8]* %region2, i64 0, i64 4103
Ulrich Weigand9e3577f2013-05-06 16:17:29 +0000120 store volatile i8 42, i8 *%ptr1
121 store volatile i8 42, i8 *%ptr2
122 ret void
123}
124
125; Test the next offset after that, which uses MVIY instead of MVI.
126define void @f6() {
127; CHECK-NOFP: f6:
128; CHECK-NOFP: llilh %r1, 8
129; CHECK-NOFP: agr %r1, %r15
130; CHECK-NOFP: mviy 4096(%r1), 42
131; CHECK-NOFP: br %r14
132;
133; CHECK-FP: f6:
134; CHECK-FP: llilh %r1, 8
135; CHECK-FP: agr %r1, %r11
136; CHECK-FP: mviy 4096(%r1), 42
137; CHECK-FP: br %r14
Richard Sandiford23943222013-07-05 13:11:52 +0000138 %region1 = alloca [524104 x i8], align 8
139 %region2 = alloca [524104 x i8], align 8
140 %ptr1 = getelementptr inbounds [524104 x i8]* %region1, i64 0, i64 4104
141 %ptr2 = getelementptr inbounds [524104 x i8]* %region2, i64 0, i64 4104
Ulrich Weigand9e3577f2013-05-06 16:17:29 +0000142 store volatile i8 42, i8 *%ptr1
143 store volatile i8 42, i8 *%ptr2
144 ret void
145}
146
147; Now try an offset of 524287 from the start of the object, with the
148; object being at offset 1048576 (1 << 20). The backend prefers to create
149; anchors 0x10000 bytes apart, so that the high part can be loaded using
150; LLILH while still using MVI in more cases than 0x40000 anchors would.
151define void @f7() {
152; CHECK-NOFP: f7:
153; CHECK-NOFP: llilh %r1, 23
154; CHECK-NOFP: agr %r1, %r15
155; CHECK-NOFP: mviy 65535(%r1), 42
156; CHECK-NOFP: br %r14
157;
158; CHECK-FP: f7:
159; CHECK-FP: llilh %r1, 23
160; CHECK-FP: agr %r1, %r11
161; CHECK-FP: mviy 65535(%r1), 42
162; CHECK-FP: br %r14
Richard Sandiford23943222013-07-05 13:11:52 +0000163 %region1 = alloca [1048400 x i8], align 8
164 %region2 = alloca [1048400 x i8], align 8
165 %ptr1 = getelementptr inbounds [1048400 x i8]* %region1, i64 0, i64 524287
166 %ptr2 = getelementptr inbounds [1048400 x i8]* %region2, i64 0, i64 524287
Ulrich Weigand9e3577f2013-05-06 16:17:29 +0000167 store volatile i8 42, i8 *%ptr1
168 store volatile i8 42, i8 *%ptr2
169 ret void
170}
171
172; Keep the object-relative offset the same but bump the size of the
173; objects by one doubleword.
174define void @f8() {
175; CHECK-NOFP: f8:
176; CHECK-NOFP: llilh %r1, 24
177; CHECK-NOFP: agr %r1, %r15
178; CHECK-NOFP: mvi 7(%r1), 42
179; CHECK-NOFP: br %r14
180;
181; CHECK-FP: f8:
182; CHECK-FP: llilh %r1, 24
183; CHECK-FP: agr %r1, %r11
184; CHECK-FP: mvi 7(%r1), 42
185; CHECK-FP: br %r14
Richard Sandiford23943222013-07-05 13:11:52 +0000186 %region1 = alloca [1048408 x i8], align 8
187 %region2 = alloca [1048408 x i8], align 8
188 %ptr1 = getelementptr inbounds [1048408 x i8]* %region1, i64 0, i64 524287
189 %ptr2 = getelementptr inbounds [1048408 x i8]* %region2, i64 0, i64 524287
Ulrich Weigand9e3577f2013-05-06 16:17:29 +0000190 store volatile i8 42, i8 *%ptr1
191 store volatile i8 42, i8 *%ptr2
192 ret void
193}
194
195; Check a case where the original displacement is out of range. The backend
196; should force separate address logic from the outset. We don't yet do any
197; kind of anchor optimization, so there should be no offset on the MVI itself.
198;
199; Before frame lowering this is an LA followed by the AGFI seen below.
200; The LA then gets lowered into the LLILH/LA form. The exact sequence
201; isn't that important though.
202define void @f9() {
203; CHECK-NOFP: f9:
204; CHECK-NOFP: llilh [[R1:%r[1-5]]], 16
205; CHECK-NOFP: la [[R2:%r[1-5]]], 8([[R1]],%r15)
206; CHECK-NOFP: agfi [[R2]], 524288
207; CHECK-NOFP: mvi 0([[R2]]), 42
208; CHECK-NOFP: br %r14
209;
210; CHECK-FP: f9:
211; CHECK-FP: llilh [[R1:%r[1-5]]], 16
212; CHECK-FP: la [[R2:%r[1-5]]], 8([[R1]],%r11)
213; CHECK-FP: agfi [[R2]], 524288
214; CHECK-FP: mvi 0([[R2]]), 42
215; CHECK-FP: br %r14
Richard Sandiford23943222013-07-05 13:11:52 +0000216 %region1 = alloca [1048408 x i8], align 8
217 %region2 = alloca [1048408 x i8], align 8
218 %ptr1 = getelementptr inbounds [1048408 x i8]* %region1, i64 0, i64 524288
219 %ptr2 = getelementptr inbounds [1048408 x i8]* %region2, i64 0, i64 524288
Ulrich Weigand9e3577f2013-05-06 16:17:29 +0000220 store volatile i8 42, i8 *%ptr1
221 store volatile i8 42, i8 *%ptr2
222 ret void
223}
224
Richard Sandiford23943222013-07-05 13:11:52 +0000225; Repeat f4 in a case that needs the emergency spill slots (because all
Ulrich Weigand9e3577f2013-05-06 16:17:29 +0000226; call-clobbered registers are live and no call-saved ones have been
227; allocated).
228define void @f10(i32 *%vptr) {
229; CHECK-NOFP: f10:
Richard Sandiford23943222013-07-05 13:11:52 +0000230; CHECK-NOFP: stg [[REGISTER:%r[1-9][0-4]?]], [[OFFSET:160|168]](%r15)
Ulrich Weigand9e3577f2013-05-06 16:17:29 +0000231; CHECK-NOFP: llilh [[REGISTER]], 8
232; CHECK-NOFP: agr [[REGISTER]], %r15
233; CHECK-NOFP: mvi 0([[REGISTER]]), 42
Richard Sandiford23943222013-07-05 13:11:52 +0000234; CHECK-NOFP: lg [[REGISTER]], [[OFFSET]](%r15)
Ulrich Weigand9e3577f2013-05-06 16:17:29 +0000235; CHECK-NOFP: br %r14
236;
237; CHECK-FP: f10:
Richard Sandiford23943222013-07-05 13:11:52 +0000238; CHECK-FP: stg [[REGISTER:%r[1-9][0-4]?]], [[OFFSET:160|168]](%r11)
Ulrich Weigand9e3577f2013-05-06 16:17:29 +0000239; CHECK-FP: llilh [[REGISTER]], 8
240; CHECK-FP: agr [[REGISTER]], %r11
241; CHECK-FP: mvi 0([[REGISTER]]), 42
Richard Sandiford23943222013-07-05 13:11:52 +0000242; CHECK-FP: lg [[REGISTER]], [[OFFSET]](%r11)
Ulrich Weigand9e3577f2013-05-06 16:17:29 +0000243; CHECK-FP: br %r14
244 %i0 = load volatile i32 *%vptr
245 %i1 = load volatile i32 *%vptr
246 %i3 = load volatile i32 *%vptr
247 %i4 = load volatile i32 *%vptr
248 %i5 = load volatile i32 *%vptr
Richard Sandiford23943222013-07-05 13:11:52 +0000249 %region1 = alloca [524104 x i8], align 8
250 %region2 = alloca [524104 x i8], align 8
251 %ptr1 = getelementptr inbounds [524104 x i8]* %region1, i64 0, i64 8
252 %ptr2 = getelementptr inbounds [524104 x i8]* %region2, i64 0, i64 8
Ulrich Weigand9e3577f2013-05-06 16:17:29 +0000253 store volatile i8 42, i8 *%ptr1
254 store volatile i8 42, i8 *%ptr2
255 store volatile i32 %i0, i32 *%vptr
256 store volatile i32 %i1, i32 *%vptr
257 store volatile i32 %i3, i32 *%vptr
258 store volatile i32 %i4, i32 *%vptr
259 store volatile i32 %i5, i32 *%vptr
260 ret void
261}
262
Richard Sandiford23943222013-07-05 13:11:52 +0000263; And again with maximum register pressure. The only spill slots that the
264; NOFP case needs are the emergency ones, so the offsets are the same as for f4.
Ulrich Weigand9e3577f2013-05-06 16:17:29 +0000265; However, the FP case uses %r11 as the frame pointer and must therefore
266; spill a second register. This leads to an extra displacement of 8.
267define void @f11(i32 *%vptr) {
268; CHECK-NOFP: f11:
269; CHECK-NOFP: stmg %r6, %r15,
Richard Sandiford23943222013-07-05 13:11:52 +0000270; CHECK-NOFP: stg [[REGISTER:%r[1-9][0-4]?]], [[OFFSET:160|168]](%r15)
Ulrich Weigand9e3577f2013-05-06 16:17:29 +0000271; CHECK-NOFP: llilh [[REGISTER]], 8
272; CHECK-NOFP: agr [[REGISTER]], %r15
273; CHECK-NOFP: mvi 0([[REGISTER]]), 42
Richard Sandiford23943222013-07-05 13:11:52 +0000274; CHECK-NOFP: lg [[REGISTER]], [[OFFSET]](%r15)
Ulrich Weigand9e3577f2013-05-06 16:17:29 +0000275; CHECK-NOFP: lmg %r6, %r15,
276; CHECK-NOFP: br %r14
277;
278; CHECK-FP: f11:
279; CHECK-FP: stmg %r6, %r15,
Richard Sandiford23943222013-07-05 13:11:52 +0000280; CHECK-FP: stg [[REGISTER:%r[1-9][0-4]?]], [[OFFSET:160|168]](%r11)
Ulrich Weigand9e3577f2013-05-06 16:17:29 +0000281; CHECK-FP: llilh [[REGISTER]], 8
282; CHECK-FP: agr [[REGISTER]], %r11
283; CHECK-FP: mvi 8([[REGISTER]]), 42
Richard Sandiford23943222013-07-05 13:11:52 +0000284; CHECK-FP: lg [[REGISTER]], [[OFFSET]](%r11)
Ulrich Weigand9e3577f2013-05-06 16:17:29 +0000285; CHECK-FP: lmg %r6, %r15,
286; CHECK-FP: br %r14
287 %i0 = load volatile i32 *%vptr
288 %i1 = load volatile i32 *%vptr
289 %i3 = load volatile i32 *%vptr
290 %i4 = load volatile i32 *%vptr
291 %i5 = load volatile i32 *%vptr
292 %i6 = load volatile i32 *%vptr
293 %i7 = load volatile i32 *%vptr
294 %i8 = load volatile i32 *%vptr
295 %i9 = load volatile i32 *%vptr
296 %i10 = load volatile i32 *%vptr
297 %i11 = load volatile i32 *%vptr
298 %i12 = load volatile i32 *%vptr
299 %i13 = load volatile i32 *%vptr
300 %i14 = load volatile i32 *%vptr
Richard Sandiford23943222013-07-05 13:11:52 +0000301 %region1 = alloca [524104 x i8], align 8
302 %region2 = alloca [524104 x i8], align 8
303 %ptr1 = getelementptr inbounds [524104 x i8]* %region1, i64 0, i64 8
304 %ptr2 = getelementptr inbounds [524104 x i8]* %region2, i64 0, i64 8
Ulrich Weigand9e3577f2013-05-06 16:17:29 +0000305 store volatile i8 42, i8 *%ptr1
306 store volatile i8 42, i8 *%ptr2
307 store volatile i32 %i0, i32 *%vptr
308 store volatile i32 %i1, i32 *%vptr
309 store volatile i32 %i3, i32 *%vptr
310 store volatile i32 %i4, i32 *%vptr
311 store volatile i32 %i5, i32 *%vptr
312 store volatile i32 %i6, i32 *%vptr
313 store volatile i32 %i7, i32 *%vptr
314 store volatile i32 %i8, i32 *%vptr
315 store volatile i32 %i9, i32 *%vptr
316 store volatile i32 %i10, i32 *%vptr
317 store volatile i32 %i11, i32 *%vptr
318 store volatile i32 %i12, i32 *%vptr
319 store volatile i32 %i13, i32 *%vptr
320 store volatile i32 %i14, i32 *%vptr
321 ret void
322}