• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; 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
6declare void @foo(i32 *)
7
8; The CFA offset is 160 (the caller-allocated part of the frame) + 168.
9define void @f1(i64 %x) {
10; CHECK-LABEL: f1:
11; 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
23; two emergency spill slots at 160(%r15), for instructions with unsigned
24; 12-bit offsets that end up being out of range.  Fill the remaining
25; 32760 - 176 bytes by allocating (32760 - 176) / 8 = 4073 doublewords.
26define void @f2(i64 %x) {
27; CHECK-LABEL: f2:
28; CHECK: aghi %r15, -32760
29; CHECK: .cfi_def_cfa_offset 32920
30; CHECK: stg %r2, 176(%r15)
31; CHECK: aghi %r15, 32760
32; CHECK: br %r14
33  %y = alloca [4073 x i64], align 8
34  %ptr = getelementptr inbounds [4073 x i64], [4073 x i64]* %y, i64 0, i64 0
35  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) {
42; CHECK-LABEL: f3:
43; CHECK: aghi %r15, -32768
44; CHECK: .cfi_def_cfa_offset 32928
45; CHECK: stg %r2, 176(%r15)
46; CHECK: agfi %r15, 32768
47; CHECK: br %r14
48  %y = alloca [4074 x i64], align 8
49  %ptr = getelementptr inbounds [4074 x i64], [4074 x i64]* %y, i64 0, i64 0
50  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) {
57; CHECK-LABEL: f4:
58; CHECK: agfi %r15, -32776
59; CHECK: .cfi_def_cfa_offset 32936
60; CHECK: stg %r2, 176(%r15)
61; CHECK: agfi %r15, 32776
62; CHECK: br %r14
63  %y = alloca [4075 x i64], align 8
64  %ptr = getelementptr inbounds [4075 x i64], [4075 x i64]* %y, i64 0, i64 0
65  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) {
72; CHECK-LABEL: f5:
73; CHECK: agfi %r15, -2147483640
74; CHECK: stg %r2, 176(%r15)
75; CHECK: agfi %r15, 2147483640
76; CHECK: br %r14
77  %y = alloca [268435433 x i64], align 8
78  %ptr = getelementptr inbounds [268435433 x i64], [268435433 x i64]* %y, i64 0, i64 0
79  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) {
86; CHECK-LABEL: f6:
87; CHECK: agfi %r15, -2147483648
88; CHECK: stg %r2, 176(%r15)
89; CHECK: agfi %r15, 2147483640
90; CHECK: aghi %r15, 8
91; CHECK: br %r14
92  %y = alloca [268435434 x i64], align 8
93  %ptr = getelementptr inbounds [268435434 x i64], [268435434 x i64]* %y, i64 0, i64 0
94  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) {
101; CHECK-LABEL: f7:
102; CHECK: agfi %r15, -2147483648
103; CHECK: aghi %r15, -8
104; CHECK: stg %r2, 176(%r15)
105; CHECK: agfi %r15, 2147483640
106; CHECK: aghi %r15, 16
107; CHECK: br %r14
108  %y = alloca [268435435 x i64], align 8
109  %ptr = getelementptr inbounds [268435435 x i64], [268435435 x i64]* %y, i64 0, i64 0
110  store volatile i64 %x, i64* %ptr
111  ret void
112}
113
114; Make sure that LA can be rematerialized.
115define void @f8() {
116; CHECK-LABEL: f8:
117; 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}
127