Shaders/ir: keep skips when body can resurrect EXEC or has scalar side effects #443

Open
github-bot wants to merge 1 commit from github-bot/gh-443 into main AGit
Owner

@⁠AscilCH on GitHub · 2026-11-25 00:52 UTC · original
AscilCH:fix/shader-ir-without-skips-exec-and-scalar-effects → main · +429 −7 · 1 files · 1 commits · open

Problem

In crates/victory-shader/src/ir.rs, without_skips removes s_cbranch_execz branches so waves with EXEC == 0 fall through and execute the skipped region inside. Previously:

  1. Unchecked EXEC resurrection: skipped() exempted Reg::S(126 | 127) (EXEC_LO/EXEC_HI) from join-phi checks without verifying that inside preserves EXEC == 0. If inside restored an outer saved EXEC (s_mov_b64 exec, s[12:13]) or widened EXEC (s_or_b64, s_not_b64, s_andn2_b64 exec, s[12:13], exec, etc.), removing s_cbranch_execz resurrected skipped lanes inside inside (executing vector stores/writes on skipped lanes and arriving at the join with non-zero EXEC).
  2. Unchecked EXEC-independent scalar side effects: skipped() did not reject s_store_*/s_buffer_store_*/s_scratch_store_*/s_atomic_*/s_buffer_atomic_*, s_sendmsg/s_sendmsghalt, s_barrier, or s_round_mode/s_denorm_mode inside inside, all of which execute even when EXEC == 0.

Fix

  • Reject skipped() if any block in inside contains an EXEC-independent scalar side effect (s_*store*, s_*atomic*, s_sendmsg*, s_barrier, s_round_mode, s_denorm_mode).
  • Track values that may be nonzero when EXEC enters inside as 0 (least fixpoint, with only the s_cbranch_execz's own EXEC dwords known zero on entry), preserving zero across narrowing v_cmpx_*, s_and*/s_andn2*, s_mov_b32/s_mov_b64, and pure whole-wave sections (s_or_saveexec/s_nand_saveexec paired with an exact full-width restore and no side effects). Reject if any EXEC write/phi outside pure whole-wave sections or incoming EXEC join phi can become nonzero, or if a join VGPR phi receives a write from inside a whole-wave section.
  • Add synthetic unit test a_skip_is_kept_when_body_resurrects_exec_or_has_scalar_side_effects.

Verification

  • cargo test -p victory-shader --locked ir::tests: 8 passed, 0 failed
  • cargo test -p victory-shader --locked wave64_tests: 5 passed, 0 failed
  • cargo xtask policy: 169 files ok
  • cargo clippy -p victory-shader --all-targets --locked -- -D warnings: clean
  • cargo clippy -p victory-shader --all-targets --all-features --locked -- -D warnings: clean

(AI-assisted; synthetic unit tests only, no game data.)

**@⁠AscilCH** on GitHub · 2026-11-25 00:52 UTC · [original](https://github.com/fxceless/victory-fork/pull/443) `AscilCH:fix/shader-ir-without-skips-exec-and-scalar-effects` → `main` · +429 −7 · 1 files · 1 commits · open ## Problem In `crates/victory-shader/src/ir.rs`, `without_skips` removes `s_cbranch_execz` branches so waves with `EXEC == 0` fall through and execute the skipped region `inside`. Previously: 1. **Unchecked `EXEC` resurrection**: `skipped()` exempted `Reg::S(126 | 127)` (`EXEC_LO`/`EXEC_HI`) from join-phi checks without verifying that `inside` preserves `EXEC == 0`. If `inside` restored an outer saved `EXEC` (`s_mov_b64 exec, s[12:13]`) or widened `EXEC` (`s_or_b64`, `s_not_b64`, `s_andn2_b64 exec, s[12:13], exec`, etc.), removing `s_cbranch_execz` resurrected skipped lanes inside `inside` (executing vector stores/writes on skipped lanes and arriving at the join with non-zero `EXEC`). 2. **Unchecked EXEC-independent scalar side effects**: `skipped()` did not reject `s_store_*`/`s_buffer_store_*`/`s_scratch_store_*`/`s_atomic_*`/`s_buffer_atomic_*`, `s_sendmsg`/`s_sendmsghalt`, `s_barrier`, or `s_round_mode`/`s_denorm_mode` inside `inside`, all of which execute even when `EXEC == 0`. ## Fix - Reject `skipped()` if any block in `inside` contains an EXEC-independent scalar side effect (`s_*store*`, `s_*atomic*`, `s_sendmsg*`, `s_barrier`, `s_round_mode`, `s_denorm_mode`). - Track values that may be nonzero when `EXEC` enters `inside` as `0` (least fixpoint, with only the `s_cbranch_execz`'s own `EXEC` dwords known zero on entry), preserving zero across narrowing `v_cmpx_*`, `s_and*`/`s_andn2*`, `s_mov_b32`/`s_mov_b64`, and pure whole-wave sections (`s_or_saveexec`/`s_nand_saveexec` paired with an exact full-width restore and no side effects). Reject if any `EXEC` write/phi outside pure whole-wave sections or incoming `EXEC` join phi can become nonzero, or if a join VGPR phi receives a write from inside a whole-wave section. - Add synthetic unit test `a_skip_is_kept_when_body_resurrects_exec_or_has_scalar_side_effects`. ## Verification - `cargo test -p victory-shader --locked ir::tests`: 8 passed, 0 failed - `cargo test -p victory-shader --locked wave64_tests`: 5 passed, 0 failed - `cargo xtask policy`: 169 files ok - `cargo clippy -p victory-shader --all-targets --locked -- -D warnings`: clean - `cargo clippy -p victory-shader --all-targets --all-features --locked -- -D warnings`: clean *(AI-assisted; synthetic unit tests only, no game data.)*
In `ir::without_skips`, removing `s_cbranch_execz` causes waves with `EXEC == 0` to fall through and execute the skipped region `inside`. Previously `skipped()` exempted `Reg::S(126 | 127)` (`EXEC_LO`/`EXEC_HI`) from join-phi checks without verifying that `inside` keeps `EXEC == 0`, and did not check `inside` for EXEC-independent scalar side effects.

1. Reject skipping regions containing EXEC-independent scalar side effects (`s_store_*`, `s_buffer_store_*`, `s_scratch_store_*`, `s_atomic_*`, `s_buffer_atomic_*`, `s_sendmsg`, `s_sendmsghalt`, `s_barrier`, `s_round_mode`, `s_denorm_mode`).
2. Compute a least fixpoint of values inside `inside` that may be nonzero when `EXEC` enters as `0` (seeded with external values other than the skip branch's own `EXEC` dwords), propagating zero through narrowing `v_cmpx_*`, `s_and*`/`s_andn2*`, `s_mov_b32`/`s_mov_b64`, and pure whole-wave sections (`s_or_saveexec`/`s_nand_saveexec` paired with an exact full-width restore). Reject if any `EXEC` write or phi inside `inside` (outside a pure whole-wave section) or incoming `EXEC` phi at `target` can become nonzero, or if a live VGPR phi at `target` takes a value written inside a whole-wave section.
3. Add synthetic unit tests verifying outer-EXEC restores, `s_or_b64`/`s_andn2_b64` EXEC widening, inner narrowing (still allowed), `s_sendmsg`, `s_barrier`, and `s_buffer_store_dword`.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:43:26 +00:00
This pull request has changes conflicting with the target branch.
  • crates/victory-shader/src/ir.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/443/head:github-bot/gh-443'
git switch 'github-bot/gh-443'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-443'
git switch 'github-bot/gh-443'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-443'
git switch 'github-bot/gh-443'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-443'
git switch 'main'
git merge --squash 'github-bot/gh-443'
git switch 'main'
git merge --ff-only 'github-bot/gh-443'
git switch 'main'
git merge 'github-bot/gh-443'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.