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

Open
github-bot wants to merge 1 commit from github-bot/gh-1938 into main AGit
Owner

@⁠mastrr9 on GitHub · 2026-11-24 23:43 UTC · original
mastrr9:feat/dxil-drop-redundant-phi-sccs → main · +325 −2 · 1 files · 1 commits · draft

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

  • The head commit has not been built for Windows or tested.
  • cargo test --workspace was not run for this change on its own.
  • AMD and Intel GPUs; release build.
  • Effect on driver compile time or frame time.
  • Textual conflicts in opt.rs are expected with #1818, #1906 and #1930; whichever lands later needs a rebase.

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.
**@⁠mastrr9** on GitHub · 2026-11-24 23:43 UTC · [original](https://github.com/xcl-dev/xcl/pull/1938) `mastrr9:feat/dxil-drop-redundant-phi-sccs` → `main` · +325 −2 · 1 files · 1 commits · draft `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`](https://github.com/mastrr9/xcl/commit/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** - The head commit has not been built for Windows or tested. - `cargo test --workspace` was not run for this change on its own. - AMD and Intel GPUs; release build. - Effect on driver compile time or frame time. - Textual conflicts in `opt.rs` are expected with #1818, #1906 and #1930; whichever lands later needs a rebase. **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.
`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 (#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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:10:36 +00:00
Author
Owner

@⁠raylitebull on GitHub · 2026-11-25 01:08 UTC · original

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.

**@⁠raylitebull** on GitHub · 2026-11-25 01:08 UTC · [original](https://github.com/xcl-dev/xcl/pull/1938#issuecomment-7149246069) 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.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-25 02:41 UTC · original

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

**@⁠DavidM1911** on GitHub · 2026-11-25 02:41 UTC · [original](https://github.com/xcl-dev/xcl/pull/1938#issuecomment-7151044709) Verification on RTX 3060 Ti (Windows 11): **merge conflict with current `main`** — needs a rebase before it can be tested.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-26 00:42 UTC · original

Re-verification on RTX 3060 Ti (Windows 11): still a merge conflict with current main on the new head — needs another rebase before it can be tested.

**@⁠DavidM1911** on GitHub · 2026-11-26 00:42 UTC · [original](https://github.com/xcl-dev/xcl/pull/1938#issuecomment-7179040571) Re-verification on RTX 3060 Ti (Windows 11): still a **merge conflict with current `main`** on the new head — needs another rebase before it can be tested.
This pull request has changes conflicting with the target branch.
  • crates/xcl/src/gpu/dxil/module/opt.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1938/head:github-bot/gh-1938'
git switch 'github-bot/gh-1938'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1938'
git switch 'github-bot/gh-1938'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1938'
git switch 'github-bot/gh-1938'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1938'
git switch 'main'
git merge --squash 'github-bot/gh-1938'
git switch 'main'
git merge --ff-only 'github-bot/gh-1938'
git switch 'main'
git merge 'github-bot/gh-1938'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.