gfx2hlsl: support cascaded else-if EXEC narrowing and balanced save tracking #3804

Manually merged
github merged 5 commits from github-bot/gh-3802 into gh-pr/3802/base 2026-12-03 03:37:07 +00:00 AGit
Owner

@⁠Holastor on GitHub · 2026-12-02 00:18 UTC · original
Holastor:dxil/execz-elseif-cascade → main · +105 −13 · 2 files · 5 commits · merged 2026-12-03 03:30 UTC

Depends on #3802

Summary

Extends Stage.execz_else_branch in tools/startup/gfx2hlsl.py to support cascaded wave-level else-if chains where an inner s_cbranch_execz narrows EXEC after an earlier outer EXEC save (s_mov_b32 sN, exec_lo / s_and_saveexec_b32 sN, ...).

  • Cascaded EXEC narrowing & else_idx scalar prologue (3e49cba4): resolves the dominating saved sN register when guard - 1 narrows EXEC in-place, and permits a pure scalar prologue at else_idx before s_mov_b32 exec_lo, sN.
  • s_andn2_b32 / s_andn2_b64 join restores (fb4b212a): accepts s_andn2_b32 exec_lo, sN, exec_lo (and 64-bit s_andn2_b64) when switching EXEC from the then arm to the outer else arm at join_idx.
  • Balanced EXEC save tracking (94f66241): skips closed inner s_and_saveexec / s_mov_b32 exec_lo, sR pairs during backward save lookup so nested v_cmpx_* / s_and_b32 regions resolve the enclosing active save register sN.
  • Shared epilogue entries (4c699f59): allows unconditional s_branch from < guard into (else_idx, join_idx) when sN is unread in [target, join_idx) and join_idx restores EXEC.

Verification

  • python -B tests/startup_gfx2hlsl_compute_check.py (pass; adds hlsl_cascade_else, hlsl_andn2_join, hlsl_balanced_save, and hlsl_shared_epilogue positive tests plus negative controls for clobbered outer save registers and external s_branch into then)
  • python -B tests/docs_links_check.py (147 Markdown files, 671 links — pass)
  • python -B tests/bidi_controls_check.py (2502 tracked files — pass)
**@⁠Holastor** on GitHub · 2026-12-02 00:18 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3802) `Holastor:dxil/execz-elseif-cascade` → `main` · +105 −13 · 2 files · 5 commits · merged 2026-12-03 03:30 UTC Depends on #3802 ## Summary Extends `Stage.execz_else_branch` in `tools/startup/gfx2hlsl.py` to support cascaded wave-level `else-if` chains where an inner `s_cbranch_execz` narrows `EXEC` after an earlier outer `EXEC` save (`s_mov_b32 sN, exec_lo` / `s_and_saveexec_b32 sN, ...`). - **Cascaded `EXEC` narrowing & `else_idx` scalar prologue (`3e49cba4`):** resolves the dominating saved `sN` register when `guard - 1` narrows `EXEC` in-place, and permits a pure scalar prologue at `else_idx` before `s_mov_b32 exec_lo, sN`. - **`s_andn2_b32` / `s_andn2_b64` join restores (`fb4b212a`):** accepts `s_andn2_b32 exec_lo, sN, exec_lo` (and 64-bit `s_andn2_b64`) when switching `EXEC` from the `then` arm to the outer `else` arm at `join_idx`. - **Balanced `EXEC` save tracking (`94f66241`):** skips closed inner `s_and_saveexec` / `s_mov_b32 exec_lo, sR` pairs during backward save lookup so nested `v_cmpx_*` / `s_and_b32` regions resolve the enclosing active save register `sN`. - **Shared epilogue entries (`4c699f59`):** allows unconditional `s_branch` from `< guard` into `(else_idx, join_idx)` when `sN` is unread in `[target, join_idx)` and `join_idx` restores `EXEC`. ## Verification - `python -B tests/startup_gfx2hlsl_compute_check.py` (pass; adds `hlsl_cascade_else`, `hlsl_andn2_join`, `hlsl_balanced_save`, and `hlsl_shared_epilogue` positive tests plus negative controls for clobbered outer save registers and external `s_branch` into `then`) - `python -B tests/docs_links_check.py` (147 Markdown files, 671 links — pass) - `python -B tests/bidi_controls_check.py` (2502 tracked files — pass)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-02 00:23:38 +00:00
github-bot force-pushed github-bot/gh-3802 from 4c699f5904 to 7e49781da0 2026-12-02 20:46:39 +00:00 Compare
Author
Owner

@⁠R0Y00 on GitHub · 2026-12-02 17:44 UTC · original · requested changes

The four nearby Python suites passed on 569b3785. Two source-built variants still pass the widened EXEC proof. In the CMPX variant, insert s_mov_b32 s21, 0; s_branch 1; s_mov_b32 s21, exec_lo immediately before v_cmpx_lt_u32 v0, 1. The generated HLSL branches around the save and still lowers the later s_cbranch_execz to a per-lane branch using the purported saved mask. In the cascade control, replacing the else-prologue s_nop 0 with s_mov_b32 s21, 0 also translates, and the generated restore becomes exec = (0x00000000u) & 1. Please require the selected save to dominate the guard, and limit the else prologue to scalar operations that leave the saved mask intact. Add both as refusal controls.

**@⁠R0Y00** on GitHub · 2026-12-02 17:44 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3802#pullrequestreview-6155946232) · **requested changes** The four nearby Python suites passed on 569b3785. Two source-built variants still pass the widened EXEC proof. In the CMPX variant, insert `s_mov_b32 s21, 0; s_branch 1; s_mov_b32 s21, exec_lo` immediately before `v_cmpx_lt_u32 v0, 1`. The generated HLSL branches around the save and still lowers the later `s_cbranch_execz` to a per-lane branch using the purported saved mask. In the cascade control, replacing the else-prologue `s_nop 0` with `s_mov_b32 s21, 0` also translates, and the generated restore becomes `exec = (0x00000000u) & 1`. Please require the selected save to dominate the guard, and limit the else prologue to scalar operations that leave the saved mask intact. Add both as refusal controls.
Author
Owner

@⁠Holastor on GitHub · 2026-12-02 20:45 UTC · original

Addressed both review findings in commit 7e49781d:

  1. Dominating save requirement (tools/startup/gfx2hlsl.py): Restricted the backward save scan in Stage.execz_else_branch to stop at any basic-block entry (k + 1 in into) or branch/terminator (s_branch, s_cbranch*, s_setpc*, s_swappc*, s_movrel*, s_call*, s_endpgm, s_rfe) so a bypassed save before v_cmpx_* / narrowing is rejected.
  2. Saved-register integrity in else_idx prologue (tools/startup/gfx2hlsl.py): Rejected scalar instructions in the else_idx prologue before EXEC restoration whenever effects[k][2] & saved is non-empty.
  3. Negative refusal controls (tests/startup_gfx2hlsl_compute_check.py): Added both requested controls (bypassed s_mov_b32 s21, 0; s_branch 1; s_mov_b32 s21, exec_lo before v_cmpx_lt_u32, and s_mov_b32 s21, 0 replacing s_nop 0 in the else_idx prologue); reverting either guard independently fails its matching control.

Verification:

  • python -B tests/startup_gfx2hlsl_compute_check.py — pass
  • python -B tests/docs_links_check.py, tests/bidi_controls_check.py, tests/startup_triage_run_check.py, and tests/startup_gfx2hlsl_refusals_check.py — pass

Ready for re-review (@⁠R0Y00).

**@⁠Holastor** on GitHub · 2026-12-02 20:45 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3802#issuecomment-7358277838) Addressed both review findings in commit `7e49781d`: 1. **Dominating save requirement (`tools/startup/gfx2hlsl.py`):** Restricted the backward save scan in `Stage.execz_else_branch` to stop at any basic-block entry (`k + 1 in into`) or branch/terminator (`s_branch`, `s_cbranch*`, `s_setpc*`, `s_swappc*`, `s_movrel*`, `s_call*`, `s_endpgm`, `s_rfe`) so a bypassed save before `v_cmpx_*` / narrowing is rejected. 2. **Saved-register integrity in `else_idx` prologue (`tools/startup/gfx2hlsl.py`):** Rejected scalar instructions in the `else_idx` prologue before `EXEC` restoration whenever `effects[k][2] & saved` is non-empty. 3. **Negative refusal controls (`tests/startup_gfx2hlsl_compute_check.py`):** Added both requested controls (bypassed `s_mov_b32 s21, 0; s_branch 1; s_mov_b32 s21, exec_lo` before `v_cmpx_lt_u32`, and `s_mov_b32 s21, 0` replacing `s_nop 0` in the `else_idx` prologue); reverting either guard independently fails its matching control. **Verification:** - `python -B tests/startup_gfx2hlsl_compute_check.py` — pass - `python -B tests/docs_links_check.py`, `tests/bidi_controls_check.py`, `tests/startup_triage_run_check.py`, and `tests/startup_gfx2hlsl_refusals_check.py` — pass Ready for re-review (@⁠R0Y00).
github-bot changed target branch from main to gh-pr/3802/base 2026-12-03 03:36:55 +00:00
github manually merged commit 7e49781da0 into gh-pr/3802/base 2026-12-03 03:37:07 +00:00
Author
Owner

@⁠R0Y00 on GitHub · 2026-12-03 03:30 UTC · original · approved these changes

Re-reviewed 7e49781d in a clean trial merge onto 7db6f197 (git diff --cached --check github/main passed). #3802 is in main. This revision addresses both blockers from my review: the backward save scan stops at an intervening block boundary, and the else prologue refuses a write to the saved EXEC mask. I removed each guard independently in the trial tree. Each corresponding source-built control then failed with accepted, expected a refusal, and both pass with the guards restored.

python -B tests/startup_gfx2hlsl_compute_check.py and the adjacent startup_gfx2hlsl_{refusals,spill_branches,loop_constants}_check.py suites passed. With the same trial tree I ran the compute check in dispatch <dxc> <offscreen_check> <adapter> and control m-else-unswitched <dxc> <offscreen_check> <adapter> modes. WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656 each matched 320 words in all 34 dispatch cases and caught the unswitched-else mutant at word 1 (c5c5c5c5 vs fedcba98). Windows build 26300, SDK DXC, D3D12 debug layer enabled, no capability skips.

**@⁠R0Y00** on GitHub · 2026-12-03 03:30 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3802#pullrequestreview-6163238888) · **approved these changes** Re-reviewed `7e49781d` in a clean trial merge onto `7db6f197` (`git diff --cached --check github/main` passed). #3802 is in main. This revision addresses both blockers from my review: the backward save scan stops at an intervening block boundary, and the else prologue refuses a write to the saved EXEC mask. I removed each guard independently in the trial tree. Each corresponding source-built control then failed with `accepted, expected a refusal`, and both pass with the guards restored. `python -B tests/startup_gfx2hlsl_compute_check.py` and the adjacent `startup_gfx2hlsl_{refusals,spill_branches,loop_constants}_check.py` suites passed. With the same trial tree I ran the compute check in `dispatch <dxc> <offscreen_check> <adapter>` and `control m-else-unswitched <dxc> <offscreen_check> <adapter>` modes. WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656 each matched 320 words in all 34 dispatch cases and caught the unswitched-else mutant at word 1 (`c5c5c5c5` vs `fedcba98`). Windows build 26300, SDK DXC, D3D12 debug layer enabled, no capability skips.
This discussion has been locked. Commenting is limited to contributors.
No description provided.