shader: coalesce single-pred blocks and fold dead diamonds in DXIL opt #2623

Manually merged
github merged 1 commit from github-bot/gh-2623 into main 2026-11-30 14:17:06 +00:00 AGit
Owner

@⁠nidea1 on GitHub · 2026-11-29 15:04 UTC · original
nidea1:perf/dxil-opt-cfg-block-coalescing → main · +391 −7 · 1 files · 1 commits · merged 2026-11-30 14:12 UTC

Summary

Adds simplify_cfg() to the DXIL module optimizer (crates/victory-shader/src/emit/bitcode/opt.rs, gated under FOLD alongside prune() and mid-loop drop_dead_insts() when DEAD is enabled):

  1. Same-target conditional branch folding: folds CondBr(_, t, t) -> Br(t) whenever all phis in t agree for that predecessor.
  2. Single-predecessor block coalescing: merges a -> Br(b) chains when b has only predecessor a (resolving single-entry phis with a degenerate phi-cycle guard and remapping successor phi incoming block IDs).
  3. Empty trampoline threading: threads empty phi-free trampoline blocks (e: Br(t)) into phi-free targets t, collapsing dead if/else diamonds into straight-line blocks and unlocking cross-block LOADS reuse/DSE and BARRIERS coalescing on subsequent rounds.

Verification

  • cargo test -p victory-shader --lib: 462 passed, 0 failed (27/27 opt::tests::, including randomized differential oracle, RTX 3060 Ti DXIL parity, and new CFG coalescing / diamond / phi-remap tests).
  • cargo clippy -p victory-shader --tests: 0 warnings in opt.rs.
  • cargo xtask policy --staged: passed.
  • Corpus benchmark across top 10 largest Wave64-folded compute shaders (RTX 3060 Ti host settings):
    • Total DXIL basic blocks: 41,896 → 33,885 (-19.1%, -8,011 blocks; largest ~1.8 MB folded compute shader dropped 8,548 → 6,992 blocks, -18.2%).
    • Total DXIL bytes: 8,453,912 → 8,412,904 B (-41 KB across top 10; up to -5.4% on branch-heavy folded compute shaders).
  • Full corpus translation & pipeline validation on RTX 3060 Ti: 2,720 / 2,720 used pipelines compiled cleanly with 0 failures and verified in live gameplay.
**@⁠nidea1** on GitHub · 2026-11-29 15:04 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2623) `nidea1:perf/dxil-opt-cfg-block-coalescing` → `main` · +391 −7 · 1 files · 1 commits · merged 2026-11-30 14:12 UTC ## Summary Adds `simplify_cfg()` to the DXIL module optimizer (`crates/victory-shader/src/emit/bitcode/opt.rs`, gated under `FOLD` alongside `prune()` and mid-loop `drop_dead_insts()` when `DEAD` is enabled): 1. **Same-target conditional branch folding**: folds `CondBr(_, t, t) -> Br(t)` whenever all phis in `t` agree for that predecessor. 2. **Single-predecessor block coalescing**: merges `a -> Br(b)` chains when `b` has only predecessor `a` (resolving single-entry phis with a degenerate phi-cycle guard and remapping successor phi incoming block IDs). 3. **Empty trampoline threading**: threads empty phi-free trampoline blocks (`e: Br(t)`) into phi-free targets `t`, collapsing dead `if/else` diamonds into straight-line blocks and unlocking cross-block `LOADS` reuse/DSE and `BARRIERS` coalescing on subsequent rounds. ## Verification - `cargo test -p victory-shader --lib`: 462 passed, 0 failed (27/27 `opt::tests::`, including randomized differential oracle, RTX 3060 Ti DXIL parity, and new CFG coalescing / diamond / phi-remap tests). - `cargo clippy -p victory-shader --tests`: 0 warnings in `opt.rs`. - `cargo xtask policy --staged`: passed. - Corpus benchmark across top 10 largest Wave64-folded compute shaders (RTX 3060 Ti host settings): - Total DXIL basic blocks: **41,896 → 33,885** (**-19.1%**, -8,011 blocks; largest ~1.8 MB folded compute shader dropped **8,548 → 6,992** blocks, -18.2%). - Total DXIL bytes: **8,453,912 → 8,412,904 B** (-41 KB across top 10; up to -5.4% on branch-heavy folded compute shaders). - Full corpus translation & pipeline validation on RTX 3060 Ti: 2,720 / 2,720 used pipelines compiled cleanly with 0 failures and verified in live gameplay.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-29 15:08:50 +00:00
github manually merged commit f7624c6644 into main 2026-11-30 14:17:06 +00:00
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/trustno1-coder--VIctory-NVIDIA!2623
No description provided.