1 ; RUN: llc -mtriple=aarch64-none-linux-gnu < %s | FileCheck %s
2 ; RUN: llc -mtriple=arm64-none-linux-gnu < %s | FileCheck %s
4 ; This test checks that LLVM can do basic stripping and reapplying of branches
7 declare void @test_true()
8 declare void @test_false()
10 ; !0 corresponds to a branch being taken, !1 to not being takne.
11 !0 = metadata !{metadata !"branch_weights", i32 64, i32 4}
12 !1 = metadata !{metadata !"branch_weights", i32 4, i32 64}
14 define void @test_Bcc_fallthrough_taken(i32 %in) nounwind {
15 ; CHECK-LABEL: test_Bcc_fallthrough_taken:
16 %tst = icmp eq i32 %in, 42
17 br i1 %tst, label %true, label %false, !prof !0
19 ; CHECK: cmp {{w[0-9]+}}, #42
21 ; CHECK: b.ne [[FALSE:.LBB[0-9]+_[0-9]+]]
23 ; CHECK-NEXT: bl test_true
26 ; CHECK: bl test_false
29 call void @test_true()
33 call void @test_false()
37 define void @test_Bcc_fallthrough_nottaken(i32 %in) nounwind {
38 ; CHECK-LABEL: test_Bcc_fallthrough_nottaken:
39 %tst = icmp eq i32 %in, 42
40 br i1 %tst, label %true, label %false, !prof !1
42 ; CHECK: cmp {{w[0-9]+}}, #42
44 ; CHECK: b.eq [[TRUE:.LBB[0-9]+_[0-9]+]]
46 ; CHECK-NEXT: bl test_false
52 call void @test_true()
56 call void @test_false()
60 define void @test_CBZ_fallthrough_taken(i32 %in) nounwind {
61 ; CHECK-LABEL: test_CBZ_fallthrough_taken:
62 %tst = icmp eq i32 %in, 0
63 br i1 %tst, label %true, label %false, !prof !0
65 ; CHECK: cbnz {{w[0-9]+}}, [[FALSE:.LBB[0-9]+_[0-9]+]]
67 ; CHECK-NEXT: bl test_true
70 ; CHECK: bl test_false
73 call void @test_true()
77 call void @test_false()
81 define void @test_CBZ_fallthrough_nottaken(i64 %in) nounwind {
82 ; CHECK-LABEL: test_CBZ_fallthrough_nottaken:
83 %tst = icmp eq i64 %in, 0
84 br i1 %tst, label %true, label %false, !prof !1
86 ; CHECK: cbz {{x[0-9]+}}, [[TRUE:.LBB[0-9]+_[0-9]+]]
88 ; CHECK-NEXT: bl test_false
94 call void @test_true()
98 call void @test_false()
102 define void @test_CBNZ_fallthrough_taken(i32 %in) nounwind {
103 ; CHECK-LABEL: test_CBNZ_fallthrough_taken:
104 %tst = icmp ne i32 %in, 0
105 br i1 %tst, label %true, label %false, !prof !0
107 ; CHECK: cbz {{w[0-9]+}}, [[FALSE:.LBB[0-9]+_[0-9]+]]
109 ; CHECK-NEXT: bl test_true
112 ; CHECK: bl test_false
115 call void @test_true()
119 call void @test_false()
123 define void @test_CBNZ_fallthrough_nottaken(i64 %in) nounwind {
124 ; CHECK-LABEL: test_CBNZ_fallthrough_nottaken:
125 %tst = icmp ne i64 %in, 0
126 br i1 %tst, label %true, label %false, !prof !1
128 ; CHECK: cbnz {{x[0-9]+}}, [[TRUE:.LBB[0-9]+_[0-9]+]]
130 ; CHECK-NEXT: bl test_false
133 ; CHECK: bl test_true
136 call void @test_true()
140 call void @test_false()
144 define void @test_TBZ_fallthrough_taken(i32 %in) nounwind {
145 ; CHECK-LABEL: test_TBZ_fallthrough_taken:
146 %bit = and i32 %in, 32768
147 %tst = icmp eq i32 %bit, 0
148 br i1 %tst, label %true, label %false, !prof !0
150 ; CHECK: tbnz {{w[0-9]+}}, #15, [[FALSE:.LBB[0-9]+_[0-9]+]]
152 ; CHECK-NEXT: bl test_true
155 ; CHECK: bl test_false
158 call void @test_true()
162 call void @test_false()
166 define void @test_TBZ_fallthrough_nottaken(i64 %in) nounwind {
167 ; CHECK-LABEL: test_TBZ_fallthrough_nottaken:
168 %bit = and i64 %in, 32768
169 %tst = icmp eq i64 %bit, 0
170 br i1 %tst, label %true, label %false, !prof !1
172 ; CHECK: tbz {{[wx][0-9]+}}, #15, [[TRUE:.LBB[0-9]+_[0-9]+]]
174 ; CHECK-NEXT: bl test_false
177 ; CHECK: bl test_true
180 call void @test_true()
184 call void @test_false()
189 define void @test_TBNZ_fallthrough_taken(i32 %in) nounwind {
190 ; CHECK-LABEL: test_TBNZ_fallthrough_taken:
191 %bit = and i32 %in, 32768
192 %tst = icmp ne i32 %bit, 0
193 br i1 %tst, label %true, label %false, !prof !0
195 ; CHECK: tbz {{w[0-9]+}}, #15, [[FALSE:.LBB[0-9]+_[0-9]+]]
197 ; CHECK-NEXT: bl test_true
200 ; CHECK: bl test_false
203 call void @test_true()
207 call void @test_false()
211 define void @test_TBNZ_fallthrough_nottaken(i64 %in) nounwind {
212 ; CHECK-LABEL: test_TBNZ_fallthrough_nottaken:
213 %bit = and i64 %in, 32768
214 %tst = icmp ne i64 %bit, 0
215 br i1 %tst, label %true, label %false, !prof !1
217 ; CHECK: tbnz {{[wx][0-9]+}}, #15, [[TRUE:.LBB[0-9]+_[0-9]+]]
219 ; CHECK-NEXT: bl test_false
222 ; CHECK: bl test_true
225 call void @test_true()
229 call void @test_false()