fix(shader): prune unreachable CFG blocks before SSA #546
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/lobomfz--VIctory-xmem!546
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-546"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@tommiehansen on GitHub · 2026-12-05 02:41 UTC · original
tommiehansen:review-split/404-cfg-fix→main· +338 −13 · 2 files · 4 commits · merged 2026-12-05 17:28 UTCLatest CFG correctness verification
Exact-head audit at
201e316: debug and release shader suites passed; the deliberately omitted fallthrough-remap negative control failed as intended. This is a correctness fix, not an FPS claim.Review split from #404, based on current upstream main. The diff contains this one slice.
Linux shader suite: 298 passed and 2 ignored. The audit job failed the inherited launcher-switch documentation check tracked in #528.
Exact pinned CI evidence
No hardware timing or gameplay results. The original PR remains available until maintainers choose the integration order.
Post-review follow-up — 2026-12-05
Head:
e869080060209b9eab3d014df25a6335c3d6bad4.The CFG pruning fix now conservatively bumps TRANSLATOR_VERSION from 20 to 21, since dead blocks in formerly successful translations can affect resource/IO analysis. Reconcile the version with main at merge time. Wrapped the reviewed formatting issues. The version bump does not establish an observed DXIL difference; the prior 840-container parity evidence remains scoped to
31e7e78.Fresh pinned debug/release CI started; new test and performance results must be reported at this head. Previous validation is retained at its original revision.
Targeted branch-remap regression
Head:
201e3166e905dc5b5ad849673bc5d48463b8a2e5. Addedpruning_remaps_both_branch_targets_past_a_dead_blockto cover the fallthrough-remap gap identified by Kal0s-design. The test verifies both targets, predecessor lists and reachability after pruning. Production code is unchanged in this commit. Debug/release and deliberate missing-remap negative control pending.@Kal0s-design on GitHub · 2026-12-05 04:28 UTC · original
Checked
31e7e78on native Windows (one NVIDIA desktop card plus WARP, didn't run the game). Merge base isb581f7e, current main.The body doesn't say what goes wrong without this, so here is what I found it fixes. On main,
thread_edges,without_early_outsandwithout_skipscan leave blocks that nothing reaches.linkstill counts them as predecessors,renameonly walks reverse postorder, so a live join fed by a dead block gets a phi arg fromlookupon an emptyoutsentry, which is NONE. In a debug build that trips thedebug_assertat ir.rs:746 on main. In release there's no assert, andremove_trivial_phisthen doesreplaced[NONE](ir.rs:1562 into 1539 on main), which is an out-of-bounds panic. The translate callers in victory-gpu catch panics, so on main those shaders just come out as not translated. I put the PR's four new tests on main.thread_edges_prunes_orphaned_join_and_keeps_valid_ssaandprune_unreachable_drops_dead_preds_...hit that debug_assert, so they reproduce the bug for real. The twowithout_*tests only fail on main because of the block count asserts (3 vs 2): main keeps the dead early-exit block, but that block feeds nothing, so it's harmless there.The pruning looks right to me.
decodeonly follows reachable flow, sobuild()never has dead blocks in practice. Thereprune_unreachable(ir.rs:1299) does one RPO and returns it as is. The order is the same onerenamecomputed on main, so for programs with no dead blocks the IR is unchanged. When it does prune, block 0 stays block 0 (the entry is always reachable), the kept blocks keep their relative order,Jump/Branchtargets get remapped, andlinkrebuilds preds. Exits are the only place a block index lives insideBlock. Phis are cleared before every rename, and nothing else keyed by block index crosses from one program to another: every form in emit/mod.rs re-runs structure, io and resource on the new program, andwidenstays on one program.Indirecthas no successors anddecodenever follows it, so no block is reachable only through ans_setpc. Exec-dependent branches keep both edges, so a "not taken" side is never pruned. Insplit_irreducible(ir.rs:1418) each iteration now prunes beforemulti_entry_loop. Everything indexed (order, index, region, copy) is recomputed per iteration, so the renumbering can't leave stale indices behind. It also means dead blocks can't be chosen as part of a loop region any more, which could happen on main because it passes an all-true mask. The order returned at ir.rs:1427 is the one computed right after the last prune, with nothing changed after it, so passing it torename_with_orderis sound.With
cargo test -p victory-shader --lib -- --test-threads=4(debug) main gave 419 passed, 1 failed, 4 ignored. On the PR, 423 passed, 1 failed, 4 ignored. The failure is the same one on both,size_tests::a_reused_descriptor_register_read_only_behind_its_flag, which already fails on main. The four new tests pass. Clippy with--lib --tests --examplesgives the same 12 warnings on both (--all-targetsstops on the same pre-existing guard_runs bench error on both). One nit: the file isn't rustfmt-clean after this. Therename_with_ordersignature and the twoassert_ne!lines inprune_unreachableneed wrapping, and main's ir.rs is clean.For a differential I hashed every DXIL container the crate's test suite produces on both trees, and all 840 of 840 came out identical. One of those programs actually goes down the changed path. In
a_far_early_out_is_left_out_and_the_gate_counts_the_lanes_of_both_halves,without_early_outsleaves a dead block that feeds a live one on main (no phi needed there, so main didn't panic). That form's DXIL is byte-identical, passes dxil.dll validation and runs on the card in both trees. I also ran a throwaway fuzz, not part of the PR. One part was 200k random CFGs throughprune_unreachable, about 166k of them with dead blocks. Every remaining block is reachable, entry is unchanged, edges map to the same original blocks, preds match a freshlink, and the returned order equals main's RPO remapped. The other part was 40k random CFGs with scalar reads and writes throughsplit_irreducibleplus rename, then random pred/join/dest triples throughthread_edges. On the PR, 0 panics and 0 invalid SSA (no NONE, no dangling args, phi arity equal to preds). On main the same inputs panic about 31k times, plus about 1k panics inthread_edges. For the about 7k graphs with no dead blocks, and the about 1.6k threadings that leave none, a hash over the Debug dump of the resulting Program is the same on both trees.About TRANSLATOR_VERSION, shaders that panicked before and translate now fall under the "did not translate before" exemption in lib.rs. The case I can't rule out is a form that did translate on main while carrying a dead block whose stale contents mattered. io.rs:373, resource.rs:238/520 and parts of lower.rs walk every block, dead ones included. If such a block held a resource access or a register read, the PR's output for that shader would change. The one such program in the tests came out identical, but that's one program. A
victory shaderspass on a real cache would answer it. I couldn't do that without game data, so either run it or bump to be safe. Those forms only run for wave64 compute on 32-lane hosts, plus the threading retry.As for the other two splits, this merges cleanly with #545 (structure.rs only, and that one already treats unreachable blocks as
usize::MAXidoms). It conflicts with #547 only at the end of their.rstests module, where both append tests. The logic hunks auto-merge, and the merged code only callsrename_with_order, withrenameused just by the tests, so it's a rebase-order thing, not a real dependency. I didn't check whether the body's Linux count (298 passed, 2 ignored) matches; on Windows the suite has more tests.I didn't test release-build behaviour (the release panic above is from reading the code, not from running it), real game shaders, timing, gameplay, and AMD or other vendors' drivers.
AI-assisted: yes
@tommiehansen on GitHub · 2026-12-05 10:18 UTC · original
Thanks @Kal0s-design for the thorough CFG review. The translator version is now 21 to avoid stale cached translations, and the formatting issues are fixed. 201e316 adds coverage for both branch targets after pruning. Debug/release CI and the deliberate missing-remap negative control passed.