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

Open
mastrr9 wants to merge 1 commit from upstream-pr/1938 into main
mastrr9 commented 2026-11-24 23:43:51 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by mastrr9 on 2026-11-24T23:43:51Z.


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.
<!-- greyfinch-sync:ivall/xcl:issue:5482269167 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1938). Originally posted by [mastrr9](https://github.com/mastrr9) on 2026-11-24T23:43:51Z. --- `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.
raylitebull commented 2026-11-25 01:11:08 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by raylitebull on 2026-11-25T01:08:26Z.


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.

<!-- greyfinch-sync:ivall/xcl:comment:7149246069 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1938#issuecomment-7149246069). Originally posted by [raylitebull](https://github.com/raylitebull) on 2026-11-25T01:08:26Z. --- 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 commented 2026-11-25 03:05:47 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-25T02:41:09Z.


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

<!-- greyfinch-sync:ivall/xcl:comment:7151044709 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1938#issuecomment-7151044709). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-25T02:41:09Z. --- Verification on RTX 3060 Ti (Windows 11): **merge conflict with current `main`** — needs a rebase before it can be tested.
DavidM1911 commented 2026-11-26 01:05:42 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-26T00:42:53Z.


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.

<!-- greyfinch-sync:ivall/xcl:comment:7179040571 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1938#issuecomment-7179040571). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-26T00:42:53Z. --- 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.
github-actions[bot] commented 2026-11-30 08:40:31 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by github-actions[bot] on 2026-11-30T08:40:31Z.


Nothing has happened on this PR for 3 days, so it is marked stale and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto main if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.

<!-- greyfinch-sync:ivall/xcl:comment:7273202187 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1938#issuecomment-7273202187). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-11-30T08:40:31Z. --- Nothing has happened on this PR for 3 days, so it is marked `stale` and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto `main` if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.
Foniass commented 2026-12-01 07:07:53 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T07:07:53Z.


Triage (#1607) – head 0fda14f

No open or merged PR removes redundant phi SCCs in gpu/dxil/module/opt.rs. Main's #3269 (fixed-point optimizer) and #2194 (CFG merges) add other passes. Main still only removes single trivial phis (simplify_phis).
To keep after the rebase: main's 5a984e02 (keep backedge values behind loop phis) refuses to replace a phi with a value serialized after it (inst_at[j] < inst_at[i]). redundant_phi_sccs also handles single-phi components: iv = phi [iv, entry], [next, latch] forms the SCC {iv} with one outside value next. Without the same availability check, it would put back exactly the replacement that main's fix took out (test trivial_loop_phi_keeps_backedge_definition_after_header_uses).
Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

<!-- greyfinch-sync:ivall/xcl:comment:7303680711 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1938#issuecomment-7303680711). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T07:07:53Z. --- **Triage (#1607)** – head 0fda14f No open or merged PR removes redundant phi SCCs in `gpu/dxil/module/opt.rs`. Main's #3269 (fixed-point optimizer) and #2194 (CFG merges) add other passes. Main still only removes single trivial phis (`simplify_phis`). To keep after the rebase: main's 5a984e02 (`keep backedge values behind loop phis`) refuses to replace a phi with a value serialized after it (`inst_at[j] < inst_at[i]`). `redundant_phi_sccs` also handles single-phi components: `iv = phi [iv, entry], [next, latch]` forms the SCC `{iv}` with one outside value `next`. Without the same availability check, it would put back exactly the replacement that main's fix took out (test `trivial_loop_phi_keeps_backedge_definition_after_header_uses`). Recommendation: keep open. AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/1938:upstream-pr/1938'
git switch 'upstream-pr/1938'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/1938'
git switch 'upstream-pr/1938'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1938'
git switch 'upstream-pr/1938'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1938'
git switch 'main'
git merge --squash 'upstream-pr/1938'
git switch 'main'
git merge --ff-only 'upstream-pr/1938'
git switch 'main'
git merge 'upstream-pr/1938'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl!1928
No description provided.