Skip to content

Recompiler: direct DXIL drops phi groups that pass one value around - #1938

Draft
mastrr9 wants to merge 1 commit into
xcl-dev:mainfrom
mastrr9:feat/dxil-drop-redundant-phi-sccs
Draft

mastrr9 wants to merge 1 commit into
xcl-dev:mainfrom
mastrr9:feat/dxil-drop-redundant-phi-sccs

Conversation

@mastrr9

@mastrr9 mastrr9 commented Nov 24, 2026 •

Copy link
Copy Markdown

Module::optimize only removes a phi that is trivial on its own, so loops leave cycles of phis that name each other plus one value. This removes such groups with Tarjan SCCs over the phi operand graph (Braun et al., CC 2013). XCL_DXIL_NO_OPT=scc skips the step.

No TRANSLATOR_VERSION change: #1947 hashes the gpu/dxil sources into the translation cache's identity.

Draft: the head commit 0fda14f (rebased onto main 568e7db) has only been type-checked; Windows tests, GPU verification and the regression run are still to do.

What is in it

  • gpu/dxil/module/opt.rs: the pass, run after trivial phis and again after CSE, with four tests on hand-built IR

Tested
These runs are from before the final rebase, on a combined branch (01db80a, based on main e9e94ce; it holds this change plus four other changes), not on this PR's head commit. On the head commit, cargo check --locked --workspace --all-targets --target x86_64-pc-windows-msvc on macOS (Rust 1.100.0, the C compiler for one dependency stubbed out) finished with no errors; nothing was run.

  • Windows 11 x64, NVIDIA GeForce RTX 5080 16 GB, cargo test debug build. Driver, CPU and Rust versions were not recorded.
  • cargo test -p xcl --lib gpu::dxil::module::opt -- --test-threads=1: 4 passed, 0 failed.
  • direct_dxil_size_report (a synthetic size report that is on that branch, not in this PR), pass off (XCL_DXIL_NO_OPT=scc) → on, totals: phis 194 → 173, instructions 4027 → 4000, selects 191 → 185, bytecode 120800 B → 120640 B. The tree also had a lane-bit folding change, on in both runs.
  • gpu/dxil/module/ is unchanged between e9e94ce and f5136a6. The rebase onto 568e7db leaves the pass and its tests as they were; the tests now share one mod tests with a test that main added to opt.rs.

Regression run
Not run: there are no xcl-smoke blocks for this change.

Not tested

AI use

  • Code and tests: written by Claude Opus 5.5 in an agent session (Duet) with no Windows or GPU.
  • RTX 5080 test runs above: a Claude Sonnet 5.5 agent.
  • Overlap check, rebase and this description: Claude Code, Claude Sonnet 5.5; it also set the version to 8 during an earlier rebase and updated the commit message.
  • Latest rebase (version bump dropped), commit message and description update, and the type check: Claude Code, Claude Sonnet 5.5.

@raylitebull

Copy link
Copy Markdown
Member

Diff audit on draft 47170bf (redundant_phi_sccs Tarjan SCC removal before and after CSE, plus sub-SCC handling and tests) looks clean.

When ready to undraft: rebase onto main (dropping the manual TRANSLATOR_VERSION = 8 bump in kernel.rs, as #1947 now auto-hashes gpu/dxil sources), add the xcl-smoke block for PR description, and add AMD + NVIDIA verification.

@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11): merge conflict with current main — needs a rebase before it can be tested.

`Module::optimize` replaces a phi only when it is trivial on its own
(every incoming value the phi itself or one other value). A loop whose
body sets a register back to the value it had before the loop (a copy,
a constant, or two copies of one expression that CSE merges) leaves a
cycle of phis that name each other plus that one value: the loop
header's phi takes the value and the join's phi, the join's phi takes
the header's phi and the value. Neither is trivial alone, so both were
written, with their uses.

Remove such groups as Braun et al. ("Simple and Efficient Construction
of Static Single Assignment Form", CC 2013) do: Tarjan's strongly
connected components over the phi operand graph, operands first; a
component whose operands outside it are all one value becomes that
value; a component with several outside values is a real merge, and
the phis in it that name only its members are searched again for such
a group. The step runs after the trivial phis (so CSE sees the
replacements) and once more after CSE (groups whose definitions CSE
merged). `XCL_DXIL_NO_OPT=scc` skips it. No TRANSLATOR_VERSION change:
the translation cache's identity includes a hash of the `gpu/dxil`
sources (xcl-dev#1947).

Tests build the IR by hand: a redundant two-phi loop cycle, the same
loop with a real second value (kept), a redundant inner group inside a
real outer merge, and a cycle that is redundant only after CSE.
@mastrr9
mastrr9 force-pushed the feat/dxil-drop-redundant-phi-sccs branch from 47170bf to 0fda14f Compare November 25, 2026 07:50
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.

3 participants