blob: f61836ca8552b6e46d393fd69d816a4f9b215090 [file] [log] [blame]
Ulrich Weigand9e3577f2013-05-06 16:17:29 +00001; Test the allocation of frames in cases where we do not need to save
2; registers in the prologue.
3;
4; RUN: llc < %s -mtriple=s390x-linux-gnu | FileCheck %s
5
Richard Sandiford891a7e72013-06-27 09:42:10 +00006declare void @foo(i32 *)
7
Ulrich Weigand9e3577f2013-05-06 16:17:29 +00008; The CFA offset is 160 (the caller-allocated part of the frame) + 168.
9define void @f1(i64 %x) {
Stephen Lind24ab202013-07-14 06:24:09 +000010; CHECK-LABEL: f1:
Ulrich Weigand9e3577f2013-05-06 16:17:29 +000011; CHECK: aghi %r15, -168
12; CHECK: .cfi_def_cfa_offset 328
13; CHECK: stg %r2, 160(%r15)
14; CHECK: aghi %r15, 168
15; CHECK: br %r14
16 %y = alloca i64, align 8
17 store volatile i64 %x, i64* %y
18 ret void
19}
20
21; Check frames of size 32760, which is the largest size that can be both
22; allocated and freed using AGHI. This size is big enough to require
Richard Sandiford23943222013-07-05 13:11:52 +000023; two emergency spill slots at 160(%r15), for instructions with unsigned
Ulrich Weigand9e3577f2013-05-06 16:17:29 +000024; 12-bit offsets that end up being out of range. Fill the remaining
Richard Sandiford23943222013-07-05 13:11:52 +000025; 32760 - 176 bytes by allocating (32760 - 176) / 8 = 4073 doublewords.
Ulrich Weigand9e3577f2013-05-06 16:17:29 +000026define void @f2(i64 %x) {
Stephen Lind24ab202013-07-14 06:24:09 +000027; CHECK-LABEL: f2:
Ulrich Weigand9e3577f2013-05-06 16:17:29 +000028; CHECK: aghi %r15, -32760
29; CHECK: .cfi_def_cfa_offset 32920
Richard Sandiford23943222013-07-05 13:11:52 +000030; CHECK: stg %r2, 176(%r15)
Ulrich Weigand9e3577f2013-05-06 16:17:29 +000031; CHECK: aghi %r15, 32760
32; CHECK: br %r14
Richard Sandiford23943222013-07-05 13:11:52 +000033 %y = alloca [4073 x i64], align 8
34 %ptr = getelementptr inbounds [4073 x i64]* %y, i64 0, i64 0
Ulrich Weigand9e3577f2013-05-06 16:17:29 +000035 store volatile i64 %x, i64* %ptr
36 ret void
37}
38
39; Allocate one more doubleword. This is the one frame size that we can
40; allocate using AGHI but must free using AGFI.
41define void @f3(i64 %x) {
Stephen Lind24ab202013-07-14 06:24:09 +000042; CHECK-LABEL: f3:
Ulrich Weigand9e3577f2013-05-06 16:17:29 +000043; CHECK: aghi %r15, -32768
44; CHECK: .cfi_def_cfa_offset 32928
Richard Sandiford23943222013-07-05 13:11:52 +000045; CHECK: stg %r2, 176(%r15)
Ulrich Weigand9e3577f2013-05-06 16:17:29 +000046; CHECK: agfi %r15, 32768
47; CHECK: br %r14
Richard Sandiford23943222013-07-05 13:11:52 +000048 %y = alloca [4074 x i64], align 8
49 %ptr = getelementptr inbounds [4074 x i64]* %y, i64 0, i64 0
Ulrich Weigand9e3577f2013-05-06 16:17:29 +000050 store volatile i64 %x, i64* %ptr
51 ret void
52}
53
54; Allocate another doubleword on top of that. The allocation and free
55; must both use AGFI.
56define void @f4(i64 %x) {
Stephen Lind24ab202013-07-14 06:24:09 +000057; CHECK-LABEL: f4:
Ulrich Weigand9e3577f2013-05-06 16:17:29 +000058; CHECK: agfi %r15, -32776
59; CHECK: .cfi_def_cfa_offset 32936
Richard Sandiford23943222013-07-05 13:11:52 +000060; CHECK: stg %r2, 176(%r15)
Ulrich Weigand9e3577f2013-05-06 16:17:29 +000061; CHECK: agfi %r15, 32776
62; CHECK: br %r14
Richard Sandiford23943222013-07-05 13:11:52 +000063 %y = alloca [4075 x i64], align 8
64 %ptr = getelementptr inbounds [4075 x i64]* %y, i64 0, i64 0
Ulrich Weigand9e3577f2013-05-06 16:17:29 +000065 store volatile i64 %x, i64* %ptr
66 ret void
67}
68
69; The largest size that can be both allocated and freed using AGFI.
70; At this point the frame is too big to represent properly in the CFI.
71define void @f5(i64 %x) {
Stephen Lind24ab202013-07-14 06:24:09 +000072; CHECK-LABEL: f5:
Ulrich Weigand9e3577f2013-05-06 16:17:29 +000073; CHECK: agfi %r15, -2147483640
Richard Sandiford23943222013-07-05 13:11:52 +000074; CHECK: stg %r2, 176(%r15)
Ulrich Weigand9e3577f2013-05-06 16:17:29 +000075; CHECK: agfi %r15, 2147483640
76; CHECK: br %r14
Richard Sandiford23943222013-07-05 13:11:52 +000077 %y = alloca [268435433 x i64], align 8
78 %ptr = getelementptr inbounds [268435433 x i64]* %y, i64 0, i64 0
Ulrich Weigand9e3577f2013-05-06 16:17:29 +000079 store volatile i64 %x, i64* %ptr
80 ret void
81}
82
83; The only frame size that can be allocated using a single AGFI but which
84; must be freed using two instructions.
85define void @f6(i64 %x) {
Stephen Lind24ab202013-07-14 06:24:09 +000086; CHECK-LABEL: f6:
Ulrich Weigand9e3577f2013-05-06 16:17:29 +000087; CHECK: agfi %r15, -2147483648
Richard Sandiford23943222013-07-05 13:11:52 +000088; CHECK: stg %r2, 176(%r15)
Ulrich Weigand9e3577f2013-05-06 16:17:29 +000089; CHECK: agfi %r15, 2147483640
90; CHECK: aghi %r15, 8
91; CHECK: br %r14
Richard Sandiford23943222013-07-05 13:11:52 +000092 %y = alloca [268435434 x i64], align 8
93 %ptr = getelementptr inbounds [268435434 x i64]* %y, i64 0, i64 0
Ulrich Weigand9e3577f2013-05-06 16:17:29 +000094 store volatile i64 %x, i64* %ptr
95 ret void
96}
97
98; The smallest frame size that needs two instructions to both allocate
99; and free the frame.
100define void @f7(i64 %x) {
Stephen Lind24ab202013-07-14 06:24:09 +0000101; CHECK-LABEL: f7:
Ulrich Weigand9e3577f2013-05-06 16:17:29 +0000102; CHECK: agfi %r15, -2147483648
103; CHECK: aghi %r15, -8
Richard Sandiford23943222013-07-05 13:11:52 +0000104; CHECK: stg %r2, 176(%r15)
Ulrich Weigand9e3577f2013-05-06 16:17:29 +0000105; CHECK: agfi %r15, 2147483640
106; CHECK: aghi %r15, 16
107; CHECK: br %r14
Richard Sandiford23943222013-07-05 13:11:52 +0000108 %y = alloca [268435435 x i64], align 8
109 %ptr = getelementptr inbounds [268435435 x i64]* %y, i64 0, i64 0
Ulrich Weigand9e3577f2013-05-06 16:17:29 +0000110 store volatile i64 %x, i64* %ptr
111 ret void
112}
Richard Sandiford891a7e72013-06-27 09:42:10 +0000113
114; Make sure that LA can be rematerialized.
115define void @f8() {
Stephen Lind24ab202013-07-14 06:24:09 +0000116; CHECK-LABEL: f8:
Richard Sandiford891a7e72013-06-27 09:42:10 +0000117; CHECK: la %r2, 164(%r15)
118; CHECK: brasl %r14, foo@PLT
119; CHECK: la %r2, 164(%r15)
120; CHECK: brasl %r14, foo@PLT
121; CHECK: br %r14
122 %ptr = alloca i32
123 call void @foo(i32 *%ptr)
124 call void @foo(i32 *%ptr)
125 ret void
126}