1; RUN: llc < %s -mtriple=arm64-apple-ios7.0 | FileCheck %s
2; RUN: llc -global-isel < %s -mtriple=arm64-apple-ios7.0 | FileCheck %s
3
4@t = weak global i32 ()* null
5@x = external global i32, align 4
6
7define void @t2() {
8; CHECK-LABEL: t2:
9; CHECK: adrp	x[[GOTADDR:[0-9]+]], _t@GOTPAGE
10; CHECK: ldr	x[[ADDR:[0-9]+]], [x[[GOTADDR]], _t@GOTPAGEOFF]
11; CHECK: ldr	x[[DEST:[0-9]+]], [x[[ADDR]]]
12; CHECK: br	x[[DEST]]
13  %tmp = load i32 ()*, i32 ()** @t
14  %tmp.upgrd.2 = tail call i32 %tmp()
15  ret void
16}
17
18define void @t3() {
19; CHECK-LABEL: t3:
20; CHECK: b	_t2
21  tail call void @t2()
22  ret void
23}
24
25define double @t4(double %a) nounwind readonly ssp {
26; CHECK-LABEL: t4:
27; CHECK: b	_sin
28  %tmp = tail call double @sin(double %a) nounwind readonly
29  ret double %tmp
30}
31
32define float @t5(float %a) nounwind readonly ssp {
33; CHECK-LABEL: t5:
34; CHECK: b	_sinf
35  %tmp = tail call float @sinf(float %a) nounwind readonly
36  ret float %tmp
37}
38
39define void @t7() nounwind {
40; CHECK-LABEL: t7:
41; CHECK: b	_foo
42; CHECK: b	_bar
43
44  br i1 undef, label %bb, label %bb1.lr.ph
45
46bb1.lr.ph:                                        ; preds = %entry
47  tail call void @bar() nounwind
48  ret void
49
50bb:                                               ; preds = %entry
51  tail call void @foo() nounwind
52  ret void
53}
54
55define i32 @t8(i32 %x) nounwind ssp {
56; CHECK-LABEL: t8:
57; CHECK: b	_c
58; CHECK: b	_a
59; CHECK: b	_b
60  %and = and i32 %x, 1
61  %tobool = icmp eq i32 %and, 0
62  br i1 %tobool, label %if.end, label %if.then
63
64if.then:                                          ; preds = %entry
65  %call = tail call i32 @a(i32 %x) nounwind
66  br label %return
67
68if.end:                                           ; preds = %entry
69  %and1 = and i32 %x, 2
70  %tobool2 = icmp eq i32 %and1, 0
71  br i1 %tobool2, label %if.end5, label %if.then3
72
73if.then3:                                         ; preds = %if.end
74  %call4 = tail call i32 @b(i32 %x) nounwind
75  br label %return
76
77if.end5:                                          ; preds = %if.end
78  %call6 = tail call i32 @c(i32 %x) nounwind
79  br label %return
80
81return:                                           ; preds = %if.end5, %if.then3, %if.then
82  %retval.0 = phi i32 [ %call, %if.then ], [ %call4, %if.then3 ], [ %call6, %if.end5 ]
83  ret i32 %retval.0
84}
85
86declare float @sinf(float) nounwind readonly
87declare double @sin(double) nounwind readonly
88declare void @bar() nounwind
89declare void @foo() nounwind
90declare i32 @a(i32)
91declare i32 @b(i32)
92declare i32 @c(i32)
93
94; CHECK-LABEL: tswift:
95; CHECK: b _swiftfunc
96define swiftcc i32 @tswift(i32 %a) nounwind {
97  %res = tail call i32 @swiftfunc(i32 %a)
98  ret i32 %res
99}
100
101declare swiftcc i32 @swiftfunc(i32) nounwind
102