1; RUN: llc -march=mipsel -relocation-model=pic  \
2; RUN:     -verify-machineinstrs -mips-tail-calls=1 < %s | FileCheck %s -check-prefix=PIC32
3; RUN: llc -march=mipsel -relocation-model=static  \
4; RUN:     -verify-machineinstrs -mips-tail-calls=1 < %s | FileCheck %s -check-prefix=STATIC32
5; RUN: llc -march=mips64el -mcpu=mips64r2  \
6; RUN:     -verify-machineinstrs -mips-tail-calls=1 < %s | FileCheck %s -check-prefix=N64
7; RUN: llc -march=mipsel -mattr=mips16 -relocation-model=pic \
8; RUN:      -verify-machineinstrs -mips-tail-calls=1 < %s | \
9; RUN:     FileCheck %s -check-prefix=PIC16
10
11; RUN: llc -march=mipsel -relocation-model=pic -mattr=+micromips -mips-tail-calls=1 < %s | \
12; RUN:     FileCheck %s -check-prefix=PIC32
13; RUN: llc -march=mipsel -relocation-model=static -mattr=+micromips \
14; RUN:     -mips-tail-calls=1 < %s | FileCheck %s -check-prefix=STATIC32
15
16; RUN: llc -march=mipsel -relocation-model=pic -mcpu=mips32r6 -mips-tail-calls=1 < %s | \
17; RUN:     FileCheck %s -check-prefix=PIC32
18; RUN: llc -march=mipsel -relocation-model=static -mcpu=mips32r6 \
19; RUN:     -mips-tail-calls=1 < %s | FileCheck %s -check-prefix=STATIC32
20; RUN: llc -march=mips64el -mcpu=mips64r6  \
21; RUN:     -mips-tail-calls=1 < %s | FileCheck %s -check-prefix=N64
22
23; RUN: llc -march=mipsel -relocation-model=pic -mcpu=mips32r6 -mattr=+micromips \
24; RUN:      -mips-tail-calls=1 < %s | FileCheck %s -check-prefix=PIC32
25; RUN: llc -march=mipsel -relocation-model=static -mcpu=mips32r6 \
26; RUN:     -mattr=+micromips -mips-tail-calls=1 < %s | FileCheck %s -check-prefix=STATIC32
27; RUN: llc -march=mips64el -mcpu=mips64r6 -mattr=+micromips -mips-tail-calls=1 < %s \
28; RUN:      | FileCheck %s -check-prefix=N64
29
30@g0 = common global i32 0, align 4
31@g1 = common global i32 0, align 4
32@g2 = common global i32 0, align 4
33@g3 = common global i32 0, align 4
34@g4 = common global i32 0, align 4
35@g5 = common global i32 0, align 4
36@g6 = common global i32 0, align 4
37@g7 = common global i32 0, align 4
38@g8 = common global i32 0, align 4
39@g9 = common global i32 0, align 4
40
41define i32 @caller1(i32 %a0) nounwind {
42entry:
43; PIC32-NOT: jalr
44; STATIC32-NOT: jal
45; N64-NOT: jalr
46; PIC16: jalrc
47
48  %call = tail call i32 @callee1(i32 1, i32 1, i32 1, i32 %a0) nounwind
49  ret i32 %call
50}
51
52declare i32 @callee1(i32, i32, i32, i32)
53
54define i32 @caller2(i32 %a0, i32 %a1, i32 %a2, i32 %a3) nounwind {
55entry:
56; PIC32: jalr
57; STATIC32: jal
58; N64-NOT: jalr
59; PIC16: jalrc
60
61  %call = tail call i32 @callee2(i32 1, i32 %a0, i32 %a1, i32 %a2, i32 %a3) nounwind
62  ret i32 %call
63}
64
65declare i32 @callee2(i32, i32, i32, i32, i32)
66
67define i32 @caller3(i32 %a0, i32 %a1, i32 %a2, i32 %a3, i32 %a4) nounwind {
68entry:
69; PIC32: jalr
70; STATIC32: jal
71; N64-NOT: jalr
72; PIC16: jalrc
73
74  %call = tail call i32 @callee3(i32 1, i32 1, i32 1, i32 %a0, i32 %a1, i32 %a2, i32 %a3, i32 %a4) nounwind
75  ret i32 %call
76}
77
78declare i32 @callee3(i32, i32, i32, i32, i32, i32, i32, i32)
79
80define i32 @caller4(i32 %a0, i32 %a1, i32 %a2, i32 %a3, i32 %a4, i32 %a5, i32 %a6, i32 %a7) nounwind {
81entry:
82; PIC32: jalr
83; STATIC32: jal
84; N64: jalr
85; PIC16: jalrc
86
87  %call = tail call i32 @callee4(i32 1, i32 %a0, i32 %a1, i32 %a2, i32 %a3, i32 %a4, i32 %a5, i32 %a6, i32 %a7) nounwind
88  ret i32 %call
89}
90
91declare i32 @callee4(i32, i32, i32, i32, i32, i32, i32, i32, i32)
92
93define i32 @caller5() nounwind readonly {
94entry:
95; PIC32: .ent caller5
96; PIC32-NOT: jalr $25
97; PIC32: .end caller5
98; STATIC32: .ent caller5
99; STATIC32-NOT: jal
100; STATIC32: .end caller5
101; N64: .ent caller5
102; N64-NOT: jalr $25
103; N64: .end caller5
104; PIC16: .ent caller5
105; PIC16: jalrc
106; PIC16: .end caller5
107
108  %0 = load i32, i32* @g0, align 4
109  %1 = load i32, i32* @g1, align 4
110  %2 = load i32, i32* @g2, align 4
111  %3 = load i32, i32* @g3, align 4
112  %4 = load i32, i32* @g4, align 4
113  %5 = load i32, i32* @g5, align 4
114  %6 = load i32, i32* @g6, align 4
115  %7 = load i32, i32* @g7, align 4
116  %8 = load i32, i32* @g8, align 4
117  %9 = load i32, i32* @g9, align 4
118  %call = tail call fastcc i32 @callee5(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5, i32 %6, i32 %7, i32 %8, i32 %9)
119  ret i32 %call
120}
121
122define internal fastcc i32 @callee5(i32 %a0, i32 %a1, i32 %a2, i32 %a3, i32 %a4, i32 %a5, i32 %a6, i32 %a7, i32 %a8, i32 %a9) nounwind readnone noinline {
123entry:
124  %add = add nsw i32 %a1, %a0
125  %add1 = add nsw i32 %add, %a2
126  %add2 = add nsw i32 %add1, %a3
127  %add3 = add nsw i32 %add2, %a4
128  %add4 = add nsw i32 %add3, %a5
129  %add5 = add nsw i32 %add4, %a6
130  %add6 = add nsw i32 %add5, %a7
131  %add7 = add nsw i32 %add6, %a8
132  %add8 = add nsw i32 %add7, %a9
133  ret i32 %add8
134}
135
136declare i32 @callee8(i32, ...)
137
138define i32 @caller8_0() nounwind {
139entry:
140; PIC32: .ent caller8_0
141; PIC32: jr
142; PIC32: .end caller8_0
143; STATIC32: .ent caller8_0
144; STATIC32: j
145; STATIC32: .end caller8_0
146; N64: .ent caller8_0
147; N64-NOT: jalr $25
148; N64: .end caller8_0
149; PIC16: .ent caller8_0
150; PIC16: jalrc
151; PIC16: .end caller8_0
152
153  %call = tail call fastcc i32 @caller8_1()
154  ret i32 %call
155}
156
157define internal fastcc i32 @caller8_1() nounwind noinline {
158entry:
159; PIC32: .ent caller8_1
160; PIC32: jalr
161; PIC32: .end caller8_1
162; STATIC32: .ent caller8_1
163; STATIC32: jal
164; STATIC32: .end caller8_1
165; N64: .ent caller8_1
166; N64-NOT: jalr $25
167; N64: .end caller8_1
168; PIC16: .ent caller8_1
169; PIC16: jalrc
170; PIC16: .end caller8_1
171
172  %call = tail call i32 (i32, ...) @callee8(i32 2, i32 1) nounwind
173  ret i32 %call
174}
175
176%struct.S = type { [2 x i32] }
177
178@gs1 = external global %struct.S
179
180declare i32 @callee9(%struct.S* byval)
181
182define i32 @caller9_0() nounwind {
183entry:
184; PIC32: .ent caller9_0
185; PIC32: jr
186; PIC32: .end caller9_0
187; STATIC32: .ent caller9_0
188; STATIC32: j
189; STATIC32: .end caller9_0
190; N64: .ent caller9_0
191; N64-NOT: jalr $25
192; N64: .end caller9_0
193; PIC16: .ent caller9_0
194; PIC16: jalrc
195; PIC16: .end caller9_0
196  %call = tail call fastcc i32 @caller9_1()
197  ret i32 %call
198}
199
200define internal fastcc i32 @caller9_1() nounwind noinline {
201entry:
202; PIC32: .ent caller9_1
203; PIC32: jalr
204; PIC32: .end caller9_1
205; STATIC32: .ent caller9_1
206; STATIC32: jal
207; STATIC32: .end caller9_1
208; N64: .ent caller9_1
209; N64: jalr
210; N64: .end caller9_1
211; PIC16: .ent caller9_1
212; PIC16: jalrc
213; PIC16: .end caller9_1
214
215  %call = tail call i32 @callee9(%struct.S* byval @gs1) nounwind
216  ret i32 %call
217}
218
219declare i32 @callee10(i32, i32, i32, i32, i32, i32, i32, i32, i32)
220
221define i32 @caller10(i32 %a0, i32 %a1, i32 %a2, i32 %a3, i32 %a4, i32 %a5, i32 %a6, i32 %a7, i32 %a8) nounwind {
222entry:
223; PIC32: .ent caller10
224; PIC32-NOT: jalr $25
225; STATIC32: .ent caller10
226; STATIC32-NOT: jal
227; N64: .ent caller10
228; N64-NOT: jalr $25
229; PIC16: .ent caller10
230; PIC16: jalrc
231
232  %call = tail call i32 @callee10(i32 %a8, i32 %a0, i32 %a1, i32 %a2, i32 %a3, i32 %a4, i32 %a5, i32 %a6, i32 %a7) nounwind
233  ret i32 %call
234}
235
236declare i32 @callee11(%struct.S* byval)
237
238define i32 @caller11() nounwind noinline {
239entry:
240; PIC32: .ent caller11
241; PIC32: jalr
242; STATIC32: .ent caller11
243; STATIC32: jal
244; N64: .ent caller11
245; N64: jalr
246; PIC16: .ent caller11
247; PIC16: jalrc
248
249  %call = tail call i32 @callee11(%struct.S* byval @gs1) nounwind
250  ret i32 %call
251}
252
253declare i32 @callee12()
254
255declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture, i8* nocapture, i32, i32, i1) nounwind
256
257define i32 @caller12(%struct.S* nocapture byval %a0) nounwind {
258entry:
259; PIC32: .ent caller12
260; PIC32: jalr
261; STATIC32: .ent caller12
262; STATIC32: jal
263; N64: .ent caller12
264; N64: jalr
265; PIC16: .ent caller12
266; PIC16: jalrc
267
268  %0 = bitcast %struct.S* %a0 to i8*
269  tail call void @llvm.memcpy.p0i8.p0i8.i32(i8* bitcast (%struct.S* @gs1 to i8*), i8* %0, i32 8, i32 4, i1 false)
270  %call = tail call i32 @callee12() nounwind
271  ret i32 %call
272}
273
274declare i32 @callee13(i32, ...)
275
276define i32 @caller13() nounwind {
277entry:
278; PIC32: .ent caller13
279; PIC32-NOT: jalr
280; STATIC32: .ent caller13
281; STATIC32-NOT: jal
282; N64: .ent caller13
283; N64-NOT: jalr $25
284; PIC16: .ent caller13
285; PIC16: jalrc
286
287  %call = tail call i32 (i32, ...) @callee13(i32 1, i32 2) nounwind
288  ret i32 %call
289}
290
291; Check that there is a chain edge between the load and store nodes.
292;
293; PIC32-LABEL: caller14:
294; PIC32: lw ${{[0-9]+}}, 16($sp)
295; PIC32: sw $4, 16($sp)
296
297define void @caller14(i32 %a, i32 %b, i32 %c, i32 %d, i32 %e) {
298entry:
299  tail call void @callee14(i32 %e, i32 %b, i32 %c, i32 %d, i32 %a)
300  ret void
301}
302
303declare void @callee14(i32, i32, i32, i32, i32)
304