1*9880d681SAndroid Build Coastguard Worker; RUN: llc -mtriple=aarch64-none-linux-gnu < %s | FileCheck %s 2*9880d681SAndroid Build Coastguard Worker 3*9880d681SAndroid Build Coastguard Worker; This test checks that LLVM can do basic stripping and reapplying of branches 4*9880d681SAndroid Build Coastguard Worker; to basic blocks. 5*9880d681SAndroid Build Coastguard Worker 6*9880d681SAndroid Build Coastguard Workerdeclare void @test_true() 7*9880d681SAndroid Build Coastguard Workerdeclare void @test_false() 8*9880d681SAndroid Build Coastguard Worker 9*9880d681SAndroid Build Coastguard Worker; !0 corresponds to a branch being taken, !1 to not being takne. 10*9880d681SAndroid Build Coastguard Worker!0 = !{!"branch_weights", i32 64, i32 4} 11*9880d681SAndroid Build Coastguard Worker!1 = !{!"branch_weights", i32 4, i32 64} 12*9880d681SAndroid Build Coastguard Worker 13*9880d681SAndroid Build Coastguard Workerdefine void @test_Bcc_fallthrough_taken(i32 %in) nounwind { 14*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: test_Bcc_fallthrough_taken: 15*9880d681SAndroid Build Coastguard Worker %tst = icmp eq i32 %in, 42 16*9880d681SAndroid Build Coastguard Worker br i1 %tst, label %true, label %false, !prof !0 17*9880d681SAndroid Build Coastguard Worker 18*9880d681SAndroid Build Coastguard Worker; CHECK: cmp {{w[0-9]+}}, #42 19*9880d681SAndroid Build Coastguard Worker 20*9880d681SAndroid Build Coastguard Worker; CHECK: b.ne [[FALSE:.LBB[0-9]+_[0-9]+]] 21*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: // BB# 22*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: bl test_true 23*9880d681SAndroid Build Coastguard Worker 24*9880d681SAndroid Build Coastguard Worker; CHECK: [[FALSE]]: 25*9880d681SAndroid Build Coastguard Worker; CHECK: bl test_false 26*9880d681SAndroid Build Coastguard Worker 27*9880d681SAndroid Build Coastguard Workertrue: 28*9880d681SAndroid Build Coastguard Worker call void @test_true() 29*9880d681SAndroid Build Coastguard Worker ret void 30*9880d681SAndroid Build Coastguard Worker 31*9880d681SAndroid Build Coastguard Workerfalse: 32*9880d681SAndroid Build Coastguard Worker call void @test_false() 33*9880d681SAndroid Build Coastguard Worker ret void 34*9880d681SAndroid Build Coastguard Worker} 35*9880d681SAndroid Build Coastguard Worker 36*9880d681SAndroid Build Coastguard Workerdefine void @test_Bcc_fallthrough_nottaken(i32 %in) nounwind { 37*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: test_Bcc_fallthrough_nottaken: 38*9880d681SAndroid Build Coastguard Worker %tst = icmp eq i32 %in, 42 39*9880d681SAndroid Build Coastguard Worker br i1 %tst, label %true, label %false, !prof !1 40*9880d681SAndroid Build Coastguard Worker 41*9880d681SAndroid Build Coastguard Worker; CHECK: cmp {{w[0-9]+}}, #42 42*9880d681SAndroid Build Coastguard Worker 43*9880d681SAndroid Build Coastguard Worker; CHECK: b.eq [[TRUE:.LBB[0-9]+_[0-9]+]] 44*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: // BB# 45*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: bl test_false 46*9880d681SAndroid Build Coastguard Worker 47*9880d681SAndroid Build Coastguard Worker; CHECK: [[TRUE]]: 48*9880d681SAndroid Build Coastguard Worker; CHECK: bl test_true 49*9880d681SAndroid Build Coastguard Worker 50*9880d681SAndroid Build Coastguard Workertrue: 51*9880d681SAndroid Build Coastguard Worker call void @test_true() 52*9880d681SAndroid Build Coastguard Worker ret void 53*9880d681SAndroid Build Coastguard Worker 54*9880d681SAndroid Build Coastguard Workerfalse: 55*9880d681SAndroid Build Coastguard Worker call void @test_false() 56*9880d681SAndroid Build Coastguard Worker ret void 57*9880d681SAndroid Build Coastguard Worker} 58*9880d681SAndroid Build Coastguard Worker 59*9880d681SAndroid Build Coastguard Workerdefine void @test_CBZ_fallthrough_taken(i32 %in) nounwind { 60*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: test_CBZ_fallthrough_taken: 61*9880d681SAndroid Build Coastguard Worker %tst = icmp eq i32 %in, 0 62*9880d681SAndroid Build Coastguard Worker br i1 %tst, label %true, label %false, !prof !0 63*9880d681SAndroid Build Coastguard Worker 64*9880d681SAndroid Build Coastguard Worker; CHECK: cbnz {{w[0-9]+}}, [[FALSE:.LBB[0-9]+_[0-9]+]] 65*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: // BB# 66*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: bl test_true 67*9880d681SAndroid Build Coastguard Worker 68*9880d681SAndroid Build Coastguard Worker; CHECK: [[FALSE]]: 69*9880d681SAndroid Build Coastguard Worker; CHECK: bl test_false 70*9880d681SAndroid Build Coastguard Worker 71*9880d681SAndroid Build Coastguard Workertrue: 72*9880d681SAndroid Build Coastguard Worker call void @test_true() 73*9880d681SAndroid Build Coastguard Worker ret void 74*9880d681SAndroid Build Coastguard Worker 75*9880d681SAndroid Build Coastguard Workerfalse: 76*9880d681SAndroid Build Coastguard Worker call void @test_false() 77*9880d681SAndroid Build Coastguard Worker ret void 78*9880d681SAndroid Build Coastguard Worker} 79*9880d681SAndroid Build Coastguard Worker 80*9880d681SAndroid Build Coastguard Workerdefine void @test_CBZ_fallthrough_nottaken(i64 %in) nounwind { 81*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: test_CBZ_fallthrough_nottaken: 82*9880d681SAndroid Build Coastguard Worker %tst = icmp eq i64 %in, 0 83*9880d681SAndroid Build Coastguard Worker br i1 %tst, label %true, label %false, !prof !1 84*9880d681SAndroid Build Coastguard Worker 85*9880d681SAndroid Build Coastguard Worker; CHECK: cbz {{x[0-9]+}}, [[TRUE:.LBB[0-9]+_[0-9]+]] 86*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: // BB# 87*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: bl test_false 88*9880d681SAndroid Build Coastguard Worker 89*9880d681SAndroid Build Coastguard Worker; CHECK: [[TRUE]]: 90*9880d681SAndroid Build Coastguard Worker; CHECK: bl test_true 91*9880d681SAndroid Build Coastguard Worker 92*9880d681SAndroid Build Coastguard Workertrue: 93*9880d681SAndroid Build Coastguard Worker call void @test_true() 94*9880d681SAndroid Build Coastguard Worker ret void 95*9880d681SAndroid Build Coastguard Worker 96*9880d681SAndroid Build Coastguard Workerfalse: 97*9880d681SAndroid Build Coastguard Worker call void @test_false() 98*9880d681SAndroid Build Coastguard Worker ret void 99*9880d681SAndroid Build Coastguard Worker} 100*9880d681SAndroid Build Coastguard Worker 101*9880d681SAndroid Build Coastguard Workerdefine void @test_CBNZ_fallthrough_taken(i32 %in) nounwind { 102*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: test_CBNZ_fallthrough_taken: 103*9880d681SAndroid Build Coastguard Worker %tst = icmp ne i32 %in, 0 104*9880d681SAndroid Build Coastguard Worker br i1 %tst, label %true, label %false, !prof !0 105*9880d681SAndroid Build Coastguard Worker 106*9880d681SAndroid Build Coastguard Worker; CHECK: cbz {{w[0-9]+}}, [[FALSE:.LBB[0-9]+_[0-9]+]] 107*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: // BB# 108*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: bl test_true 109*9880d681SAndroid Build Coastguard Worker 110*9880d681SAndroid Build Coastguard Worker; CHECK: [[FALSE]]: 111*9880d681SAndroid Build Coastguard Worker; CHECK: bl test_false 112*9880d681SAndroid Build Coastguard Worker 113*9880d681SAndroid Build Coastguard Workertrue: 114*9880d681SAndroid Build Coastguard Worker call void @test_true() 115*9880d681SAndroid Build Coastguard Worker ret void 116*9880d681SAndroid Build Coastguard Worker 117*9880d681SAndroid Build Coastguard Workerfalse: 118*9880d681SAndroid Build Coastguard Worker call void @test_false() 119*9880d681SAndroid Build Coastguard Worker ret void 120*9880d681SAndroid Build Coastguard Worker} 121*9880d681SAndroid Build Coastguard Worker 122*9880d681SAndroid Build Coastguard Workerdefine void @test_CBNZ_fallthrough_nottaken(i64 %in) nounwind { 123*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: test_CBNZ_fallthrough_nottaken: 124*9880d681SAndroid Build Coastguard Worker %tst = icmp ne i64 %in, 0 125*9880d681SAndroid Build Coastguard Worker br i1 %tst, label %true, label %false, !prof !1 126*9880d681SAndroid Build Coastguard Worker 127*9880d681SAndroid Build Coastguard Worker; CHECK: cbnz {{x[0-9]+}}, [[TRUE:.LBB[0-9]+_[0-9]+]] 128*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: // BB# 129*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: bl test_false 130*9880d681SAndroid Build Coastguard Worker 131*9880d681SAndroid Build Coastguard Worker; CHECK: [[TRUE]]: 132*9880d681SAndroid Build Coastguard Worker; CHECK: bl test_true 133*9880d681SAndroid Build Coastguard Worker 134*9880d681SAndroid Build Coastguard Workertrue: 135*9880d681SAndroid Build Coastguard Worker call void @test_true() 136*9880d681SAndroid Build Coastguard Worker ret void 137*9880d681SAndroid Build Coastguard Worker 138*9880d681SAndroid Build Coastguard Workerfalse: 139*9880d681SAndroid Build Coastguard Worker call void @test_false() 140*9880d681SAndroid Build Coastguard Worker ret void 141*9880d681SAndroid Build Coastguard Worker} 142*9880d681SAndroid Build Coastguard Worker 143*9880d681SAndroid Build Coastguard Workerdefine void @test_TBZ_fallthrough_taken(i32 %in) nounwind { 144*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: test_TBZ_fallthrough_taken: 145*9880d681SAndroid Build Coastguard Worker %bit = and i32 %in, 32768 146*9880d681SAndroid Build Coastguard Worker %tst = icmp eq i32 %bit, 0 147*9880d681SAndroid Build Coastguard Worker br i1 %tst, label %true, label %false, !prof !0 148*9880d681SAndroid Build Coastguard Worker 149*9880d681SAndroid Build Coastguard Worker; CHECK: tbnz {{w[0-9]+}}, #15, [[FALSE:.LBB[0-9]+_[0-9]+]] 150*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: // BB# 151*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: bl test_true 152*9880d681SAndroid Build Coastguard Worker 153*9880d681SAndroid Build Coastguard Worker; CHECK: [[FALSE]]: 154*9880d681SAndroid Build Coastguard Worker; CHECK: bl test_false 155*9880d681SAndroid Build Coastguard Worker 156*9880d681SAndroid Build Coastguard Workertrue: 157*9880d681SAndroid Build Coastguard Worker call void @test_true() 158*9880d681SAndroid Build Coastguard Worker ret void 159*9880d681SAndroid Build Coastguard Worker 160*9880d681SAndroid Build Coastguard Workerfalse: 161*9880d681SAndroid Build Coastguard Worker call void @test_false() 162*9880d681SAndroid Build Coastguard Worker ret void 163*9880d681SAndroid Build Coastguard Worker} 164*9880d681SAndroid Build Coastguard Worker 165*9880d681SAndroid Build Coastguard Workerdefine void @test_TBZ_fallthrough_nottaken(i64 %in) nounwind { 166*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: test_TBZ_fallthrough_nottaken: 167*9880d681SAndroid Build Coastguard Worker %bit = and i64 %in, 32768 168*9880d681SAndroid Build Coastguard Worker %tst = icmp eq i64 %bit, 0 169*9880d681SAndroid Build Coastguard Worker br i1 %tst, label %true, label %false, !prof !1 170*9880d681SAndroid Build Coastguard Worker 171*9880d681SAndroid Build Coastguard Worker; CHECK: tbz {{[wx][0-9]+}}, #15, [[TRUE:.LBB[0-9]+_[0-9]+]] 172*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: // BB# 173*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: bl test_false 174*9880d681SAndroid Build Coastguard Worker 175*9880d681SAndroid Build Coastguard Worker; CHECK: [[TRUE]]: 176*9880d681SAndroid Build Coastguard Worker; CHECK: bl test_true 177*9880d681SAndroid Build Coastguard Worker 178*9880d681SAndroid Build Coastguard Workertrue: 179*9880d681SAndroid Build Coastguard Worker call void @test_true() 180*9880d681SAndroid Build Coastguard Worker ret void 181*9880d681SAndroid Build Coastguard Worker 182*9880d681SAndroid Build Coastguard Workerfalse: 183*9880d681SAndroid Build Coastguard Worker call void @test_false() 184*9880d681SAndroid Build Coastguard Worker ret void 185*9880d681SAndroid Build Coastguard Worker} 186*9880d681SAndroid Build Coastguard Worker 187*9880d681SAndroid Build Coastguard Worker 188*9880d681SAndroid Build Coastguard Workerdefine void @test_TBNZ_fallthrough_taken(i32 %in) nounwind { 189*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: test_TBNZ_fallthrough_taken: 190*9880d681SAndroid Build Coastguard Worker %bit = and i32 %in, 32768 191*9880d681SAndroid Build Coastguard Worker %tst = icmp ne i32 %bit, 0 192*9880d681SAndroid Build Coastguard Worker br i1 %tst, label %true, label %false, !prof !0 193*9880d681SAndroid Build Coastguard Worker 194*9880d681SAndroid Build Coastguard Worker; CHECK: tbz {{w[0-9]+}}, #15, [[FALSE:.LBB[0-9]+_[0-9]+]] 195*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: // BB# 196*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: bl test_true 197*9880d681SAndroid Build Coastguard Worker 198*9880d681SAndroid Build Coastguard Worker; CHECK: [[FALSE]]: 199*9880d681SAndroid Build Coastguard Worker; CHECK: bl test_false 200*9880d681SAndroid Build Coastguard Worker 201*9880d681SAndroid Build Coastguard Workertrue: 202*9880d681SAndroid Build Coastguard Worker call void @test_true() 203*9880d681SAndroid Build Coastguard Worker ret void 204*9880d681SAndroid Build Coastguard Worker 205*9880d681SAndroid Build Coastguard Workerfalse: 206*9880d681SAndroid Build Coastguard Worker call void @test_false() 207*9880d681SAndroid Build Coastguard Worker ret void 208*9880d681SAndroid Build Coastguard Worker} 209*9880d681SAndroid Build Coastguard Worker 210*9880d681SAndroid Build Coastguard Workerdefine void @test_TBNZ_fallthrough_nottaken(i64 %in) nounwind { 211*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: test_TBNZ_fallthrough_nottaken: 212*9880d681SAndroid Build Coastguard Worker %bit = and i64 %in, 32768 213*9880d681SAndroid Build Coastguard Worker %tst = icmp ne i64 %bit, 0 214*9880d681SAndroid Build Coastguard Worker br i1 %tst, label %true, label %false, !prof !1 215*9880d681SAndroid Build Coastguard Worker 216*9880d681SAndroid Build Coastguard Worker; CHECK: tbnz {{[wx][0-9]+}}, #15, [[TRUE:.LBB[0-9]+_[0-9]+]] 217*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: // BB# 218*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: bl test_false 219*9880d681SAndroid Build Coastguard Worker 220*9880d681SAndroid Build Coastguard Worker; CHECK: [[TRUE]]: 221*9880d681SAndroid Build Coastguard Worker; CHECK: bl test_true 222*9880d681SAndroid Build Coastguard Worker 223*9880d681SAndroid Build Coastguard Workertrue: 224*9880d681SAndroid Build Coastguard Worker call void @test_true() 225*9880d681SAndroid Build Coastguard Worker ret void 226*9880d681SAndroid Build Coastguard Worker 227*9880d681SAndroid Build Coastguard Workerfalse: 228*9880d681SAndroid Build Coastguard Worker call void @test_false() 229*9880d681SAndroid Build Coastguard Worker ret void 230*9880d681SAndroid Build Coastguard Worker} 231*9880d681SAndroid Build Coastguard Worker 232