1*9880d681SAndroid Build Coastguard Worker; RUN: llc -verify-machineinstrs -o - %s | FileCheck %s 2*9880d681SAndroid Build Coastguard Workertarget triple = "arm64--" 3*9880d681SAndroid Build Coastguard Worker 4*9880d681SAndroid Build Coastguard Worker; AArch64InstrInfo::optimizeCondBranch() optimizes the 5*9880d681SAndroid Build Coastguard Worker; "x = and y, 256; cmp x, 0; br" from an "and; cbnz" to a tbnz instruction. 6*9880d681SAndroid Build Coastguard Worker; It forgot to clear the a flag resulting in a MachineVerifier complaint. 7*9880d681SAndroid Build Coastguard Worker; 8*9880d681SAndroid Build Coastguard Worker; Writing a stable/simple test is tricky since most tbz instructions are already 9*9880d681SAndroid Build Coastguard Worker; formed in SelectionDAG, optimizeCondBranch() only triggers if the and 10*9880d681SAndroid Build Coastguard Worker; instruction is in a different block than the conditional jump. 11*9880d681SAndroid Build Coastguard Worker; 12*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: func 13*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: and 14*9880d681SAndroid Build Coastguard Worker; CHECK: tbnz 15*9880d681SAndroid Build Coastguard Workerdefine void @func() { 16*9880d681SAndroid Build Coastguard Worker %c0 = icmp sgt i64 0, 0 17*9880d681SAndroid Build Coastguard Worker br i1 %c0, label %b1, label %b6 18*9880d681SAndroid Build Coastguard Worker 19*9880d681SAndroid Build Coastguard Workerb1: 20*9880d681SAndroid Build Coastguard Worker br i1 undef, label %b3, label %b2 21*9880d681SAndroid Build Coastguard Worker 22*9880d681SAndroid Build Coastguard Workerb2: 23*9880d681SAndroid Build Coastguard Worker %v0 = tail call i32 @extfunc() 24*9880d681SAndroid Build Coastguard Worker br label %b5 25*9880d681SAndroid Build Coastguard Worker 26*9880d681SAndroid Build Coastguard Workerb3: 27*9880d681SAndroid Build Coastguard Worker %v1 = load i32, i32* undef, align 4 28*9880d681SAndroid Build Coastguard Worker %v2 = and i32 %v1, 256 29*9880d681SAndroid Build Coastguard Worker br label %b5 30*9880d681SAndroid Build Coastguard Worker 31*9880d681SAndroid Build Coastguard Workerb5: 32*9880d681SAndroid Build Coastguard Worker %v3 = phi i32 [ %v2, %b3 ], [ %v0, %b2 ] 33*9880d681SAndroid Build Coastguard Worker %c1 = icmp eq i32 %v3, 0 34*9880d681SAndroid Build Coastguard Worker br i1 %c1, label %b8, label %b7 35*9880d681SAndroid Build Coastguard Worker 36*9880d681SAndroid Build Coastguard Workerb6: 37*9880d681SAndroid Build Coastguard Worker tail call i32 @extfunc() 38*9880d681SAndroid Build Coastguard Worker ret void 39*9880d681SAndroid Build Coastguard Worker 40*9880d681SAndroid Build Coastguard Workerb7: 41*9880d681SAndroid Build Coastguard Worker tail call i32 @extfunc() 42*9880d681SAndroid Build Coastguard Worker ret void 43*9880d681SAndroid Build Coastguard Worker 44*9880d681SAndroid Build Coastguard Workerb8: 45*9880d681SAndroid Build Coastguard Worker ret void 46*9880d681SAndroid Build Coastguard Worker} 47*9880d681SAndroid Build Coastguard Worker 48*9880d681SAndroid Build Coastguard Workerdeclare i32 @extfunc() 49