You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Recompiler: collapse empty trampolines and merge linear blocks in direct DXIL opt - #2194
After DCE in gpu::dxil::module::opt, guarded lowering helpers and dead branches leave thousands of empty trampoline blocks ([Br(target)]), single-predecessor linear chains, and degenerate CondBr(c, t, t) / Switch terminators in the emitted DXIL.
What is in it
crates/xcl/src/gpu/dxil/module/opt.rs: add a fixed-point Module::simplify_cfg pass after DCE (opt-out via XCL_DXIL_NO_OPT=merge, orthogonal to dxil: fold constant CFG terminators after CSE #1818's constant-terminator folding):
Collapse degenerate CondBr(_, t, t) to Br(t) and strip Switch cases matching default, updating Op::Phi edge multiplicity to match.
Bypass empty trampoline blocks ([Br(t)], b != 0, t != b) whenever t's phis allow it without creating conflicting incoming values or inflating multi-predecessor phi tables (!target_has_phi || total_edges <= 1).
Merge single-predecessor linear blocks a -> b along unconditional branches, resolving single-input phis in b, updating def_block, and rewriting successor phis from b to a (including loop backedges).
Run a lightweight follow-up trivial-phi + DCE cleanup when CFG simplification changed terminators or phis.
Add 5 unit tests covering trampoline chains, phi-conflict preservation, degenerate CondBr/Switch collapse, loop-latch merge with header-phi rewriting, and the multi-predecessor phi guard.
Measured impact
Across all 2,682 compute programs from a retail shader pack (XCL_DIRECT_DXIL=1 XCL_HEAP_WINDOWS=1, XCL_DXIL_NO_OPT=merge vs default): 2,682 / 2,682 strictly smaller, 0 larger (775,076,910 -> 774,508,202 B).
On the largest compute program (95cc13288a27a96e): basic blocks 23,619 -> 20,506 (-13.2%, -3,113 blocks), IR lines 513,461 -> 504,122 (-9,339 lines), DXIL 3,345,980 -> 3,332,628 B (-0.40%).
AMD run (listed as untested), paired against main, with the direct translator on for the whole GPU suite since this changes the optimizer every direct-DXIL program goes through.
Head e64bd17 applied on main568e7db, debug, Windows 11 Pro 26200, XCL_DIRECT_DXIL=1 cargo test -p xcl --lib -- gpu:: --test-threads=4, run on main and on this PR for each card:
Per-test comparison: on both cards the only differences between the two runs are the 5 new simplify_cfg_* tests (all ok). No existing test changes result. The failures are the same on main: gpu_image_get_resinfo_1d_array on both cards (the direct-path bug #2046 fixes) and, on the RX 9070 XT only, the fuzz seeds 722 and 1599 tracked in #2115.
Not tested: driver compile time on AMD, a title with XCL_DIRECT_DXIL=1.
AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #1269.
After DCE in
gpu::dxil::module::opt, guarded lowering helpers and dead branches leave thousands of empty trampoline blocks ([Br(target)]), single-predecessor linear chains, and degenerateCondBr(c, t, t)/Switchterminators in the emitted DXIL.What is in it
crates/xcl/src/gpu/dxil/module/opt.rs: add a fixed-pointModule::simplify_cfgpass after DCE (opt-out viaXCL_DXIL_NO_OPT=merge, orthogonal to dxil: fold constant CFG terminators after CSE #1818's constant-terminator folding):CondBr(_, t, t)toBr(t)and stripSwitchcases matchingdefault, updatingOp::Phiedge multiplicity to match.[Br(t)],b != 0,t != b) whenevert's phis allow it without creating conflicting incoming values or inflating multi-predecessor phi tables (!target_has_phi || total_edges <= 1).a -> balong unconditional branches, resolving single-input phis inb, updatingdef_block, and rewriting successor phis frombtoa(including loop backedges).CondBr/Switchcollapse, loop-latch merge with header-phi rewriting, and the multi-predecessor phi guard.Measured impact
XCL_DIRECT_DXIL=1 XCL_HEAP_WINDOWS=1,XCL_DXIL_NO_OPT=mergevs default): 2,682 / 2,682 strictly smaller, 0 larger (775,076,910->774,508,202B).95cc13288a27a96e): basic blocks 23,619 -> 20,506 (-13.2%, -3,113 blocks), IR lines 513,461 -> 504,122 (-9,339 lines), DXIL 3,345,980 -> 3,332,628 B (-0.40%).Tested
cargo test -p xcl --lib gpu::dxil -- --skip fuzz_validate_and_gpu: 123 passed, 0 failed, 3 ignored (including all 5 newopt::tests::simplify_cfg_*tests and GPU execution tests on RTX 3060 Ti).xcl shaders <pack> --direct --validate --sample 1000 --max-bytes 0 --split 1withXCL_HEAP_WINDOWS=1: 1,000 / 1,000 (100.0%) across CS (102), GS (18), MS (350), PS (440), VS (90) — 0 validator errors, 0 panics, 0 timeouts.Not tested
Regression run
Base (
main):PR (
e64bd17):AI use