1; RUN: llc -mtriple=aarch64-apple-darwin -fast-isel -fast-isel-abort=1 -verify-machineinstrs < %s | FileCheck %s
2
3; CHECK-LABEL: test_or
4; CHECK:       cbnz w0, {{LBB[0-9]+_2}}
5; CHECK:       cbz w1, {{LBB[0-9]+_1}}
6define i64 @test_or(i32 %a, i32 %b) {
7bb1:
8  %0 = icmp eq i32 %a, 0
9  %1 = icmp eq i32 %b, 0
10  %or.cond = or i1 %0, %1
11  br i1 %or.cond, label %bb3, label %bb4, !prof !0
12
13bb3:
14  ret i64 0
15
16bb4:
17  %2 = call i64 @bar()
18  ret i64 %2
19}
20
21; CHECK-LABEL: test_and
22; CHECK:       cbz w0, {{LBB[0-9]+_2}}
23; CHECK:       cbnz w1, {{LBB[0-9]+_3}}
24define i64 @test_and(i32 %a, i32 %b) {
25bb1:
26  %0 = icmp ne i32 %a, 0
27  %1 = icmp ne i32 %b, 0
28  %or.cond = and i1 %0, %1
29  br i1 %or.cond, label %bb4, label %bb3, !prof !1
30
31bb3:
32  ret i64 0
33
34bb4:
35  %2 = call i64 @bar()
36  ret i64 %2
37}
38
39; If the branch is unpredictable, don't add another branch.
40
41; CHECK-LABEL: test_or_unpredictable
42; CHECK:       cmp   w0, #0
43; CHECK-NEXT:  cset  w8, eq
44; CHECK-NEXT:  cmp   w1, #0
45; CHECK-NEXT:  cset  w9, eq
46; CHECK-NEXT:  orr   w8, w8, w9
47; CHECK-NEXT:  tbnz w8, #0,
48define i64 @test_or_unpredictable(i32 %a, i32 %b) {
49bb1:
50  %0 = icmp eq i32 %a, 0
51  %1 = icmp eq i32 %b, 0
52  %or.cond = or i1 %0, %1
53  br i1 %or.cond, label %bb3, label %bb4, !unpredictable !2
54
55bb3:
56  ret i64 0
57
58bb4:
59  %2 = call i64 @bar()
60  ret i64 %2
61}
62
63; CHECK-LABEL: test_and_unpredictable
64; CHECK:       cmp   w0, #0
65; CHECK-NEXT:  cset  w8, ne
66; CHECK-NEXT:  cmp   w1, #0
67; CHECK-NEXT:  cset  w9, ne
68; CHECK-NEXT:  and   w8, w8, w9
69; CHECK-NEXT:  tbz w8, #0,
70define i64 @test_and_unpredictable(i32 %a, i32 %b) {
71bb1:
72  %0 = icmp ne i32 %a, 0
73  %1 = icmp ne i32 %b, 0
74  %or.cond = and i1 %0, %1
75  br i1 %or.cond, label %bb4, label %bb3, !unpredictable !2
76
77bb3:
78  ret i64 0
79
80bb4:
81  %2 = call i64 @bar()
82  ret i64 %2
83}
84
85declare i64 @bar()
86
87!0 = !{!"branch_weights", i32 5128, i32 32}
88!1 = !{!"branch_weights", i32 1024, i32 4136}
89!2 = !{}
90
91