1; RUN: llc -mtriple=powerpc64-unknown-linux-gnu -mcpu=pwr7 < %s | FileCheck %s
2; RUN: llc -mtriple=powerpc64-unknown-linux-gnu -mcpu=pwr7 -disable-fp-elim < %s | FileCheck -check-prefix=CHECK-FP %s
3target datalayout = "E-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-f128:128:128-v128:128:128-n32:64"
4target triple = "powerpc64-unknown-linux-gnu"
5
6%struct.s = type { i32, i32 }
7
8declare void @bar(i32*)
9
10define void @goo(%struct.s* byval nocapture readonly %a) {
11entry:
12  %x = alloca [2 x i32], align 32
13  %a1 = getelementptr inbounds %struct.s* %a, i64 0, i32 0
14  %0 = load i32* %a1, align 4
15  %arrayidx = getelementptr inbounds [2 x i32]* %x, i64 0, i64 0
16  store i32 %0, i32* %arrayidx, align 32
17  %b = getelementptr inbounds %struct.s* %a, i64 0, i32 1
18  %1 = load i32* %b, align 4
19  %arrayidx2 = getelementptr inbounds [2 x i32]* %x, i64 0, i64 1
20  store i32 %1, i32* %arrayidx2, align 4
21  call void @bar(i32* %arrayidx)
22  ret void
23}
24
25; CHECK-LABEL: @goo
26
27; CHECK-DAG: mflr 0
28; CHECK-DAG: rldicl [[REG:[0-9]+]], 1, 0, 59
29; CHECK-DAG: std 30, -16(1)
30; CHECK-DAG: mr 30, 1
31; CHECK-DAG: std 0, 16(1)
32; CHECK-DAG: subfic 0, [[REG]], -160
33; CHECK: stdux 1, 1, 0
34
35; CHECK: .cfi_offset r30, -16
36; CHECK: .cfi_offset lr, 16
37
38; CHECK: std 3, 48(30)
39
40; CHECK: ld 1, 0(1)
41; CHECK-DAG: ld 0, 16(1)
42; CHECK-DAG: ld 30, -16(1)
43; CHECK-DAG: mtlr 0
44; CHECK: blr
45
46; CHECK-FP-LABEL: @goo
47
48; CHECK-FP-DAG: mflr 0
49; CHECK-FP-DAG: rldicl [[REG:[0-9]+]], 1, 0, 59
50; CHECK-FP-DAG: std 31, -8(1)
51; CHECK-FP-DAG: std 30, -16(1)
52; CHECK-FP-DAG: mr 30, 1
53; CHECK-FP-DAG: std 0, 16(1)
54; CHECK-FP-DAG: subfic 0, [[REG]], -160
55; CHECK-FP: stdux 1, 1, 0
56
57; CHECK-FP: .cfi_offset r31, -8
58; CHECK-FP: .cfi_offset r30, -16
59; CHECK-FP: .cfi_offset lr, 16
60
61; CHECK-FP: mr 31, 1
62
63; CHECK-FP: std 3, 48(30)
64
65; CHECK-FP: ld 1, 0(1)
66; CHECK-FP-DAG: ld 0, 16(1)
67; CHECK-FP-DAG: ld 31, -8(1)
68; CHECK-FP-DAG: ld 30, -16(1)
69; CHECK-FP-DAG: mtlr 0
70; CHECK-FP: blr
71
72; The large-frame-size case.
73define void @hoo(%struct.s* byval nocapture readonly %a) {
74entry:
75  %x = alloca [200000 x i32], align 32
76  %a1 = getelementptr inbounds %struct.s* %a, i64 0, i32 0
77  %0 = load i32* %a1, align 4
78  %arrayidx = getelementptr inbounds [200000 x i32]* %x, i64 0, i64 0
79  store i32 %0, i32* %arrayidx, align 32
80  %b = getelementptr inbounds %struct.s* %a, i64 0, i32 1
81  %1 = load i32* %b, align 4
82  %arrayidx2 = getelementptr inbounds [200000 x i32]* %x, i64 0, i64 1
83  store i32 %1, i32* %arrayidx2, align 4
84  call void @bar(i32* %arrayidx)
85  ret void
86}
87
88; CHECK-LABEL: @hoo
89
90; CHECK-DAG: lis [[REG1:[0-9]+]], -13
91; CHECK-DAG: rldicl [[REG3:[0-9]+]], 1, 0, 59
92; CHECK-DAG: mflr 0
93; CHECK-DAG: ori [[REG2:[0-9]+]], [[REG1]], 51808
94; CHECK-DAG: std 30, -16(1)
95; CHECK-DAG: mr 30, 1
96; CHECK-DAG: std 0, 16(1)
97; CHECK-DAG: subfc 0, [[REG3]], [[REG2]]
98; CHECK: stdux 1, 1, 0
99
100; CHECK: blr
101
102; Make sure that the FP save area is still allocated correctly relative to
103; where r30 is saved.
104define void @loo(%struct.s* byval nocapture readonly %a) {
105entry:
106  %x = alloca [2 x i32], align 32
107  %a1 = getelementptr inbounds %struct.s* %a, i64 0, i32 0
108  %0 = load i32* %a1, align 4
109  %arrayidx = getelementptr inbounds [2 x i32]* %x, i64 0, i64 0
110  store i32 %0, i32* %arrayidx, align 32
111  %b = getelementptr inbounds %struct.s* %a, i64 0, i32 1
112  %1 = load i32* %b, align 4
113  %arrayidx2 = getelementptr inbounds [2 x i32]* %x, i64 0, i64 1
114  store i32 %1, i32* %arrayidx2, align 4
115  call void @bar(i32* %arrayidx)
116  call void asm sideeffect "", "~{f30}"() nounwind
117  ret void
118}
119
120; CHECK-LABEL: @loo
121
122; CHECK-DAG: mflr 0
123; CHECK-DAG: rldicl [[REG:[0-9]+]], 1, 0, 59
124; CHECK-DAG: std 30, -32(1)
125; CHECK-DAG: mr 30, 1
126; CHECK-DAG: std 0, 16(1)
127; CHECK-DAG: subfic 0, [[REG]], -192
128; CHECK: stdux 1, 1, 0
129
130; CHECK: stfd 30, -16(30)
131
132; CHECK: blr
133
134; CHECK-FP-LABEL: @loo
135
136; CHECK-FP-DAG: mflr 0
137; CHECK-FP-DAG: rldicl [[REG:[0-9]+]], 1, 0, 59
138; CHECK-FP-DAG: std 31, -24(1)
139; CHECK-FP-DAG: std 30, -32(1)
140; CHECK-FP-DAG: mr 30, 1
141; CHECK-FP-DAG: std 0, 16(1)
142; CHECK-FP-DAG: subfic 0, [[REG]], -192
143; CHECK-FP: stdux 1, 1, 0
144
145; CHECK-FP: stfd 30, -16(30)
146
147; CHECK-FP: blr
148