Skip to content

Recompiler: collapse empty trampolines and merge linear blocks in direct DXIL opt - #2194

Open
zondy1i wants to merge 1 commit into
xcl-dev:mainfrom
zondy1i:dxil/opt-cfg-cleanup
Open

zondy1i wants to merge 1 commit into
xcl-dev:mainfrom
zondy1i:dxil/opt-cfg-cleanup

Conversation

@zondy1i

@zondy1i zondy1i commented Nov 25, 2026 •

Copy link
Copy Markdown

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 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%).

Tested

  • Windows 11, AMD Ryzen 5 7500F, 64 GB RAM, NVIDIA GeForce RTX 3060 Ti 8 GB (driver 621.01), Rust 1.100.0 MSVC, DXC/dxil 1.9.2602.17.
  • cargo test -p xcl --lib gpu::dxil -- --skip fuzz_validate_and_gpu: 123 passed, 0 failed, 3 ignored (including all 5 new opt::tests::simplify_cfg_* tests and GPU execution tests on RTX 3060 Ti).
  • xcl shaders <pack> --direct --validate --sample 1000 --max-bytes 0 --split 1 with XCL_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

  • AMD / Intel GPUs, Linux / vkd3d-proton, cold cache-off NVIDIA driver compile timings (Windows Developer Mode is disabled on this machine).

Regression run
Base (main):

xcl-smoke v1
commit: 568e7db7729c8fa6c8f0f4b32d798faaf11462bb
gpu: NVIDIA GeForce RTX 3060 Ti
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1580 (PresentX 1580)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15495 MB

PR (e64bd17):

xcl-smoke v1
commit: e64bd17bc43714c2b3ac940da33a7be84d30999c
gpu: NVIDIA GeForce RTX 3060 Ti
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1542 (PresentX 1542)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15367 MB

AI use

  • Implemented, tested, and described with Antigravity (Gemini 4 Neon).

@DarkPanda69

Copy link
Copy Markdown

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 main 568e7db, 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:

main this PR
RX 9070 XT (RDNA4, 32.0.32029.2010, native wave64) 583 passed, 3 failed, 22 ignored, 6 SKIPPED 588 passed, 3 failed, 22 ignored, 6 SKIPPED
RTX 3060 (32.0.16.1088, wave32, split wave64) 585 passed, 1 failed, 22 ignored, 23 SKIPPED 590 passed, 1 failed, 22 ignored, 23 SKIPPED

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants