[bug] A guarded write that keeps a refused value reads 0 in the other lanes (wrong accept in write_placed / fill_phis) #256

Open
opened 2026-11-27 05:31:43 +00:00 by LakshanSivakumar · 2 comments
LakshanSivakumar commented 2026-11-27 05:31:43 +00:00 (Migrated from github.com)
Contributor

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-27T05:31:43Z.


What is wrong

Lower::write_placed builds a guarded register write as select(guard, new, old). When old is a join that nothing has read yet, commit a7fc47af un-marks the join as read. fill_phis then puts 0 on an edge that carries a value we refused to translate. So this shape translates on main:

if (c) { x = <an operation we refuse> } else { x = 0 }
... x is read by all lanes

and the then-lanes read 0. A GPU probe with a synthetic program showed it.

a7fc47af's own case is fine: there the kept value is overwritten by an unguarded write before any read. The shortcut is only right when no lane outside the guard reads the kept result.

How many shaders

Measured over the corpus with a lane-aware measurement patch (it tracks the set of lanes that still hold the kept value, and counts a read only if the reader can see such a lane):

Stage Touch the path Would be newly refused (wrong today, or not provable) Provably unaffected
Pixel 952 336 616
Vertex 4 4 0
Compute 6 6 0

The 616 keep their exact output. None of the G-buffer, culling or mesh-record shaders is among the refused. 346 is an upper bound on "wrong today", not a count: many of the 336 are probably harmless but not proven.

The 336 pixel refusals by the refused value they keep: 191 the first half of an interpolation, 69 barycentrics read directly, 52 a descriptor read only as data, 24 a hardware SGPR input.

Plan

  1. Land the lane-aware fix (in progress).
  2. Win back part of the 336 with two rules, each with its own corpus run:
    • quad DPP readers under a guard that is uniform over the quad (65 shaders);
    • helper lanes in whole-quad mode reading what only real pixel lanes wrote.

Related, not yet decided

place_bits and the 16-bit keep also turn a missing old value's kept bits into 0. 794 translating shaders reach that code (almost all v_interp_p2_f16 writing the low half over a dead intermediate). Whether the kept half is ever read is not measured.

Help wanted

Proofs, or counter-examples, for the two win-back rules. A counter-example as a synthetic program is as useful as a proof.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:issue:6640629021 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/256). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-27T05:31:43Z. --- **What is wrong** `Lower::write_placed` builds a guarded register write as `select(guard, new, old)`. When `old` is a join that nothing has read yet, commit a7fc47af un-marks the join as read. `fill_phis` then puts 0 on an edge that carries a value we refused to translate. So this shape translates on main: ``` if (c) { x = <an operation we refuse> } else { x = 0 } ... x is read by all lanes ``` and the then-lanes read 0. A GPU probe with a synthetic program showed it. a7fc47af's own case is fine: there the kept value is overwritten by an unguarded write before any read. The shortcut is only right when no lane outside the guard reads the kept result. **How many shaders** Measured over the corpus with a lane-aware measurement patch (it tracks the set of lanes that still hold the kept value, and counts a read only if the reader can see such a lane): | Stage | Touch the path | Would be newly refused (wrong today, or not provable) | Provably unaffected | |---|---|---|---| | Pixel | 952 | 336 | 616 | | Vertex | 4 | 4 | 0 | | Compute | 6 | 6 | 0 | The 616 keep their exact output. None of the G-buffer, culling or mesh-record shaders is among the refused. 346 is an upper bound on "wrong today", not a count: many of the 336 are probably harmless but not proven. The 336 pixel refusals by the refused value they keep: 191 the first half of an interpolation, 69 barycentrics read directly, 52 a descriptor read only as data, 24 a hardware SGPR input. **Plan** 1. Land the lane-aware fix (in progress). 2. Win back part of the 336 with two rules, each with its own corpus run: - quad DPP readers under a guard that is uniform over the quad (65 shaders); - helper lanes in whole-quad mode reading what only real pixel lanes wrote. **Related, not yet decided** `place_bits` and the 16-bit keep also turn a missing old value's kept bits into 0. 794 translating shaders reach that code (almost all `v_interp_p2_f16` writing the low half over a dead intermediate). Whether the kept half is ever read is not measured. **Help wanted** Proofs, or counter-examples, for the two win-back rules. A counter-example as a synthetic program is as useful as a proof.
gagarinyury commented 2026-11-27 10:30:32 +00:00 (Migrated from github.com)
Author
Contributor

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by gagarinyury on 2026-11-27T10:30:32Z.


/claim

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7215967189 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/256#issuecomment-7215967189). Originally posted by [gagarinyury](https://github.com/gagarinyury) on 2026-11-27T10:30:32Z. --- /claim
github-actions[bot] commented 2026-11-27 10:30:43 +00:00 (Migrated from github.com)
Author
Contributor

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by github-actions[bot] on 2026-11-27T10:30:43Z.


Claimed by @gagarinyury. Open a draft pull request with Refs #256 in its description within 24 hours, or the claim expires.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7215970960 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/256#issuecomment-7215970960). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-11-27T10:30:43Z. --- Claimed by @gagarinyury. Open a draft pull request with `Refs #256` in its description within 24 hours, or the claim expires.
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
LakshanSivakumar/Native-Victory-macOS#256
No description provided.