Recompiler: prune unused module constants and dead-aggregate globals in direct DXIL bitcode #2630
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2640"
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?
Imported from ivall/xcl. Originally posted by Decodere on 2026-11-26T04:24:28Z.
What is in it
Prunes unused module constants and fixes dead-aggregate global/function retention during direct DXIL bitcode serialization in
crates/xcl/src/gpu/dxil/module.rs:Module::live_values): Computes(gused, fused, cused)over reachable blocks (order) and metadata (MdDef::Val), seedingOp::Callcallees + args, only reachable incoming edges ofOp::Phi(matchingwrite_inst), and all otherOp::for_each_operandoperands. TracesGlobalDef::initandConstDef::Aggregateelements only once the owning global or constant is marked live.write_bitcodescanned everyConstDef::Aggregateinself.consts, so an unreferenced aggregate referencing an otherwise-unused internal global or function kept that declaration alive in the emitted module.BLOCK_CONSTANTSwithout mutatingModule: Buildscmap: Vec<Option<u64>>in original constant order (preservingelem_idx < agg_idxordering forCST_CODE_AGGREGATE), mapsValue::Const(c)throughconst_base + cmap[c], omitsBLOCK_CONSTANTSwhenn_consts == 0, and emits onlycusedentries while keepingwrite_bitcodeidempotent.Part of #2508
Part of #1833
Tested
live_valuessemantics (cargo test --release -p xcl --lib "gpu::dxil::module::tests::" -- --test-threads=1 --nocapture):3 passed; 2 failed; 0 ignored:unused_scalar_constants_produce_identical_bitcodefailed (dead constant 3 retained)dead_aggregate_does_not_retain_unused_global_while_live_global_init_is_keptfailed (unexpected global liveness: [true, true, false], confirmingdead_aggretainedg_dead_inner)XCL_ADAPTER=warp,XCL_WARP=1,cargo test --release -p xcl --lib "gpu::dxil::module::tests::" -- --test-threads=1 --nocapture):5 passed; 0 failed; 0 ignored; 0 skipped(0.01s, DXC1.9.2609.5validated and disassembled the pruned shader container; zero warnings inmodule.rs).cargo test --release -p xcl --lib "gpu::dxil::" -- --test-threads=1 --nocapture):187 passed; 0 failed; 3 ignored(36.91s,gpu::dxil::module::tests::5/0/0,0skipped;1pre-existingSKIPPED:gpu::dxil::kernel::dispatch_chain_native_wave64_builds_whole: no wave64).Regression run
Full release workspace on RTX 4060 (
cargo test --release --workspace --no-fail-fast -- --test-threads=4 --nocapture):37test binaries,1438 passed; 0 failed; 47 ignored,29pre-existing environment-gatedSKIPPEDlines:21skipped:no wave64(RTX 4060 is wave32)3skipped: wave32per-lane form: refusedby driver (f16 arithmetic,f16 packed,f32 conversions)3skipped: no D3D12 debug layer (d3d12SDKLayers.dllunavailable on host: debug-layerdred: false/trueanduploads_start_from_each_subresources_state)1skipped:pso_measurement_compiles_an_exact_synthetic_record(cannot disable driver cache on Windows)1skipped:heap_window_out_of_memory_falls_back_to_the_switch_form(no heap windows)Paired 60 s RTX 4060 smoke capture (
scripts/smoke.ps1):Base (
origin/mainb49be1836844fe0b0cdb3211dce3cb7fb4e21ac7):PR (
b7cfe9b224f31ddf6ba06c2d614bc446132b6062):Not tested
29host-gated workspace tests skipped on this RTX 4060 machine (wave64 hardware, wave32 per-lane driver support, D3D12 SDK debug layer, driver cache disable, and heap windows).AI use
Google Antigravity (Gemini 4 Neon) wrote the patch, unit tests, and PR description; all commands, test runs, and paired 60 s GPU smoke captures were executed directly in this workspace.
Imported from ivall/xcl. Originally posted by DarkPanda69 on 2026-11-26T04:37:33Z.
Native wave64 run (the wave64 tests skipped on the RTX 4060) on an AMD RX 9070 XT, plus an RTX 3060: the 3 new tests pass, and nothing else changes in the direct-DXIL GPU suite.
Head
b7cfe9bapplied onmainb49be18, debug, Windows 11 Pro 26200,XCL_DIRECT_DXIL=1 cargo test -p xcl --lib -- gpu:: --test-threads=4onmainand with the PR, card chosen withXCL_ADAPTER:mainOn both cards, the only result changes against
mainare the newdead_aggregate_does_not_retain_unused_global_while_live_global_init_is_kept,pruned_direct_dxil_shader_with_live_table_and_dead_constants_validatesandunused_scalar_constants_produce_identical_bitcode, all ok, with no new skips. So every direct-DXIL program in the suite, including the wave64 ones that skip on a 32-lane card, went through the pruned bitcode on the RX 9070 XT and still validates and runs. The 2 RX 9070 XT failures are the AMD fuzz seeds tracked in #2115, the same onmain.Not tested: cold-cache rebuild timings, the D3D12 debug-layer tests (no
d3d12SDKLayers.dllhere either), a title.AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report.
mainreaches on Windows; the obstacle is replaced vtables — proposal: proxies #172Imported from ivall/xcl. Originally posted by Kalmarv on 2026-11-29T00:49:23Z.
merge-check
base:
fa204595a4head:
b7cfe9b224merge: clean, but empty: the trial merge
ea280e32has no diff against main. This PR's commit has the same patch-id (d250b5ff) as main's09a65d63("Recompiler: prune unreachable direct-DXIL module values", bmjask, 2026-11-26, "Adapted from PR #2640"), which came in with bmjask's stack.build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 (XCL_DXC_DIR = DXC 1.9.2609) -> 2608 passed, 0 failed, 49 ignored; SKIPPED: 26 (21 no wave64 on this 32-lane GPU, 3 per-lane f16/f32 forms refused (#1426 semantics), 2 no heap windows); failing: none. The 3 tests (
unused_scalar_constants_produce_identical_bitcode,dead_aggregate_does_not_retain_unused_global_while_live_global_init_is_kept,pruned_direct_dxil_shader_with_live_table_and_dead_constants_validates) ran and passed. They are main's own copies:cargo test -p xcl --lib -- --listgives the same 2,498 names on main and on the merge.review: whole diff read before I found it on main; no findings. Every constant id goes through
cmap. Phi incomings from unreachable blocks are skipped in both the liveness walk and the writer (sameposfilter).for_each_operandcovers everyOp, including Switch cases, Alloca sizes and GEP indices. Live globals pull in their initializers, and dead aggregates no longer keep globals alive. All of this already holds on main.performance: nothing to measure; merging changes no file.
verdict: not yet: already on main as
09a65d63(same patch); merging adds nothing. This should be closed as merged (#1607: a PR that duplicates one already merged is closed).hardware / tool and model: NVIDIA GeForce RTX 5070 Ti 16 GB (driver 610.74, wave32 only), AMD Ryzen 9 9950X, Windows 11 build 26200; rustc 1.99.0, debug test profile, DXC 1.9.2609 via XCL_DXC_DIR. Claude Code, Claude Opus 5.5: merge, build, suite, patch-id comparison and diff review; this report.
Imported from ivall/xcl. Originally posted by throny on 2026-11-29T03:42:08Z.
merge-check claim
head:
b7cfe9b224Imported from ivall/xcl. Originally posted by throny on 2026-11-29T03:45:17Z.
merge-check
base:
fa204595head:
b7cfe9b224merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2608 passed, 0 failed, 49 ignored: exactly the base's result, because the merge changes nothing (27 SKIPPED lines). Base alone at
fa204595: 2608 passed, 0 failed, 49 ignored.review: the whole change is already on main: commit
09a65d63("Recompiler: prune unreachable direct-DXIL module values") is an ancestor offa204595, the PR's diff reverses cleanly on main's module.rs, and a trial merge of this head gives main's own tree. This agrees with the other check in the thread. The code itself had no finding (every constant id is renumbered through one map, liveness walks reachable blocks and metadata, and the pass iterates vectors only, so its output is deterministic).performance: nothing to add on main.
verdict: not yet: nothing to merge; already in main through
09a65d63, so this PR can be closed.hardware / tool and model: RTX 4080 16 GB (621.40), i9-12900K, Windows 11 26300, Rust 1.100.0, debug. Claude Code; merge, build and suite run by Claude Fable 5.2, diff review by Claude Opus 5.5 (every hunk read; nothing run on the GPU beyond the suite).
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T08:31:57Z.
Triage (#1607) – head
b7cfe9bmain has this change. Commit
09a65d6("Recompiler: prune unreachable direct-DXIL module values") says it was adapted from this PR.gpu/dxil/module.rson main hasModule::live_valueswith the same transitive liveness over global initializers and aggregates, thecmapcompaction ofBLOCK_CONSTANTS, and the three tests (unused_scalar_constants_produce_identical_bitcode,dead_aggregate_does_not_retain_unused_global_while_live_global_init_is_kept,pruned_direct_dxil_shader_with_live_table_and_dead_constants_validates). The other PRs for #2508 (#2613, #2635, #2641, #2642, #2664, #2819) change other things.Recommendation: close (superseded by main commit
09a65d6).AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
Imported from ivall/xcl. Originally posted by throny on 2026-12-01T12:56:13Z.
Closing as superseded: this change is already on
main(09a65d6). git patch-id of the PR diff is identical to that of main commit09a65d6(ancestor of main)Two independent checks found this: Foniass's close list on #1607 and ours against current
main. If something here is still missing onmain, say so and reopen it, or ask and I will.AI use: Claude Code (Claude Opus 5.5); the per-PR comparison was done by Claude Sonnet 5.5 sub-agents.
Pull request closed