Shaders: compress replaced phi chains in remove_trivial_phis #1371

Merged
fuzeofficlal merged 1 commit from upstream-pr/1371 into main 2026-11-25 00:22:27 +00:00
fuzeofficlal commented 2026-11-24 17:38:32 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-24T17:38:32Z.


Fixes #950.

Summary

  • Add iterative two-pass path compression to find inside ir::remove_trivial_phis so deep chains of trivial phis eliminated in reverse block order do not repeatedly walk O(N) chains (O(N^2) total) during the fixed-point and operand-rewrite passes.

Verification

  • Added deterministic IR tests covering 4,096-layer reverse-ordered vs forward-ordered diamond CFG chains, step-count linearity, and preservation of non-trivial loop phis.
  • cargo test --workspace, cargo clippy --workspace --all-targets --all-features, and cargo xtask policy: passed.
<!-- greyfinch-sync:Marvisak/VIctory:issue:6587791073 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1371). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-24T17:38:32Z. --- Fixes #950. ### Summary - Add iterative two-pass path compression to `find` inside `ir::remove_trivial_phis` so deep chains of trivial phis eliminated in reverse block order do not repeatedly walk `O(N)` chains (`O(N^2)` total) during the fixed-point and operand-rewrite passes. ### Verification - Added deterministic IR tests covering 4,096-layer reverse-ordered vs forward-ordered diamond CFG chains, step-count linearity, and preservation of non-trivial loop phis. - `cargo test --workspace`, `cargo clippy --workspace --all-targets --all-features`, and `cargo xtask policy`: passed.
catminou4 commented 2026-11-24 18:05:03 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T17:42:43Z.

Review: APPROVED


remove_trivial_phis find() gains path compression (two-pass iterative, no recursion): the replaced[] union-find no longer degrades to O(chain^2) on long trivial-phi chains. Semantics unchanged — compression only shortcuts lookups; the three new ir.rs tests verify identical SSA results on 4096-layer forward/reverse diamonds, a <100k step bound, and that non-trivial phis keep correct representatives. All run on macOS. Local verification: macOS arm64, rustc 1.98.1, PR head merged into main ffe310e, cargo test -p <crate> --locked. Shader execution tests (valu_tests/host/diff_tests) are #[cfg(all(test, windows))], so macOS covers lowering/decode/unit tests only. 99 passed, 0 failed.

<!-- greyfinch-sync:Marvisak/VIctory:review:6044388869 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1371#pullrequestreview-6044388869). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T17:42:43Z. **Review:** APPROVED --- remove_trivial_phis find() gains path compression (two-pass iterative, no recursion): the replaced[] union-find no longer degrades to O(chain^2) on long trivial-phi chains. Semantics unchanged — compression only shortcuts lookups; the three new ir.rs tests verify identical SSA results on 4096-layer forward/reverse diamonds, a <100k step bound, and that non-trivial phis keep correct representatives. All run on macOS. Local verification: macOS arm64, rustc 1.98.1, PR head merged into main ffe310e, `cargo test -p <crate> --locked`. Shader execution tests (valu_tests/host/diff_tests) are `#[cfg(all(test, windows))]`, so macOS covers lowering/decode/unit tests only. 99 passed, 0 failed.
catminou4 commented 2026-11-24 21:02:17 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T20:50:18Z.

Review: APPROVED


Tested locally on macOS arm64 (rustc 1.98.1): PR head merged cleanly into current main (ffe310e), cargo test -p victory-shader --locked → 99 passed, 0 failed. Hardware/valu tests are #[cfg(all(test, windows))] and only run on Windows; macOS covers structure/lowering unit tests.

remove_trivial_phis now compresses replaced phi chains with a bounded step budget (find() with steps) instead of one pass per phi; three tests cover reverse-order diamond chains, bounded compression, and non-trivial phi preservation. +3 macOS tests (99 total).

<!-- greyfinch-sync:Marvisak/VIctory:review:6047177318 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1371#pullrequestreview-6047177318). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T20:50:18Z. **Review:** APPROVED --- Tested locally on macOS arm64 (rustc 1.98.1): PR head merged cleanly into current main (ffe310e), cargo test -p victory-shader --locked → 99 passed, 0 failed. Hardware/valu tests are #[cfg(all(test, windows))] and only run on Windows; macOS covers structure/lowering unit tests. remove_trivial_phis now compresses replaced phi chains with a bounded step budget (find() with steps) instead of one pass per phi; three tests cover reverse-order diamond chains, bounded compression, and non-trivial phi preservation. +3 macOS tests (99 total).
upstream-sync closed this pull request 2026-11-25 01:06:23 +00:00
sinan-cmyk commented 2026-11-25 02:06:23 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by sinan-cmyk on 2026-11-25T01:48:23Z.


Offline measurement on a retail dump, and the shader tests on Ada

Result: no count change against main.

Offline. I merged head 5c44562 onto main ffe310e (clean merge) and ran victory translate --validate --list on shaders.rpf (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with main program by program (25,889 programs). Validated: 21,724 on main, 21,724 with this PR.

No program changes its failure reason either. That is the expected result for a fix whose instructions sit behind the earlier failures on main. The count shows that the change rejects nothing. It does not show whether the output is right.

Tests: with the same merge, cargo test --locked -p victory-shader --lib passed 123, failed 0. The bitcode benchmark is ignored, as on main, where 120 pass. The run was on an RTX 4070 SUPER (Ada, 32-lane waves, driver 32.0.16.1088), the default adapter, with VICTORY_WARP unset.

No shader names or data are included, per the asset policy. AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7149977691 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1371#issuecomment-7149977691). Originally posted by [sinan-cmyk](https://github.com/sinan-cmyk) on 2026-11-25T01:48:23Z. --- ### Offline measurement on a retail dump, and the shader tests on Ada **Result: no count change against `main`.** **Offline.** I merged head 5c44562 onto `main` ffe310e (clean merge) and ran `victory translate --validate --list` on `shaders.rpf` (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with `main` program by program (25,889 programs). Validated: 21,724 on `main`, 21,724 with this PR. No program changes its failure reason either. That is the expected result for a fix whose instructions sit behind the earlier failures on `main`. The count shows that the change rejects nothing. It does not show whether the output is right. **Tests:** with the same merge, `cargo test --locked -p victory-shader --lib` passed 123, failed 0. The bitcode benchmark is ignored, as on `main`, where 120 pass. The run was on an RTX 4070 SUPER (Ada, 32-lane waves, driver 32.0.16.1088), the default adapter, with `VICTORY_WARP` unset. No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
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
Marvisak/VIctory!1371
No description provided.