1 ; RUN: opt < %s -inline -S | FileCheck %s
3 ; We have to apply the less restrictive TailCallKind of the call site being
4 ; inlined and any call sites cloned into the caller.
6 ; No tail marker after inlining, since test_capture_c captures an alloca.
7 ; CHECK: define void @test_capture_a(
9 ; CHECK: call void @test_capture_c(
11 declare void @test_capture_c(i32*)
12 define internal void @test_capture_b(i32* %P) {
13 tail call void @test_capture_c(i32* %P)
16 define void @test_capture_a() {
17 %A = alloca i32 ; captured by test_capture_b
18 call void @test_capture_b(i32* %A)
22 ; No musttail marker after inlining, since the prototypes don't match.
23 ; CHECK: define void @test_proto_mismatch_a(
25 ; CHECK: call void @test_proto_mismatch_c(
27 declare void @test_proto_mismatch_c(i32*)
28 define internal void @test_proto_mismatch_b(i32* %p) {
29 musttail call void @test_proto_mismatch_c(i32* %p)
32 define void @test_proto_mismatch_a() {
33 call void @test_proto_mismatch_b(i32* null)
37 ; After inlining through a musttail call site, we need to keep musttail markers
38 ; to prevent unbounded stack growth.
39 ; CHECK: define void @test_musttail_basic_a(
40 ; CHECK: musttail call void @test_musttail_basic_c(
42 declare void @test_musttail_basic_c(i32* %p)
43 define internal void @test_musttail_basic_b(i32* %p) {
44 musttail call void @test_musttail_basic_c(i32* %p)
47 define void @test_musttail_basic_a(i32* %p) {
48 musttail call void @test_musttail_basic_b(i32* %p)
52 ; Don't insert lifetime end markers here, the lifetime is trivially over due
54 ; CHECK: define void @test_byval_a(
55 ; CHECK: musttail call void @test_byval_c(
56 ; CHECK-NEXT: ret void
58 declare void @test_byval_c(i32* byval %p)
59 define internal void @test_byval_b(i32* byval %p) {
60 musttail call void @test_byval_c(i32* byval %p)
63 define void @test_byval_a(i32* byval %p) {
64 musttail call void @test_byval_b(i32* byval %p)
68 ; Don't insert a stack restore, we're about to return.
69 ; CHECK: define void @test_dynalloca_a(
70 ; CHECK: call i8* @llvm.stacksave(
71 ; CHECK: alloca i8, i32 %n
72 ; CHECK: musttail call void @test_dynalloca_c(
73 ; CHECK-NEXT: ret void
75 declare void @escape(i8* %buf)
76 declare void @test_dynalloca_c(i32* byval %p, i32 %n)
77 define internal void @test_dynalloca_b(i32* byval %p, i32 %n) alwaysinline {
78 %buf = alloca i8, i32 %n ; dynamic alloca
79 call void @escape(i8* %buf) ; escape it
80 musttail call void @test_dynalloca_c(i32* byval %p, i32 %n)
83 define void @test_dynalloca_a(i32* byval %p, i32 %n) {
84 musttail call void @test_dynalloca_b(i32* byval %p, i32 %n)
88 ; We can't merge the returns.
89 ; CHECK: define void @test_multiret_a(
90 ; CHECK: musttail call void @test_multiret_c(
91 ; CHECK-NEXT: ret void
92 ; CHECK: musttail call void @test_multiret_d(
93 ; CHECK-NEXT: ret void
95 declare void @test_multiret_c(i1 zeroext %b)
96 declare void @test_multiret_d(i1 zeroext %b)
97 define internal void @test_multiret_b(i1 zeroext %b) {
98 br i1 %b, label %c, label %d
100 musttail call void @test_multiret_c(i1 zeroext %b)
103 musttail call void @test_multiret_d(i1 zeroext %b)
106 define void @test_multiret_a(i1 zeroext %b) {
107 musttail call void @test_multiret_b(i1 zeroext %b)
111 ; We have to avoid bitcast chains.
112 ; CHECK: define i32* @test_retptr_a(
113 ; CHECK: musttail call i8* @test_retptr_c(
114 ; CHECK-NEXT: bitcast i8* {{.*}} to i32*
115 ; CHECK-NEXT: ret i32*
117 declare i8* @test_retptr_c()
118 define internal i16* @test_retptr_b() {
119 %rv = musttail call i8* @test_retptr_c()
120 %v = bitcast i8* %rv to i16*
123 define i32* @test_retptr_a() {
124 %rv = musttail call i16* @test_retptr_b()
125 %v = bitcast i16* %rv to i32*
129 ; Combine the last two cases: multiple returns with pointer bitcasts.
130 ; CHECK: define i32* @test_multiptrret_a(
131 ; CHECK: musttail call i8* @test_multiptrret_c(
132 ; CHECK-NEXT: bitcast i8* {{.*}} to i32*
133 ; CHECK-NEXT: ret i32*
134 ; CHECK: musttail call i8* @test_multiptrret_d(
135 ; CHECK-NEXT: bitcast i8* {{.*}} to i32*
136 ; CHECK-NEXT: ret i32*
138 declare i8* @test_multiptrret_c(i1 zeroext %b)
139 declare i8* @test_multiptrret_d(i1 zeroext %b)
140 define internal i16* @test_multiptrret_b(i1 zeroext %b) {
141 br i1 %b, label %c, label %d
143 %c_rv = musttail call i8* @test_multiptrret_c(i1 zeroext %b)
144 %c_v = bitcast i8* %c_rv to i16*
147 %d_rv = musttail call i8* @test_multiptrret_d(i1 zeroext %b)
148 %d_v = bitcast i8* %d_rv to i16*
151 define i32* @test_multiptrret_a(i1 zeroext %b) {
152 %rv = musttail call i16* @test_multiptrret_b(i1 zeroext %b)
153 %v = bitcast i16* %rv to i32*
157 ; Inline a musttail call site which contains a normal return and a musttail call.
158 ; CHECK: define i32 @test_mixedret_a(
160 ; CHECK: musttail call i32 @test_mixedret_c(
161 ; CHECK-NEXT: ret i32
162 ; CHECK: call i32 @test_mixedret_d(i1 zeroext %b)
167 declare i32 @test_mixedret_c(i1 zeroext %b)
168 declare i32 @test_mixedret_d(i1 zeroext %b)
169 define internal i32 @test_mixedret_b(i1 zeroext %b) {
170 br i1 %b, label %c, label %d
172 %c_rv = musttail call i32 @test_mixedret_c(i1 zeroext %b)
175 %d_rv = call i32 @test_mixedret_d(i1 zeroext %b)
176 %d_rv1 = add i32 1, %d_rv
179 define i32 @test_mixedret_a(i1 zeroext %b) {
180 %rv = musttail call i32 @test_mixedret_b(i1 zeroext %b)