Recompiler: collapse empty trampolines and merge linear blocks in direct DXIL opt #2194
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!2194
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/2194/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?
@zondy1i on GitHub · 2026-11-25 08:45 UTC · original
zondy1i:dxil/opt-cfg-cleanup→main· +603 −2 · 1 files · 1 commits · merged 2026-11-25 10:44 UTCPart 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 #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
@DarkPanda69 on GitHub · 2026-11-25 09:00 UTC · original
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
e64bd17applied onmain568e7db, debug, Windows 11 Pro 26200,XCL_DIRECT_DXIL=1 cargo test -p xcl --lib -- gpu:: --test-threads=4, run onmainand on this PR for each card:mainPer-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 onmain:gpu_image_get_resinfo_1d_arrayon 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.
@NWProgramming00 on GitHub · 2026-11-25 09:09 UTC · original
Independent run on NVIDIA and on an AMD GPU with native wave64 (the AMD part is listed as not tested). Exact head
e64bd17, compared with its base568e7db.Hardware: Windows 11, NVIDIA GeForce RTX 5070 Ti 16 GB, and an AMD Radeon RDNA2 iGPU (gfx1036, native 64-lane waves) selected with
XCL_ADAPTER=radeon. Release builds.cargo build --release --workspacethencargo test --release --workspace --no-fail-fast -- --test-threads=4, each adapter with and withoutXCL_DIRECT_DXIL=all:568e7dbe64bd17XCL_DIRECT_DXIL=allXCL_DIRECT_DXIL=allopt::tests::simplify_cfg_*tests. They pass on both adapters.fuzz_validate_and_gpu_0..3on NVIDIA:CreateComputePipelineStatereturnsE_OUTOFMEMORY(#1905).fuzz_validate_and_gpu_1on the RDNA2 iGPU: seed 540,res[833] = 0x7, CPU 0x6(#2115, #2170).gpu_image_get_resinfo_1d_arraywithXCL_DIRECT_DXIL=all, both adapters: layers come back as 1 instead of 3 (#2046).offline_compute_pipeline_is_reused_by_a_second_processwithXCL_DIRECT_DXIL=all, both adapters (#1674).e2e.rs) pass 3/3 on both adapters.Not tested: cold-cache NVIDIA driver compile times, and a title run.
AI use: Claude Code (Claude Opus 5.5) ran the suites, compared them with the base and wrote this comment.
@bielfreedom on GitHub · 2026-11-25 10:41 UTC · original
AMD Windows driver timing for #2194: on the RX 9070 XT, AMD's
CreateComputePipelineStateis about the same speed with this change, except one program that builds 16 % faster. This adds driver timing to DarkPanda69's GPU suite run on the same card.Setup
568e7db;e64bd17.fnv64) and per-CreateComputePipelineStatetime.Method
XCL_DIRECT_DXIL=1,XCL_HEAP_WINDOWS=0,XCL_PIPELINE_THREADS=1.XCL_PSO_DISK_CACHE=0and a fresh exe name per run, because the AMD driver cache is keyed on the exe file name.26 programs (means of 2 rounds; all 104 builds succeeded, 0 refused)
84eee477d68b6fdf(CS_RaytracingResolve), went 53.2 → 53.6 s.620491641aa9bad6, 17.9 → 15.1 s (−16 %). Its rounds were 17.93 / 17.90 s on base and 15.12 / 15.06 s on this PR. An earlier pair of base runs gave 17.7 s. Its DXIL shrinks by only 56 B, so the AMD compiler seems to react to the shape of the CFG rather than the size.ActivateRays (
95cc13288a27a96e), plain on this adapter, 1 run:Tests on this card (
XCL_REQUIRE_GPU=1,XCL_ADAPTER=9070)cargo test --release -p xcl --lib -- dxil::module::opt --test-threads=1: 6 passed, 0 failed.simplify_cfg_*tests.Read / inference
620491641aa9bad6is one of the two programs bobosneefdev reported as slow to build on AMD in #1269, so the 16 % there is the part that matters on this vendor.Not tested
gpu::suite on this build (DarkPanda69 covered it on this card).XCL_HEAP_WINDOWS=1.AI use: Claude Code (Claude Opus 5.5) ran the measurements and tests and drafted this. The account owner is away; counts and timings only, no game data.