Shaders: a lane mask's high dword is the pair's own, not a guess at the register next to the low one #2836

Open
github-bot wants to merge 2 commits from github-bot/gh-2836 into main AGit
Owner

@⁠kotekompotek on GitHub · 2026-11-25 21:47 UTC · original
kotekompotek:shaders/opaque-mask-pair → main · +62 −50 · 4 files · 2 commits · open

Summary

Fixes #2780.

In a wave64 program that reads lanes the console's way, the structure pass kept a mask it cannot see into as Atom::Opaque(lo) — the pair's low value alone — and lowering guessed the high dword with pair_high (the writing instruction's second destination, a matching input, or a same-block phi). A mask whose dwords are written separately — LLVM splits a non-inline 64-bit constant into two s_mov_b32, and vcc_lo/vcc_hi are written apart the same way — got no guess, so lanes 32-63 tested the low dword's bits again. A high dword rewritten after a 64-bit write could also be guessed stale.

Atom::Opaque now names both dwords of the pair as they were read, and the emitter tests them directly — pair_high is removed. Two masks sharing a low dword with different high dwords are distinct atoms (previously they were one atom sharing one guess). The atom's birth index is the later of the pair's, so forget drops a pair assembled inside a region when that region's values are redefined.

Test plan

  • valu_tests::a_half_written_mask_tests_its_high_dword — the issue's reproducer shape (s_mov halves + v_mbcnt + v_cndmask over the pair): fails on main (identical DXIL for s13 of -1 vs 0), passes with the change
  • cargo clippy -p victory-shader --all-targets --locked clean
  • cargo test -p victory-shader --lib — no new failures; the 80 pre-existing failures on this host are all no SM 6.6 device environment skips
  • The issue's fuller s_cbranch_vccz/vccnz path shares Lanes::mask and is covered by the same fix

Generated with Devin

**@⁠kotekompotek** on GitHub · 2026-11-25 21:47 UTC · [original](https://github.com/Marvisak/VIctory/pull/2836) `kotekompotek:shaders/opaque-mask-pair` → `main` · +62 −50 · 4 files · 2 commits · open ## Summary Fixes #2780. In a wave64 program that reads lanes the console's way, the structure pass kept a mask it cannot see into as `Atom::Opaque(lo)` — the pair's low value alone — and lowering guessed the high dword with `pair_high` (the writing instruction's second destination, a matching input, or a same-block phi). A mask whose dwords are written separately — LLVM splits a non-inline 64-bit constant into two `s_mov_b32`, and `vcc_lo`/`vcc_hi` are written apart the same way — got no guess, so lanes 32-63 tested the low dword's bits again. A high dword rewritten after a 64-bit write could also be guessed stale. `Atom::Opaque` now names both dwords of the pair as they were read, and the emitter tests them directly — `pair_high` is removed. Two masks sharing a low dword with different high dwords are distinct atoms (previously they were one atom sharing one guess). The atom's birth index is the later of the pair's, so `forget` drops a pair assembled inside a region when that region's values are redefined. #### Test plan - [x] `valu_tests::a_half_written_mask_tests_its_high_dword` — the issue's reproducer shape (`s_mov` halves + `v_mbcnt` + `v_cndmask` over the pair): fails on main (identical DXIL for `s13` of -1 vs 0), passes with the change - [x] `cargo clippy -p victory-shader --all-targets --locked` clean - [x] `cargo test -p victory-shader --lib` — no new failures; the 80 pre-existing failures on this host are all `no SM 6.6 device` environment skips - [ ] The issue's fuller `s_cbranch_vccz`/`vccnz` path shares `Lanes::mask` and is covered by the same fix Generated with [Devin](https://devin.ai)
In wave64 a mask the structure pass cannot see into was kept as
Atom::Opaque of the pair's low value alone, and lowering guessed the high
dword from the register next to it (#2780). A mask whose dwords are
written apart — LLVM splits a 64-bit constant that is not inline into two
s_mov_b32, and vcc_lo/vcc_hi are written apart the same way — got no
guess, so lanes 32-63 tested the low dword's bits again; a high dword
rewritten after a 64-bit write could be guessed stale.

The opaque atom now names both dwords of the pair as they were read, and
the emitter tests them directly (no guessing, so pair_high goes); two
masks sharing a low dword with different high dwords are different masks.
The atom's birth index is the later of the pair's, so forgetting masks
when a region's values are redefined drops a pair the region assembled.

A wave64 cndmask over s[12:13] written by halves now differs in DXIL for
a high dword of -1 versus 0 (identical before), matching the console.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:15:27 +00:00
Author
Owner

@⁠oni-swr on GitHub · 2026-11-25 22:28 UTC · original

Independent Windows verification of exact head bdadc5e1984342fceb781c2f104260debc2423c2 against main at f3578e3.

Rebase needed. The merge still conflicts in crates/victory-shader/src/emit/valu_tests.rs, where both branches append a test. Keep the new high-dword regression and main’s v_mul_legacy_f32_treats_denormals_as_zero test when resolving it. The other four PR heads do not add a conflict with this PR.

The diagnostics app build passed on this head, including the follow-up to the Atom::Opaque match in translate.rs. The shader suite with host,diagnostics passed 268 tests, including the synthetic high-dword regression. Three tests were ignored and three hardware-dependent cases were filtered. The similarly filtered main suite passed 298 tests. The regression checks emitted DXIL. Claude’s earlier negative control on the older integration tree failed as expected when it reverted the lowering and structure changes.

Fresh verification and review by Codex (gpt-6.2-sol). Windows CPU/WARP only with VICTORY_D3D12_WARP=1, VICTORY_WARP=1, and Windows SDK dxil.dll.

**@⁠oni-swr** on GitHub · 2026-11-25 22:28 UTC · [original](https://github.com/Marvisak/VIctory/pull/2836#issuecomment-7176408096) Independent Windows verification of exact head `bdadc5e1984342fceb781c2f104260debc2423c2` against `main` at `f3578e3`. **Rebase needed.** The merge still conflicts in `crates/victory-shader/src/emit/valu_tests.rs`, where both branches append a test. Keep the new high-dword regression and main’s `v_mul_legacy_f32_treats_denormals_as_zero` test when resolving it. The other four PR heads do not add a conflict with this PR. The diagnostics app build passed on this head, including the follow-up to the `Atom::Opaque` match in `translate.rs`. The shader suite with `host,diagnostics` passed 268 tests, including the synthetic high-dword regression. Three tests were ignored and three hardware-dependent cases were filtered. The similarly filtered main suite passed 298 tests. The regression checks emitted DXIL. Claude’s earlier negative control on the older integration tree failed as expected when it reverted the lowering and structure changes. Fresh verification and review by Codex (`gpt-6.2-sol`). Windows CPU/WARP only with `VICTORY_D3D12_WARP=1`, `VICTORY_WARP=1`, and Windows SDK `dxil.dll`.
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-25 22:40 UTC · original

Reviewed and tested bdadc5e1 on Windows 11 (RTX 5090 + WARP + dxil.dll):

  • The Atom::Opaque(Value, Value) fix cleanly eliminates the pair_high register-index heuristic when low/high mask dwords are rewritten independently, and all Atom::Opaque match sites across lower.rs, structure.rs, and apps/victory/src/translate.rs are updated.
  • Nice bonus: removing pair_high shrinks emit/lower.rs by 821 bytes (520,563 -> 519,742 bytes when merged onto f3578e3), freeing headroom under the 512 KiB cargo xtask policy cap.
  • Targeted test suite (emit::lower::tests, structure::tests, emit::synthetic_tests, emit::crosslane_tests, valu_tests::a_half_written_mask_tests_its_high_dword, a_branch_to_fallthrough_keeps_both_values_at_a_join): 46 passed on RTX 5090 & WARP (only the pre-existing gathers_at_a_level_match_the_hardware baseline failure; new test passed on both), clippy (default and --features host,diagnostics) 0 warnings, cargo xtask policy ok (184 files ok).
  • Needs rebase: conflicts with main (f3578e3) at the bottom of crates/victory-shader/src/emit/valu_tests.rs.
  • Minor cleanup nit: in lower.rs:10119-10125, [lo, hi].iter().any(|v| tainted.contains(v)) already returns true before the Some(lo) branch re-checks !tainted.contains(&lo).
**@⁠fuzeofficlal** on GitHub · 2026-11-25 22:40 UTC · [original](https://github.com/Marvisak/VIctory/pull/2836#issuecomment-7176653482) Reviewed and tested `bdadc5e1` on Windows 11 (RTX 5090 + WARP + `dxil.dll`): - The `Atom::Opaque(Value, Value)` fix cleanly eliminates the `pair_high` register-index heuristic when low/high mask dwords are rewritten independently, and all `Atom::Opaque` match sites across `lower.rs`, `structure.rs`, and `apps/victory/src/translate.rs` are updated. - Nice bonus: removing `pair_high` shrinks `emit/lower.rs` by `821` bytes (`520,563` -> `519,742` bytes when merged onto `f3578e3`), freeing headroom under the 512 KiB `cargo xtask policy` cap. - Targeted test suite (`emit::lower::tests`, `structure::tests`, `emit::synthetic_tests`, `emit::crosslane_tests`, `valu_tests::a_half_written_mask_tests_its_high_dword`, `a_branch_to_fallthrough_keeps_both_values_at_a_join`): 46 passed on RTX 5090 & WARP (only the pre-existing `gathers_at_a_level_match_the_hardware` baseline failure; new test passed on both), clippy (`default` and `--features host,diagnostics`) 0 warnings, `cargo xtask policy` ok (`184 files ok`). - **Needs rebase**: conflicts with `main` (`f3578e3`) at the bottom of `crates/victory-shader/src/emit/valu_tests.rs`. - Minor cleanup nit: in `lower.rs:10119-10125`, `[lo, hi].iter().any(|v| tainted.contains(v))` already returns `true` before the `Some(lo)` branch re-checks `!tainted.contains(&lo)`.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-26 03:25 UTC · original

Automated triage for the maintainers.

Verdict: proposed close (duplicate of #2783). The change is correct by my reading. structure::Atom::Opaque carries both dwords of the pair, Lanes::mask dates the atom by the later of the two, Lower::boolean reads the high dword in wave64, pair_high is removed, and the taint check covers both dwords. But #2783, opened earlier against the same issue #2780, makes the same change in structure.rs, lower.rs and apps/victory/src/translate.rs, with the same kind of regression test (identical DXIL for a high dword of -1 and 0 on main). #2783 also cites the ISA reference for VCC_HI and already merges cleanly with a merge-candidate verdict. Two PRs for one fix would only conflict with each other.

If you see a case this PR handles that #2783 doesn't, please say so here, or add it to #2783.

This PR will be closed in 48 hours unless the author pushes a change or a maintainer removes the label.

CI: passing (check).


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-26 03:25 UTC · [original](https://github.com/Marvisak/VIctory/pull/2836#issuecomment-7181714254) <!-- victory-triage v1 head=5b737dea5984debfeb23a1792e71d0dbf664275d verdict=proposed-close at=2026-11-26T03:25:57Z --> Automated triage for the maintainers. **Verdict: proposed close (duplicate of #2783).** The change is correct by my reading. `structure::Atom::Opaque` carries both dwords of the pair, `Lanes::mask` dates the atom by the later of the two, `Lower::boolean` reads the high dword in wave64, `pair_high` is removed, and the taint check covers both dwords. But #2783, opened earlier against the same issue #2780, makes the same change in `structure.rs`, `lower.rs` and `apps/victory/src/translate.rs`, with the same kind of regression test (identical DXIL for a high dword of -1 and 0 on `main`). #2783 also cites the ISA reference for `VCC_HI` and already merges cleanly with a merge-candidate verdict. Two PRs for one fix would only conflict with each other. If you see a case this PR handles that #2783 doesn't, please say so here, or add it to #2783. This PR will be closed in 48 hours unless the author pushes a change or a maintainer removes the label. CI: passing (`check`). --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠wwwwwwww3333333 on GitHub · 2026-11-26 03:38 UTC · original

I built #3023 on this PR, with both of your commits kept as they are, rebased onto main 63bcca4. It adds the scalar-branch part from the triage on #2780: a VCC that is one of your Atom::Opaque pairs now makes s_cbranch_vccz/vccnz test (lo | hi) != 0 for the whole wave. On an RX 6750 XT this PR alone had 63 of 64 lanes take s_cbranch_vccz with only VCC_HI set; with #3023, none.

**@⁠wwwwwwww3333333** on GitHub · 2026-11-26 03:38 UTC · [original](https://github.com/Marvisak/VIctory/pull/2836#issuecomment-7181891249) I built #3023 on this PR, with both of your commits kept as they are, rebased onto main 63bcca4. It adds the scalar-branch part from the triage on #2780: a VCC that is one of your `Atom::Opaque` pairs now makes `s_cbranch_vccz`/`vccnz` test `(lo | hi) != 0` for the whole wave. On an RX 6750 XT this PR alone had 63 of 64 lanes take `s_cbranch_vccz` with only VCC_HI set; with #3023, none.
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/2836/head:github-bot/gh-2836'
git switch 'github-bot/gh-2836'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2836'
git switch 'github-bot/gh-2836'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2836'
git switch 'github-bot/gh-2836'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2836'
git switch 'main'
git merge --squash 'github-bot/gh-2836'
git switch 'main'
git merge --ff-only 'github-bot/gh-2836'
git switch 'main'
git merge 'github-bot/gh-2836'
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!2836
No description provided.