1; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py 2; RUN: llc -verify-machineinstrs -o - %s | FileCheck %s 3target triple = "arm64--" 4 5; AArch64InstrInfo::optimizeCondBranch() optimizes the 6; "x = and y, 256; cmp x, 0; br" from an "and; cbnz" to a tbnz instruction. 7; It forgot to clear the a flag resulting in a MachineVerifier complaint. 8; 9; Writing a stable/simple test is tricky since most tbz instructions are already 10; formed in SelectionDAG, optimizeCondBranch() only triggers if the and 11; instruction is in a different block than the conditional jump. 12 13define void @func() uwtable { 14; CHECK-LABEL: func: 15; CHECK: // %bb.0: 16; CHECK-NEXT: mov w8, #1 17; CHECK-NEXT: cbnz w8, .LBB0_3 18; CHECK-NEXT: // %bb.1: // %b1 19; CHECK-NEXT: str x30, [sp, #-16]! // 8-byte Folded Spill 20; CHECK-NEXT: .cfi_def_cfa_offset 16 21; CHECK-NEXT: .cfi_offset w30, -16 22; CHECK-NEXT: .cfi_remember_state 23; CHECK-NEXT: cbz wzr, .LBB0_4 24; CHECK-NEXT: // %bb.2: // %b3 25; CHECK-NEXT: ldr w8, [x8] 26; CHECK-NEXT: and w0, w8, #0x100 27; CHECK-NEXT: ldr x30, [sp], #16 // 8-byte Folded Reload 28; CHECK-NEXT: .cfi_def_cfa_offset 0 29; CHECK-NEXT: .cfi_restore w30 30; CHECK-NEXT: cbz w0, .LBB0_5 31; CHECK-NEXT: .LBB0_3: // %common.ret.sink.split 32; CHECK-NEXT: b extfunc 33; CHECK-NEXT: .LBB0_4: // %b2 34; CHECK-NEXT: .cfi_restore_state 35; CHECK-NEXT: bl extfunc 36; CHECK-NEXT: ldr x30, [sp], #16 // 8-byte Folded Reload 37; CHECK-NEXT: .cfi_def_cfa_offset 0 38; CHECK-NEXT: .cfi_restore w30 39; CHECK-NEXT: cbnz w0, .LBB0_3 40; CHECK-NEXT: .LBB0_5: // %common.ret 41; CHECK-NEXT: ret 42 %c0 = icmp sgt i64 0, 0 43 br i1 %c0, label %b1, label %b6 44 45b1: 46 br i1 undef, label %b3, label %b2 47 48b2: 49 %v0 = tail call i32 @extfunc() 50 br label %b5 51 52b3: 53 %v1 = load i32, i32* undef, align 4 54 %v2 = and i32 %v1, 256 55 br label %b5 56 57b5: 58 %v3 = phi i32 [ %v2, %b3 ], [ %v0, %b2 ] 59 %c1 = icmp eq i32 %v3, 0 60 br i1 %c1, label %b8, label %b7 61 62b6: 63 tail call i32 @extfunc() 64 ret void 65 66b7: 67 tail call i32 @extfunc() 68 ret void 69 70b8: 71 ret void 72} 73 74declare i32 @extfunc() 75