; Pin: SepRepCleanup's redundant-LDY elision must clear the now-stale
; `killed $y` flag on the prior Y-user.
;
; Trigger: any sequence that emits two LDY_Imm16 #N back-to-back with
; STA [dp],y between (e.g. an i32 store that splits into two i16
; stores, each going through STAptr32 inserter which emits its own
; LDY #0).  Without the fix, the third peephole at SepRepCleanup
; deletes the second LDY, but the first STA's `implicit killed $y`
; annotation was set under the assumption that the second LDY was
; about to redefine Y — leaving the second STA reading "dead" Y.
;
; The fix walks backward from the erased LDY to the most recent
; Y-using operand and clears its kill flag.  -verify-machineinstrs
; catches the bug if it regresses.
;
; RUN: llc -mtriple=w65816 -O2 -verify-machineinstrs < %s | FileCheck %s

define void @two_i32_stores_share_y(ptr %p) {
; CHECK-LABEL: two_i32_stores_share_y:
; The fix is invisible in asm output — both STAs emit identically with
; or without the kill-flag fix.  The pin is `-verify-machineinstrs`
; not aborting.  Match a minimal shape so the test still has structure.
; CHECK:       ldy #0x0
; CHECK:       sta [0xe0
; CHECK:       sta [0xe0
; CHECK:       rtl
  store i32 0, ptr %p
  ret void
}
