; Pin: W65816LowerWide32 Pass 2b splits Wide32 PHIs.
;
; Without PHI splitting, an i32 phi (loop-carried 32-bit value)
; survives to RA, hits "Wide32 reload to non-pair reg" UNREACHABLE.
; softDouble at -O2 was the original repro (ma/mb mantissa loops).
;
; This test mimics the shape: an i32 carried across a loop.  If
; LowerWide32 doesn't split the PHI, llc aborts.
;
; RUN: llc -mtriple=w65816 -O2 < %s | FileCheck %s

define i32 @sum_i32_loop(ptr %p, i16 %n) {
; CHECK-LABEL: sum_i32_loop:
; CHECK:       rtl
entry:
  %is_zero = icmp eq i16 %n, 0
  br i1 %is_zero, label %done, label %loop

loop:
  %i   = phi i16 [ 0, %entry ], [ %i.next, %loop ]
  %acc = phi i32 [ 0, %entry ], [ %acc.next, %loop ]
  %addr = getelementptr inbounds i32, ptr %p, i16 %i
  %v   = load i32, ptr %addr
  %acc.next = add i32 %acc, %v
  %i.next   = add i16 %i, 1
  %cond     = icmp eq i16 %i.next, %n
  br i1 %cond, label %done, label %loop

done:
  %r = phi i32 [ 0, %entry ], [ %acc.next, %loop ]
  ret i32 %r
}
