Repository navigation
Conversation
`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.
Member
|
Diff audit on draft When ready to undraft: rebase onto |
Contributor
|
Verification on RTX 3060 Ti (Windows 11): merge conflict with current |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Module::optimizeonly 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=sccskips the step.TRANSLATOR_VERSIONgoes 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 IRgpu/dxil/kernel.rs:TRANSLATOR_VERSION8Tested
These runs are from before the final rebase, on a combined branch (
01db80a, based on maine9e94ce; it holds this change plus four other changes), not on this PR's head commit.cargo testdebug 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 betweene9e94ceandf5136a6. 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-smokeblocks for this change.Not tested
f5136a6) has not been built or tested: it was rebased on macOS, with no Rust toolchain.cargo test --workspacewas not run for this change on its own.opt.rsare expected with dxil: fold constant CFG terminators after CSE #1818, Recompiler: fold 64-bit ints, bitcast selects and commutative CSE in direct DXIL #1906 and Recompiler: invalidate block-local DXIL CSE wave/quad cache across dx.op.discard #1930; whichever lands later needs a rebase.AI use