65816-llvm-mos/src/llvm/test/CodeGen/W65816/cmp0-carry-branch.mir

85 lines
2.2 KiB
YAML

# Pin: W65816StackSlotCleanup Pass 1c drops `CMPi16imm $a, 0` after an op
# that already set N/Z from A, but only when the branch it feeds reads N or
# Z. `cmp #0` also sets C (always 1), so before a BCC/BCS the CMP is the
# carry's only source and has to stay.
#
# The pre-2026-09-28 i32 compare lowering emitted exactly this shape for the
# high half of an unsigned compare against a 16-bit constant (`hi <u 0`,
# i.e. `lda hi ; cmp #0 ; bcc`). With the CMP erased the BCC tested a stale
# carry, and `x >= 0x8000`, `x > 1`, `x < 0xFFFF` ... on a uint32_t took
# the wrong branch whenever x had a non-zero high half.
#
# keep_bcc: CMP #0 before BCC stays.
# keep_bcs: CMP #0 before BCS stays.
# drop_beq: CMP #0 before BEQ still goes (the LDA's Z is the same).
#
# RUN: llc -mtriple=w65816 -run-pass=w65816-stack-slot-cleanup -o - %s | FileCheck %s
--- |
target triple = "w65816"
define void @keep_bcc() { ret void }
define void @keep_bcs() { ret void }
define void @drop_beq() { ret void }
...
---
# CHECK-LABEL: name: keep_bcc
# CHECK: $a = LDAfi %stack.0, 0
# CHECK-NEXT: CMPi16imm killed $a, 0, implicit-def $p
# CHECK-NEXT: BCC %bb.1, implicit $p
name: keep_bcc
tracksRegLiveness: false
stack:
- { id: 0, size: 2, alignment: 1 }
body: |
bb.0:
successors: %bb.1, %bb.2
$a = LDAfi %stack.0, 0
CMPi16imm killed $a, 0, implicit-def $p
BCC %bb.1, implicit $p
BRA %bb.2
bb.1:
RTL
bb.2:
RTL
...
---
# CHECK-LABEL: name: keep_bcs
# CHECK: $a = LDAfi %stack.0, 0
# CHECK-NEXT: CMPi16imm killed $a, 0, implicit-def $p
# CHECK-NEXT: BCS %bb.1, implicit $p
name: keep_bcs
tracksRegLiveness: false
stack:
- { id: 0, size: 2, alignment: 1 }
body: |
bb.0:
successors: %bb.1, %bb.2
$a = LDAfi %stack.0, 0
CMPi16imm killed $a, 0, implicit-def $p
BCS %bb.1, implicit $p
BRA %bb.2
bb.1:
RTL
bb.2:
RTL
...
---
# CHECK-LABEL: name: drop_beq
# CHECK: $a = LDAfi %stack.0, 0
# CHECK-NOT: CMPi16imm
# CHECK: BEQ %bb.1, implicit $p
name: drop_beq
tracksRegLiveness: false
stack:
- { id: 0, size: 2, alignment: 1 }
body: |
bb.0:
successors: %bb.1, %bb.2
$a = LDAfi %stack.0, 0
CMPi16imm killed $a, 0, implicit-def $p
BEQ %bb.1, implicit $p
BRA %bb.2
bb.1:
RTL
bb.2:
RTL
...