2. On subsequent iterations: Use %12 (updated value from bb7)
**What's happening**:
- %3 always resolves to 0 (initial value from %2)
- The incoming value from bb7 (%12) is not being properly connected
- Loop variable never increments → infinite loop
### Suspected Code Location
In `finalize_phis()` around lines 670-688:
```python
chosen: Dict[int, ir.Value] = {}
for (b_decl, v_src) in incoming:
try:
bd = int(b_decl); vs = int(v_src)
except Exception:
continue
pred_match = nearest_pred_on_path(bd)
if pred_match is None:
continue
# If self-carry is specified (vs == dst_vid), map to init_src_vid when available
if vs == int(dst_vid) and init_src_vid is not None:
vs = int(init_src_vid) # ← SUSPICIOUS: May cause %12 to be ignored
try:
val = self.resolver._value_at_end_i64(vs, pred_match, self.preds, self.block_end_values, self.vmap, self.bb_map)
except Exception:
val = None
if val is None:
val = ir.Constant(self.i64, 0) # ← Falls back to 0
chosen[pred_match] = val
```
### Hypothesis
The self-carry logic (lines 679-681) or value resolution (line 683) may be incorrectly mapping or failing to retrieve %12 from bb7, causing the PHI to always use the fallback value of 0.
## Next Steps
### Immediate Action Required
1.**Add Trace Logging**:
- Enable `NYASH_CLI_VERBOSE=1` or similar PHI-specific tracing
- Log what values are being wired to each PHI incoming edge
2.**Minimal Fix Verification**:
- Verify `_value_at_end_i64(12, 7, ...)` returns the correct LLVM value
- Check if `nearest_pred_on_path()` correctly identifies bb7 as predecessor of bb4
3.**Test Matrix**:
- Simple Add: ✅ (already passing)
- Loop Min While: ❌ (currently failing)
- Case A/B2 from previous phases: (regression check needed)