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 ; We can't merge the returns.
53 ; CHECK: define void @test_multiret_a(
54 ; CHECK: musttail call void @test_multiret_c(
55 ; CHECK-NEXT: ret void
56 ; CHECK: musttail call void @test_multiret_d(
57 ; CHECK-NEXT: ret void
59 declare void @test_multiret_c(i1 zeroext %b)
60 declare void @test_multiret_d(i1 zeroext %b)
61 define internal void @test_multiret_b(i1 zeroext %b) {
62 br i1 %b, label %c, label %d
64 musttail call void @test_multiret_c(i1 zeroext %b)
67 musttail call void @test_multiret_d(i1 zeroext %b)
70 define void @test_multiret_a(i1 zeroext %b) {
71 musttail call void @test_multiret_b(i1 zeroext %b)
75 ; We have to avoid bitcast chains.
76 ; CHECK: define i32* @test_retptr_a(
77 ; CHECK: musttail call i8* @test_retptr_c(
78 ; CHECK-NEXT: bitcast i8* {{.*}} to i32*
79 ; CHECK-NEXT: ret i32*
81 declare i8* @test_retptr_c()
82 define internal i16* @test_retptr_b() {
83 %rv = musttail call i8* @test_retptr_c()
84 %v = bitcast i8* %rv to i16*
87 define i32* @test_retptr_a() {
88 %rv = musttail call i16* @test_retptr_b()
89 %v = bitcast i16* %rv to i32*
93 ; Combine the last two cases: multiple returns with pointer bitcasts.
94 ; CHECK: define i32* @test_multiptrret_a(
95 ; CHECK: musttail call i8* @test_multiptrret_c(
96 ; CHECK-NEXT: bitcast i8* {{.*}} to i32*
97 ; CHECK-NEXT: ret i32*
98 ; CHECK: musttail call i8* @test_multiptrret_d(
99 ; CHECK-NEXT: bitcast i8* {{.*}} to i32*
100 ; CHECK-NEXT: ret i32*
102 declare i8* @test_multiptrret_c(i1 zeroext %b)
103 declare i8* @test_multiptrret_d(i1 zeroext %b)
104 define internal i16* @test_multiptrret_b(i1 zeroext %b) {
105 br i1 %b, label %c, label %d
107 %c_rv = musttail call i8* @test_multiptrret_c(i1 zeroext %b)
108 %c_v = bitcast i8* %c_rv to i16*
111 %d_rv = musttail call i8* @test_multiptrret_d(i1 zeroext %b)
112 %d_v = bitcast i8* %d_rv to i16*
115 define i32* @test_multiptrret_a(i1 zeroext %b) {
116 %rv = musttail call i16* @test_multiptrret_b(i1 zeroext %b)
117 %v = bitcast i16* %rv to i32*
121 ; Inline a musttail call site which contains a normal return and a musttail call.
122 ; CHECK: define i32 @test_mixedret_a(
124 ; CHECK: musttail call i32 @test_mixedret_c(
125 ; CHECK-NEXT: ret i32
126 ; CHECK: call i32 @test_mixedret_d(i1 zeroext %b)
131 declare i32 @test_mixedret_c(i1 zeroext %b)
132 declare i32 @test_mixedret_d(i1 zeroext %b)
133 define internal i32 @test_mixedret_b(i1 zeroext %b) {
134 br i1 %b, label %c, label %d
136 %c_rv = musttail call i32 @test_mixedret_c(i1 zeroext %b)
139 %d_rv = call i32 @test_mixedret_d(i1 zeroext %b)
140 %d_rv1 = add i32 1, %d_rv
143 define i32 @test_mixedret_a(i1 zeroext %b) {
144 %rv = musttail call i32 @test_mixedret_b(i1 zeroext %b)