gfx2hlsl: uniform compute load proof (#2607) bypassed at a loop head that narrows EXEC #2749

Closed
opened 2026-11-26 06:19:01 +00:00 by MasterDomino · 1 comment
MasterDomino commented 2026-11-26 06:19:01 +00:00 (Migrated from github.com)
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-26T06:19:01Z.


#2607 (merged as 1c061f87) lets a buffer load past the entry block feed v_readfirstlane_b32 when its address is wave-uniform and EXEC is the entry mask. That entry-EXEC requirement can be bypassed at a loop head. exec_known is tracked in program order, so at the target of an SCC back edge it's still true even when the loop body narrowed EXEC before branching back.

Repro (gfx2hlsl compute stage, driven the same way as the PR's own unit checks):

s_cbranch_scc0 label_0008
s_nop 0
s_buffer_load_dword s3, s[4:7], 0x10
buffer_load_dword v7, off, s[4:7], s3      ; 0xc, back-edge target
v_readfirstlane_b32 s9, v7
s_add_u32 s3, s3, 4
v_cmp_lt_f32_e32 vcc_lo, v0, v1
s_and_b32 exec_lo, exec_lo, vcc_lo
s_cmp_lt_u32 s3, 64
s_cbranch_scc1 label_000c
s_endpgm
translator result
59218765 (just before #2607) REFUSED: v_readfirstlane_b32 requires a proven uniform source
1c061f87 / main c8b7b973 accepted: v7 = r0.Load(a + 0); ulc_7 = r0.Load(a + 0); s9 = ulc_7;, unguarded

Why it's wrong. On a pass where the body left EXEC empty, the hardware's v_readfirstlane returns lane 0's v7 from the previous pass. The translation reloads at the new s3 instead. That's the case #2607's empty and potentially-empty EXEC refusals are meant to exclude.

Suggested fix.

  • Refuse: refuse the load proof when a back edge into a target at or before the load comes from a body that may write EXEC, or stop treating exec as known at such targets.
  • Control: add this program as a refusal control.

Related, for whoever picks this up:

  • Cache revision: #2607 emits the ulc_N temporary for every qualifying load past the entry block, whether or not anything reads it. Programs that translated before therefore emit different HLSL. For example, s_cbranch_scc0; s_nop; s_buffer_load_dword s3; buffer_load_dword v7, off, s[4:7], s3; v_add_f32 v1, v7, v1 gains ulc_7 = r0.Load(a + 0);. That would normally come with a compute cache revision bump; main has since moved to 19cs with #2708, which re-keys those entries anyway.
  • Pre-existing: separately, main emits unguarded VGPR writes in such a loop even without a readfirstlane (for example v1 = U(F(v6) + F(v1))). Fixing that changes emitted HLSL and needs its own revision bump.
  • No D3D12 readback: every #2607 check compares emitted text. A WARP/hardware case with a uniform load past a branch, a readfirstlane and a store of s9 from every lane against a CPU reference would test the lowering itself, as tedin7 asked on the PR.

@NiiRoZz @R0Y00: found in our review of #2607, which finished just after the merge. The probe is the PR's own translate() text harness, not a GPU run.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6620807150 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/2757). Originally posted by [MasterDomino](https://github.com/MasterDomino) on 2026-11-26T06:19:01Z. --- #2607 (merged as `1c061f87`) lets a buffer load past the entry block feed `v_readfirstlane_b32` when its address is wave-uniform and EXEC is the entry mask. That entry-EXEC requirement can be bypassed at a loop head. `exec_known` is tracked in program order, so at the target of an SCC back edge it's still true even when the loop body narrowed EXEC before branching back. **Repro** (gfx2hlsl compute stage, driven the same way as the PR's own unit checks): ``` s_cbranch_scc0 label_0008 s_nop 0 s_buffer_load_dword s3, s[4:7], 0x10 buffer_load_dword v7, off, s[4:7], s3 ; 0xc, back-edge target v_readfirstlane_b32 s9, v7 s_add_u32 s3, s3, 4 v_cmp_lt_f32_e32 vcc_lo, v0, v1 s_and_b32 exec_lo, exec_lo, vcc_lo s_cmp_lt_u32 s3, 64 s_cbranch_scc1 label_000c s_endpgm ``` | translator | result | |---|---| | `59218765` (just before #2607) | `REFUSED: v_readfirstlane_b32 requires a proven uniform source` | | `1c061f87` / `main` `c8b7b973` | accepted: `v7 = r0.Load(a + 0); ulc_7 = r0.Load(a + 0); s9 = ulc_7;`, unguarded | **Why it's wrong.** On a pass where the body left EXEC empty, the hardware's `v_readfirstlane` returns lane 0's `v7` from the previous pass. The translation reloads at the new `s3` instead. That's the case #2607's empty and potentially-empty EXEC refusals are meant to exclude. **Suggested fix.** - **Refuse:** refuse the load proof when a back edge into a target at or before the load comes from a body that may write EXEC, or stop treating `exec` as known at such targets. - **Control:** add this program as a refusal control. **Related, for whoever picks this up:** - **Cache revision:** #2607 emits the `ulc_N` temporary for every qualifying load past the entry block, whether or not anything reads it. Programs that translated before therefore emit different HLSL. For example, `s_cbranch_scc0; s_nop; s_buffer_load_dword s3; buffer_load_dword v7, off, s[4:7], s3; v_add_f32 v1, v7, v1` gains `ulc_7 = r0.Load(a + 0);`. That would normally come with a compute cache revision bump; `main` has since moved to `19cs` with #2708, which re-keys those entries anyway. - **Pre-existing:** separately, `main` emits unguarded VGPR writes in such a loop even without a readfirstlane (for example `v1 = U(F(v6) + F(v1))`). Fixing that changes emitted HLSL and needs its own revision bump. - **No D3D12 readback:** every #2607 check compares emitted text. A WARP/hardware case with a uniform load past a branch, a readfirstlane and a store of `s9` from every lane against a CPU reference would test the lowering itself, as tedin7 asked on the PR. @NiiRoZz @R0Y00: found in our review of #2607, which finished just after the merge. The probe is the PR's own `translate()` text harness, not a GPU run. AI-assisted; commands listed were executed locally.
RavenCurseBurg commented 2026-11-26 07:00:28 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by RavenCurseBurg on 2026-11-26T06:38:58Z.


I will take the past-entry uniform buffer-load proof at loop heads. I will pin the reported backward SCC branch, check neighbouring loops with an unchanged EXEC mask and forward-only loads, and submit a focused fix based on main e3cf6a91. I have Windows 11, Python, LLVM 15, WARP, Intel UHD 770 and RTX 4060 available. The separate general VGPR-write question can be tracked independently.

AI-assisted with Codex.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7184639347 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/2757#issuecomment-7184639347). Originally posted by [RavenCurseBurg](https://github.com/RavenCurseBurg) on 2026-11-26T06:38:58Z. --- I will take the past-entry uniform buffer-load proof at loop heads. I will pin the reported backward SCC branch, check neighbouring loops with an unchanged EXEC mask and forward-only loads, and submit a focused fix based on main e3cf6a91. I have Windows 11, Python, LLVM 15, WARP, Intel UHD 770 and RTX 4060 available. The separate general VGPR-write question can be tracked independently. AI-assisted with Codex.
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
R0Y00/Xbox2Windows#2749
No description provided.