1 ; RUN: llc < %s -mtriple=armv6-apple-ios5.0 -mattr=+vfp2 -arm-atomic-cfg-tidy=0 | FileCheck %s -check-prefix=CHECKV6
2 ; RUN: llc < %s -mtriple=thumbv7-apple-ios5.0 -arm-atomic-cfg-tidy=0 | FileCheck %s -check-prefix=CHECKT2D
3 ; RUN: llc < %s -mtriple=armv6-linux-gnueabi -relocation-model=pic -mattr=+vfp2 -arm-atomic-cfg-tidy=0 \
4 ; RUN: | FileCheck %s -check-prefix=CHECKELF
6 ; Enable tailcall optimization for iOS 5.0
9 @t = weak global ptr null ; <ptr> [#uses=1]
11 declare void @g(i32, i32, i32, i32)
13 define void @t1() "frame-pointer"="all" {
16 call void @g( i32 1, i32 2, i32 3, i32 4 )
20 define void @t2() "frame-pointer"="all" {
26 ; CHECKT2D-NEXT: bx r0
27 %tmp = load ptr, ptr @t ; <ptr> [#uses=1]
28 %tmp.upgrd.2 = tail call i32 %tmp( ) ; <i32> [#uses=0]
32 define void @t3() "frame-pointer"="all" {
40 tail call void @t2( ) ; <i32> [#uses=0]
44 ; Sibcall optimization of expanded libcalls. rdar://8707777
45 define double @t4(double %a) nounwind readonly ssp "frame-pointer"="all" {
51 %0 = tail call double @sin(double %a) nounwind readonly ; <double> [#uses=1]
55 define float @t5(float %a) nounwind readonly ssp "frame-pointer"="all" {
61 %0 = tail call float @sinf(float %a) nounwind readonly ; <float> [#uses=1]
65 declare float @sinf(float) nounwind readonly
67 declare double @sin(double) nounwind readonly
69 define i32 @t6(i32 %a, i32 %b) nounwind readnone "frame-pointer"="all" {
72 ; CHECKV6: b ___divsi3
74 ; CHECKELF: b __aeabi_idiv
79 ; Make sure the tail call instruction isn't deleted
81 declare void @foo() nounwind
83 define void @t7() nounwind "frame-pointer"="all" {
87 ; CHECKT2D-NEXT: bne.w _foo
88 ; CHECKT2D-NEXT: LBB{{.*}}:
90 ; CHECKT2D-NEXT: mov r7, sp
91 ; CHECKT2D-NEXT: bl _foo
92 br i1 undef, label %bb, label %bb1.lr.ph
95 tail call void @foo() nounwind
99 tail call void @foo() nounwind
103 ; Make sure codegenprep is duplicating ret instructions to enable tail calls.
105 define i32 @t8(i32 %x) nounwind ssp "frame-pointer"="all" {
107 ; CHECKT2D-LABEL: t8:
110 %tobool = icmp eq i32 %and, 0
111 br i1 %tobool, label %if.end, label %if.then
113 if.then: ; preds = %entry
115 %call = tail call i32 @a(i32 %x) nounwind
118 if.end: ; preds = %entry
119 %and1 = and i32 %x, 2
120 %tobool2 = icmp eq i32 %and1, 0
121 br i1 %tobool2, label %if.end5, label %if.then3
123 if.then3: ; preds = %if.end
125 %call4 = tail call i32 @b(i32 %x) nounwind
128 if.end5: ; preds = %if.end
130 %call6 = tail call i32 @c(i32 %x) nounwind
133 return: ; preds = %if.end5, %if.then3, %if.then
134 %retval.0 = phi i32 [ %call, %if.then ], [ %call4, %if.then3 ], [ %call6, %if.end5 ]
146 ; Use the correct input chain for the tailcall node or else the call to
147 ; _ZN9MutexLockD1Ev would be lost.
148 %class.MutexLock = type { i8 }
150 @x = external global i32, align 4
152 define i32 @t9() nounwind "frame-pointer"="all" {
153 ; CHECKT2D-LABEL: t9:
154 ; CHECKT2D: bl __ZN9MutexLockC1Ev
155 ; CHECKT2D: bl __ZN9MutexLockD1Ev
156 ; CHECKT2D: b.w ___divsi3
157 %lock = alloca %class.MutexLock, align 1
158 %1 = call ptr @_ZN9MutexLockC1Ev(ptr %lock)
159 %2 = load i32, ptr @x, align 4
160 %3 = sdiv i32 1000, %2
161 %4 = call ptr @_ZN9MutexLockD1Ev(ptr %lock)
165 declare ptr @_ZN9MutexLockC1Ev(ptr) unnamed_addr nounwind align 2
167 declare ptr @_ZN9MutexLockD1Ev(ptr) unnamed_addr nounwind align 2
170 ; Correctly preserve the input chain for the tailcall node in the bitcast case,
171 ; otherwise the call to floorf is lost.
172 define float @libcall_tc_test2(ptr nocapture %a, float %b) "frame-pointer"="all" {
173 ; CHECKT2D-LABEL: libcall_tc_test2:
174 ; CHECKT2D: bl _floorf
175 ; CHECKT2D: b.w _truncf
176 %1 = load float, ptr %a, align 4
177 %call = tail call float @floorf(float %1)
178 store float %call, ptr %a, align 4
179 %call1 = tail call float @truncf(float %b)
183 declare float @floorf(float) readnone
184 declare float @truncf(float) readnone