Shaders: track SGPR origins across cancelling s_xor_b32/b64 swaps (#815) #2387

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

@⁠fuzeofficlal on GitHub · 2026-11-25 12:29 UTC · original
fuzeofficlal:fix/shader-xor-register-exchanges-815 → main · +370 −0 · 2 files · 1 commits · open

Summary

Resolves cancelling s_xor_b32 and s_xor_b64 chains in Tracer::propagate_copies (crates/victory-shader/src/resource.rs) so temporary-free three-XOR SGPR exchanges (a ^= b; b ^= a; a ^= b, including swaps through vcc_lo/vcc_hi and 64-bit SGPR pairs) preserve root-parameter and descriptor origins across loops and control-flow joins.

In the native compute corpus measurements reported in #815 (and #1481 Class C), register permutations emitted via three-XOR exchanges caused root pointers and descriptor words to lose their SSA origin and fail with "an address not from a root parameter" (418 -> 339 -> 64 when including vcc_lo/vcc_hi) or "an address from a phi" (193 -> 24).

Details

  • XOR over 32-bit words is exact GF(2) arithmetic (x ^ x == 0, x ^ 0 == x): Tracer::xor_cancelled collects XOR operands with bounded expansion (MAX_XOR_STEPS = 32, expanding the latest s_xor_b32/s_xor_b64 definition in (rpo[block], inst_index) order so local swaps cancel cleanly without oscillating across loop phis).
  • Cancels paired Values and folds constant terms (NULL, 32-bit inline/literal constants, and sign-extended 64-bit inline integers 128..=208):
    • 0 remaining Values -> Some(Moved::Const(const_acc))
    • 1 remaining Value and const_acc == 0 -> Some(Moved::Value(v))
    • Otherwise None (any non-cancelling XOR remains opaque).

Verification

  • resource::tests::three_xor_swap_tracks_32bit_64bit_and_vcc_exchanges & three_xor_swap_preserves_phi_origins_and_non_cancelling_xor_stays_opaque: cover 32-bit SGPR swaps, 64-bit SGPR pair swaps, vcc_lo (code = 106) swaps, join/loop phi convergence, and negative non-cancelling/mutated-descriptor checks.
  • emit::valu_tests::three_xor_swap_tracks_table_through_vcc_and_64bit_pair: validates DXIL with dxil.dll and executes on both hardware GPU and WARP.
  • cargo clippy -p victory-shader --lib --tests --all-features --locked -- -D warnings & cargo xtask policy pass.

Refs #815, #1481

**@⁠fuzeofficlal** on GitHub · 2026-11-25 12:29 UTC · [original](https://github.com/Marvisak/VIctory/pull/2387) `fuzeofficlal:fix/shader-xor-register-exchanges-815` → `main` · +370 −0 · 2 files · 1 commits · open ### Summary Resolves cancelling `s_xor_b32` and `s_xor_b64` chains in `Tracer::propagate_copies` (`crates/victory-shader/src/resource.rs`) so temporary-free three-XOR SGPR exchanges (`a ^= b; b ^= a; a ^= b`, including swaps through `vcc_lo`/`vcc_hi` and 64-bit SGPR pairs) preserve root-parameter and descriptor origins across loops and control-flow joins. In the native compute corpus measurements reported in #815 (and #1481 Class C), register permutations emitted via three-XOR exchanges caused root pointers and descriptor words to lose their SSA origin and fail with `"an address not from a root parameter"` (`418 -> 339 -> 64` when including `vcc_lo`/`vcc_hi`) or `"an address from a phi"` (`193 -> 24`). ### Details - XOR over 32-bit words is exact GF(2) arithmetic (`x ^ x == 0`, `x ^ 0 == x`): `Tracer::xor_cancelled` collects XOR operands with bounded expansion (`MAX_XOR_STEPS = 32`, expanding the latest `s_xor_b32`/`s_xor_b64` definition in `(rpo[block], inst_index)` order so local swaps cancel cleanly without oscillating across loop phis). - Cancels paired `Value`s and folds constant terms (`NULL`, 32-bit inline/literal constants, and sign-extended 64-bit inline integers `128..=208`): - 0 remaining `Value`s -> `Some(Moved::Const(const_acc))` - 1 remaining `Value` and `const_acc == 0` -> `Some(Moved::Value(v))` - Otherwise `None` (any non-cancelling XOR remains opaque). ### Verification - `resource::tests::three_xor_swap_tracks_32bit_64bit_and_vcc_exchanges` & `three_xor_swap_preserves_phi_origins_and_non_cancelling_xor_stays_opaque`: cover 32-bit SGPR swaps, 64-bit SGPR pair swaps, `vcc_lo` (`code = 106`) swaps, join/loop phi convergence, and negative non-cancelling/mutated-descriptor checks. - `emit::valu_tests::three_xor_swap_tracks_table_through_vcc_and_64bit_pair`: validates DXIL with `dxil.dll` and executes on both hardware GPU and `WARP`. - `cargo clippy -p victory-shader --lib --tests --all-features --locked -- -D warnings` & `cargo xtask policy` pass. Refs #815, #1481
Cancel paired SSA values and fold constants over s_xor_b32/s_xor_b64 in copy propagation so three-XOR register exchanges (including via vcc_lo/vcc_hi and 64-bit SGPR pairs) preserve root parameter and descriptor origins across control flow.

Co-authored-by: Machad3x <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:04:20 +00:00
Author
Owner

@⁠welisonzika14-jpg on GitHub · 2026-11-25 13:08 UTC · original

First run on NVIDIA hardware here, as far as I can see. RTX 5070 (Blackwell, driver 621.24), Ryzen 7 5700X, Windows 11, Rust 1.98.1 MSVC, no game files. Head 87317be merged onto main 940d32f, cargo test -p victory-gpu -p victory-shader --lib --no-fail-fast.

The PR's new test(s) pass on this card: emit::valu_tests::three_xor_swap_tracks_table_through_vcc_and_64bit_pair, resource::tests::three_xor_swap_tracks_32bit_64bit_and_vcc_exchanges, resource::tests::three_xor_swap_preserves_phi_origins_and_non_cancelling_xor_stays_opaque. The rest is the same as main on this card: the 5 known NVIDIA failures from #1744 (2 view heap cap tests in victory-gpu, 3 in victory-shader), nothing new.

One run, unit tests only, title not run.

Written with AI help (Claude/Kiro); the numbers are from runs on my machine.

**@⁠welisonzika14-jpg** on GitHub · 2026-11-25 13:08 UTC · [original](https://github.com/Marvisak/VIctory/pull/2387#issuecomment-7163341255) First run on NVIDIA hardware here, as far as I can see. RTX 5070 (Blackwell, driver 621.24), Ryzen 7 5700X, Windows 11, Rust 1.98.1 MSVC, no game files. Head `87317be` merged onto `main` `940d32f`, `cargo test -p victory-gpu -p victory-shader --lib --no-fail-fast`. The PR's new test(s) pass on this card: `emit::valu_tests::three_xor_swap_tracks_table_through_vcc_and_64bit_pair`, `resource::tests::three_xor_swap_tracks_32bit_64bit_and_vcc_exchanges`, `resource::tests::three_xor_swap_preserves_phi_origins_and_non_cancelling_xor_stays_opaque`. The rest is the same as `main` on this card: the 5 known NVIDIA failures from #1744 (2 view heap cap tests in `victory-gpu`, 3 in `victory-shader`), nothing new. One run, unit tests only, title not run. Written with AI help (Claude/Kiro); the numbers are from runs on my machine.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 14:59 UTC · original

Automated triage for the maintainers.

Merge candidate. Tracer::xor_cancelled (crates/victory-shader/src/resource.rs) lets copy propagation see through three-XOR register exchanges (a ^= b; b ^= a; a ^= b, also via vcc_lo and 64-bit pairs). It expands s_xor_b32/s_xor_b64 definitions, at most 32 steps, cancels equal SSA values pairwise and folds constants. It yields an origin only when exactly one value (with zero constant) or only a constant remains, else nothing. Cancelling identical SSA values is exact, so this cannot invent an origin. Phis are not expanded. The 64-bit inline integers are sign-extended per half, and wide literals and float inline constants are refused. Tests cover 32/64-bit and VCC swaps, phi joins and non-cancelling XORs staying opaque, plus a GPU run on hardware and WARP.

CI: check passing. A contributor reports the new tests passing on an RTX 5070.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 14:59 UTC · [original](https://github.com/Marvisak/VIctory/pull/2387#issuecomment-7166120084) <!-- victory-triage v1 head=87317be84f75116629b015945a335335c7da3880 verdict=merge-candidate at=2026-11-25T14:58:48Z --> Automated triage for the maintainers. **Merge candidate.** `Tracer::xor_cancelled` (`crates/victory-shader/src/resource.rs`) lets copy propagation see through three-XOR register exchanges (`a ^= b; b ^= a; a ^= b`, also via `vcc_lo` and 64-bit pairs). It expands `s_xor_b32`/`s_xor_b64` definitions, at most 32 steps, cancels equal SSA values pairwise and folds constants. It yields an origin only when exactly one value (with zero constant) or only a constant remains, else nothing. Cancelling identical SSA values is exact, so this cannot invent an origin. Phis are not expanded. The 64-bit inline integers are sign-extended per half, and wide literals and float inline constants are refused. Tests cover 32/64-bit and VCC swaps, phi joins and non-cancelling XORs staying opaque, plus a GPU run on hardware and WARP. CI: `check` passing. A contributor reports the new tests passing on an RTX 5070. --- _Generated by [Claude Code](https://claude.ai/code)_
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

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

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2387'
git switch 'github-bot/gh-2387'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2387'
git switch 'github-bot/gh-2387'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2387'
git switch 'main'
git merge --squash 'github-bot/gh-2387'
git switch 'main'
git merge --ff-only 'github-bot/gh-2387'
git switch 'main'
git merge 'github-bot/gh-2387'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!2387
No description provided.