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

Open
AscilCH wants to merge 1 commit from upstream-pr/443 into main
AscilCH commented 2026-11-25 00:52:33 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by AscilCH on 2026-11-25T00:52:33Z.


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.)

<!-- greyfinch-sync:fxceless/victory-fork:issue:6594584101 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/443). Originally posted by [AscilCH](https://github.com/AscilCH) on 2026-11-25T00:52:33Z. --- ## 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.)*
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/443:upstream-pr/443'
git switch 'upstream-pr/443'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/443'
git switch 'upstream-pr/443'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/443'
git switch 'upstream-pr/443'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/443'
git switch 'main'
git merge --squash 'upstream-pr/443'
git switch 'main'
git merge --ff-only 'upstream-pr/443'
git switch 'main'
git merge 'upstream-pr/443'
git push origin 'main'
Sign in to join this conversation.
No reviewers
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
fxceless/victory-fork!443
No description provided.