1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -verify-machineinstrs -o - %s | FileCheck %s
3 target triple = "arm64--"
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.
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.
13 define void @func() uwtable {
16 ; CHECK-NEXT: mov w8, #1 // =0x1
17 ; CHECK-NEXT: cbnz w8, .LBB0_3
18 ; CHECK-NEXT: // %bb.1: // %b1
19 ; CHECK-NEXT: cbz wzr, .LBB0_4
20 ; CHECK-NEXT: // %bb.2: // %b3
21 ; CHECK-NEXT: ldr w8, [x8]
22 ; CHECK-NEXT: and w0, w8, #0x100
23 ; CHECK-NEXT: cbz w0, .LBB0_5
24 ; CHECK-NEXT: .LBB0_3: // %common.ret.sink.split
25 ; CHECK-NEXT: b extfunc
26 ; CHECK-NEXT: .LBB0_4: // %b2
27 ; CHECK-NEXT: str x30, [sp, #-16]! // 8-byte Folded Spill
28 ; CHECK-NEXT: .cfi_def_cfa_offset 16
29 ; CHECK-NEXT: .cfi_offset w30, -16
30 ; CHECK-NEXT: bl extfunc
31 ; CHECK-NEXT: ldr x30, [sp], #16 // 8-byte Folded Reload
32 ; CHECK-NEXT: .cfi_def_cfa_offset 0
33 ; CHECK-NEXT: .cfi_restore w30
34 ; CHECK-NEXT: cbnz w0, .LBB0_3
35 ; CHECK-NEXT: .LBB0_5: // %common.ret
37 %c0 = icmp sgt i64 0, 0
38 br i1 %c0, label %b1, label %b6
41 br i1 undef, label %b3, label %b2
44 %v0 = tail call i32 @extfunc()
48 %v1 = load i32, ptr undef, align 4
49 %v2 = and i32 %v1, 256
53 %v3 = phi i32 [ %v2, %b3 ], [ %v0, %b2 ]
54 %c1 = icmp eq i32 %v3, 0
55 br i1 %c1, label %b8, label %b7
58 tail call i32 @extfunc()
62 tail call i32 @extfunc()
69 declare i32 @extfunc()