blob: 8821029520fe42cb7e31d1850b4546c13e91ff36 [file] [log] [blame]
Tim Northoverb4ddc082014-05-30 10:09:59 +00001; 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 \
Saleem Abdulrasoolb720a6b2014-03-11 15:09:49 +00004; RUN: | FileCheck %s -check-prefix=CHECKELF
Bob Wilson8decdc42011-10-07 17:17:49 +00005
6; Enable tailcall optimization for iOS 5.0
7; rdar://9120031
Dale Johannesenc1570dd2010-06-18 19:00:18 +00008
9@t = weak global i32 ()* null ; <i32 ()**> [#uses=1]
10
11declare void @g(i32, i32, i32, i32)
12
Evan Chengf3c01f32010-06-19 01:01:32 +000013define void @t1() {
Stephen Lind24ab202013-07-14 06:24:09 +000014; CHECKELF-LABEL: t1:
Evan Chengd4b08732010-11-30 23:55:39 +000015; CHECKELF: bl g(PLT)
Dale Johannesenc1570dd2010-06-18 19:00:18 +000016 call void @g( i32 1, i32 2, i32 3, i32 4 )
17 ret void
18}
19
Evan Chengf3c01f32010-06-19 01:01:32 +000020define void @t2() {
Stephen Lind24ab202013-07-14 06:24:09 +000021; CHECKV6-LABEL: t2:
Jim Grosbachdbfb29d2011-07-08 18:50:22 +000022; CHECKV6: bx r0
Stephen Lind24ab202013-07-14 06:24:09 +000023; CHECKT2D-LABEL: t2:
Cameron Zwarich3088e0a2011-05-25 04:45:27 +000024; CHECKT2D: ldr
25; CHECKT2D-NEXT: ldr
Jim Grosbachdbfb29d2011-07-08 18:50:22 +000026; CHECKT2D-NEXT: bx r0
David Blaikiea79ac142015-02-27 21:17:42 +000027 %tmp = load i32 ()*, i32 ()** @t ; <i32 ()*> [#uses=1]
Dale Johannesenc1570dd2010-06-18 19:00:18 +000028 %tmp.upgrd.2 = tail call i32 %tmp( ) ; <i32> [#uses=0]
29 ret void
30}
31
Evan Chengd4b08732010-11-30 23:55:39 +000032define void @t3() {
Stephen Lind24ab202013-07-14 06:24:09 +000033; CHECKV6-LABEL: t3:
Jim Grosbachdbfb29d2011-07-08 18:50:22 +000034; CHECKV6: b _t2
Stephen Lind24ab202013-07-14 06:24:09 +000035; CHECKELF-LABEL: t3:
Jim Grosbachdbfb29d2011-07-08 18:50:22 +000036; CHECKELF: b t2(PLT)
Stephen Lind24ab202013-07-14 06:24:09 +000037; CHECKT2D-LABEL: t3:
Jim Grosbachdbfb29d2011-07-08 18:50:22 +000038; CHECKT2D: b.w _t2
Cameron Zwarichbc906902011-05-23 01:57:17 +000039
Dale Johannesene2289282010-07-08 01:18:23 +000040 tail call void @t2( ) ; <i32> [#uses=0]
41 ret void
42}
Evan Chengd4b08732010-11-30 23:55:39 +000043
44; Sibcall optimization of expanded libcalls. rdar://8707777
45define double @t4(double %a) nounwind readonly ssp {
46entry:
Stephen Lind24ab202013-07-14 06:24:09 +000047; CHECKV6-LABEL: t4:
Jim Grosbachdbfb29d2011-07-08 18:50:22 +000048; CHECKV6: b _sin
Stephen Lind24ab202013-07-14 06:24:09 +000049; CHECKELF-LABEL: t4:
Jim Grosbachdbfb29d2011-07-08 18:50:22 +000050; CHECKELF: b sin(PLT)
Evan Chengd4b08732010-11-30 23:55:39 +000051 %0 = tail call double @sin(double %a) nounwind readonly ; <double> [#uses=1]
52 ret double %0
53}
54
55define float @t5(float %a) nounwind readonly ssp {
56entry:
Stephen Lind24ab202013-07-14 06:24:09 +000057; CHECKV6-LABEL: t5:
Jim Grosbachdbfb29d2011-07-08 18:50:22 +000058; CHECKV6: b _sinf
Stephen Lind24ab202013-07-14 06:24:09 +000059; CHECKELF-LABEL: t5:
Jim Grosbachdbfb29d2011-07-08 18:50:22 +000060; CHECKELF: b sinf(PLT)
Evan Chengd4b08732010-11-30 23:55:39 +000061 %0 = tail call float @sinf(float %a) nounwind readonly ; <float> [#uses=1]
62 ret float %0
63}
64
65declare float @sinf(float) nounwind readonly
66
67declare double @sin(double) nounwind readonly
68
69define i32 @t6(i32 %a, i32 %b) nounwind readnone {
70entry:
Stephen Lind24ab202013-07-14 06:24:09 +000071; CHECKV6-LABEL: t6:
Jim Grosbachdbfb29d2011-07-08 18:50:22 +000072; CHECKV6: b ___divsi3
Stephen Lind24ab202013-07-14 06:24:09 +000073; CHECKELF-LABEL: t6:
Jim Grosbachdbfb29d2011-07-08 18:50:22 +000074; CHECKELF: b __aeabi_idiv(PLT)
Evan Chengd4b08732010-11-30 23:55:39 +000075 %0 = sdiv i32 %a, %b
76 ret i32 %0
77}
Evan Chengd6093ff2011-01-25 01:28:33 +000078
79; Make sure the tail call instruction isn't deleted
80; rdar://8309338
81declare void @foo() nounwind
82
83define void @t7() nounwind {
84entry:
Stephen Lind24ab202013-07-14 06:24:09 +000085; CHECKT2D-LABEL: t7:
Quentin Colombet8cb95b82015-11-18 00:40:54 +000086; CHECKT2D: it ne
87; CHECKT2D-NEXT: bne.w _foo
88; CHECKT2D-NEXT: push
89; CHECKT2D-NEXT: mov r7, sp
90; CHECKT2D-NEXT: blx _foo
Evan Chengd6093ff2011-01-25 01:28:33 +000091 br i1 undef, label %bb, label %bb1.lr.ph
92
93bb1.lr.ph:
94 tail call void @foo() nounwind
95 unreachable
96
97bb:
98 tail call void @foo() nounwind
99 ret void
100}
Evan Chenga40d4062012-03-30 01:24:39 +0000101
102; Make sure codegenprep is duplicating ret instructions to enable tail calls.
103; rdar://11140249
104define i32 @t8(i32 %x) nounwind ssp {
105entry:
Stephen Lind24ab202013-07-14 06:24:09 +0000106; CHECKT2D-LABEL: t8:
Evan Chenga40d4062012-03-30 01:24:39 +0000107; CHECKT2D-NOT: push
Evan Chenga40d4062012-03-30 01:24:39 +0000108 %and = and i32 %x, 1
109 %tobool = icmp eq i32 %and, 0
110 br i1 %tobool, label %if.end, label %if.then
111
112if.then: ; preds = %entry
113; CHECKT2D: bne.w _a
114 %call = tail call i32 @a(i32 %x) nounwind
115 br label %return
116
117if.end: ; preds = %entry
118 %and1 = and i32 %x, 2
119 %tobool2 = icmp eq i32 %and1, 0
120 br i1 %tobool2, label %if.end5, label %if.then3
121
122if.then3: ; preds = %if.end
123; CHECKT2D: bne.w _b
124 %call4 = tail call i32 @b(i32 %x) nounwind
125 br label %return
126
127if.end5: ; preds = %if.end
128; CHECKT2D: b.w _c
129 %call6 = tail call i32 @c(i32 %x) nounwind
130 br label %return
131
132return: ; preds = %if.end5, %if.then3, %if.then
133 %retval.0 = phi i32 [ %call, %if.then ], [ %call4, %if.then3 ], [ %call6, %if.end5 ]
134 ret i32 %retval.0
135}
136
137declare i32 @a(i32)
138
139declare i32 @b(i32)
140
141declare i32 @c(i32)
Evan Chengf8bad082012-04-10 01:51:00 +0000142
143; PR12419
144; rdar://11195178
145; Use the correct input chain for the tailcall node or else the call to
146; _ZN9MutexLockD1Ev would be lost.
147%class.MutexLock = type { i8 }
148
149@x = external global i32, align 4
150
Evan Cheng07526242012-04-10 03:15:42 +0000151define i32 @t9() nounwind {
Stephen Lind24ab202013-07-14 06:24:09 +0000152; CHECKT2D-LABEL: t9:
Evan Cheng07526242012-04-10 03:15:42 +0000153; CHECKT2D: blx __ZN9MutexLockC1Ev
154; CHECKT2D: blx __ZN9MutexLockD1Ev
155; CHECKT2D: b.w ___divsi3
Evan Chengf8bad082012-04-10 01:51:00 +0000156 %lock = alloca %class.MutexLock, align 1
157 %1 = call %class.MutexLock* @_ZN9MutexLockC1Ev(%class.MutexLock* %lock)
David Blaikiea79ac142015-02-27 21:17:42 +0000158 %2 = load i32, i32* @x, align 4
Evan Chengf8bad082012-04-10 01:51:00 +0000159 %3 = sdiv i32 1000, %2
160 %4 = call %class.MutexLock* @_ZN9MutexLockD1Ev(%class.MutexLock* %lock)
161 ret i32 %3
162}
163
164declare %class.MutexLock* @_ZN9MutexLockC1Ev(%class.MutexLock*) unnamed_addr nounwind align 2
165
166declare %class.MutexLock* @_ZN9MutexLockD1Ev(%class.MutexLock*) unnamed_addr nounwind align 2
Lang Hames67c09b32013-05-13 10:21:19 +0000167
168; rdar://13827621
169; Correctly preserve the input chain for the tailcall node in the bitcast case,
170; otherwise the call to floorf is lost.
171define float @libcall_tc_test2(float* nocapture %a, float %b) {
Stephen Lind24ab202013-07-14 06:24:09 +0000172; CHECKT2D-LABEL: libcall_tc_test2:
Lang Hames67c09b32013-05-13 10:21:19 +0000173; CHECKT2D: blx _floorf
174; CHECKT2D: b.w _truncf
David Blaikiea79ac142015-02-27 21:17:42 +0000175 %1 = load float, float* %a, align 4
Lang Hames67c09b32013-05-13 10:21:19 +0000176 %call = tail call float @floorf(float %1)
177 store float %call, float* %a, align 4
178 %call1 = tail call float @truncf(float %b)
179 ret float %call1
180}
181
182declare float @floorf(float) readnone
183declare float @truncf(float) readnone