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.

TRANSLATOR_VERSION goes from 7 to 8 because the output changes. #1793 and other changes to the direct translator also set 8; identical edits merge silently, so whichever lands later should take the next free number.

Draft: the head commit has not been built or tested yet.

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
  • gpu/dxil/kernel.rs: TRANSLATOR_VERSION 8

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.

  • 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. Since the tested commit the only code difference in this change is the version number (then 6 → 7).

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 the rebase and updated the commit message.

`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. The output changes, so
TRANSLATOR_VERSION goes to 8 (main is at 7). Other open changes also
bump it to 8: whichever lands later takes the next free number.

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.
@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.

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