Shaders: prune unreachable blocks before SSA construction #1484
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!1484
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1484/head"
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?
@chiperandrei42 on GitHub · 2026-11-24 18:21 UTC · original
chiperandrei42:fix/ir-prune-unreachable-blocks→main· +177 −10 · 1 files · 1 commits · closed without mergingSummary: Fixes VIC-BT-002 from #1242:
Prunes blocks unreachable from entry block 0 (remapping Exit::Jump and Exit::Branch targets in code order) before link(&mut blocks) and after split_irreducible if any blocks become unreachable.
Ensures Block::preds, reverse_postorder, liveness, and SSA phi argument construction never observe unreachable predecessors, preventing NONE (Value(u32::MAX)) from entering phi.args and panicking remove_trivial_phis in release builds.
Factors SSA construction into build_ssa and adds synthetic unit tests (prunes_unreachable_predecessor_before_ssa, prunes_unreachable_edge_into_entry_and_merge).
Verification:
cargo test --workspace (122 passed, 1 ignored in victory-shader)
cargo test --release -p victory-shader (122 passed, 1 ignored)
cargo clippy --workspace --all-targets -- -D warnings
cargo xtask policy
victory translate --validate on local dump (26,148/26,148 translated; zero regressions)
@wbkepler on GitHub · 2026-11-24 20:59 UTC · original
A note to read alongside #1619, which pins the same VIC-BT-002 invariants from the other side.
From reading
ir.rsandgfx10/mod.rsatffe310e:build()can't produce an unreachable block today.gfx10::decodeonly decodes instructions it reaches from offset 0, andbuild()turns those sameFlowedges intoExits. The one place they can differ isfar_jump.decoderesolves it against the instructions decoded so far, andbuild()resolves it against the full list. That can only add an edge inbuild(), never remove one. So every leader is reachable, everyouts[p]is filled before the phi arguments are read, andlookupcan't returnNONE. #1619'sa_branch_skips_its_dead_code_before_the_ir_is_builtshows this for the VIC-BT-002 reproducer: the dead code at 4 and 8 is never decoded.The second prune in
build_ssaalso can't fire.split_irreducibleonly moves edges into a multi-entry SCC, and its header keeps an outside predecessor, so the original entry and every copied block stay reachable.So
prune_unreachablechanges nothing for any program that goes throughbuild(), and I see no correctness problem with keeping it as a guard. The two new tests build theirBlocks by hand and skipdecode, so they show the guard working but not a program that reached the release panic. If you have an input that hits it throughbuild(), abuild_wordstest would pin the real trigger. If not, it may be worth calling this defensive in the description. It is compatible with #1619'sassert_well_formed(both only add tests at the end ofir::tests, so the conflict is textual).AI-assisted review (Claude Code); checked on Windows 11 / RTX 5090.
@Marvisak on GitHub · 2026-11-25 00:41 UTC · original
Automated triage for the maintainers. Closing because it does not change behaviour the project needs (formatting, guards for cases that cannot occur, or notes and translations that cannot be kept current).
Prunes unreachable blocks before SSA, a state
ir::buildcannot produce: the decoder only yields instructions reachable from offset 0 and node splitting keeps the originals reachable (#1619 shows this with tests). Its own tests feed hand-built blocks; 177 lines of hardening for nothing.If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.
Pull request closed