Recompiler: fold shift-masks, nested masks, double-xor, and all-ones or in direct DXIL opt #2279
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!2279
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/2279/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@ramon-victor on GitHub · 2026-11-25 12:11 UTC · original
ramon-victor:opt/dxil-algebraic-bitmask-folds→main· +164 −1 · 1 files · 1 commits · merged 2026-11-25 18:37 UTCAdds zero-allocation algebraic bitmask and identity simplifications to
Module::simplify_op(gpu::dxil::module::opt) for<= 32-bit integerOp::Bininstructions:orabsorption (x | ~0 -> ~0,~0 | x -> ~0) and0 >>a x -> 0.xorcancellation ((x ^ k) ^ k -> xin all operand orders, collapsing doublelnot/ bitwisenot).(x >>u s) & m -> x >>u swhen(mask >> s) & m == (mask >> s)(e.g.(x >> 24) & 0xFFinv_cvt_f32_ubyte3,(x >> 16) & 0xFFFF,(x >> 31) & 1), or0when disjoint.(x << s) & m -> x << swhen((mask << s) & mask) & m == ((mask << s) & mask)(e.g.(x << 2) & ~3in dword-aligned buffer addressing), or0when disjoint.((x & c1) & c2) -> x & c1whenc1 & c2 == c1(or0whenc1 & c2 == 0), and((x | c1) | c2) -> x | c1whenc1 | c2 == c1(or~0whenc1 | c2 == ~0).zext(i1):zext(i1) & m -> zext(i1)whenm & 1 != 0, or0whenm & 1 == 0.All rules return existing dominating SSA values or constants without creating instructions and keep
w > 32untouched soInt64Opsflags stay consistent.Part of #1269.
What is in it
crates/xcl/src/gpu/dxil/module/opt.rs: add the above algebraic bitmask and identity folds insideModule::simplify_op, plussimplify_op_folds_bitmasks_double_xor_and_all_ones_ortesting every rule and verifying SSA well-formedness.On a seeded 600-program sample (
xcl shaders <archive> --direct --sample 600 --seed 3 --max-bytes 40000 --validate --threads 8, 573 programs within the cap), all 573/573 validate cleanly (0validator failures):41,323,736 B -> 41,273,276 B(-50,460 B,-0.12%)Tested
621.24, wave32), AMD Ryzen 7 5700X, Windows 11 Pro26300,rustc 1.99.0(x86_64-pc-windows-msvc), DXC/DXIL1.8.2502.11(Windows SDK10.0.26100.0).cargo test -p xcl --lib gpu::dxil::module::opt::tests(debug):7 passed; 0 failed(includingsimplify_op_folds_bitmasks_double_xor_and_all_ones_or)..\scripts\test.ps1(debug, full workspace):1251 passed; 0 failed; 46 ignored(25 GPU sub-checks skipped on this wave32 adapter: 21no wave64, 1no heap windows, 3 per-lane#1426refusals).cargo build --release -p xcl+ direct DXIL validation sweep on 573 sampled retail shader programs:573/573translated anddxil.dll-validated (0failures).Regression run
Not tested
XCL_SAMPLE_*env vars unset).AI use
orfolds inmodule/opt.rs, added unit tests covering each rule, and ran the workspace test suite, 573-shader validation benchmark, and 60 s smoke regression run.@itsSio on GitHub · 2026-11-25 12:41 UTC · original
Tested
Independent verification on clean
38f47bfaf1d00332560535c8f202482cf77d630e, Windows 11 Pro build 26200, x64 MSVC, unoptimized dev/test profiles with debug info off.cargo build --workspace --lockedandcargo test --workspace --locked --no-fail-fast -- --test-threads=4 --nocaptureexited 0 on both PCs.SKIPPED32.0.16.108832.0.16.1088cargo test -p xcl --lib --locked gpu::dxil::module::opt::tests -- --test-threads=1 --nocapture: 7 passed / 0 failed / 0 ignored, zero runtime skips on both PCs. This includes the synthetic test for the bitmask, double-XOR and all-ones OR folds and SSA well-formedness. That test checks optimizer behavior, not GPU output.Not tested
Exact parent, AMD or Intel, native wave64, title samples, or performance.
AI use
Ran via Samaritan:
openai/gpt-6.2-sol): scoped and ran the two-PC verification, audited the logs, and wrote this report. No subagents contributed.@nnonno91 on GitHub · 2026-11-25 15:13 UTC · original
Independent Windows test of
38f47bfaf1d00332560535c8f202482cf77d630e. The optimizer tests passed on the PR head, and the new test caught the old behavior when run with the parent optimizer.Tested
cargo test --locked -p xcl --lib gpu::dxil::module::opt::tests -- --nocapture --test-threads=1reported 7 passed, 0 failed, 0 ignored, and no logged skips.1a0bbe3a2ba91ea8f5b6fc29130a053868d3c9e6, keeping the head's test module.cargo test --locked -p xcl --lib simplify_op_folds_bitmasks_double_xor_and_all_ones_or -- --nocapture --test-threads=1reported 0 passed, 1 failed, 0 ignored, and no logged skips. The first assertion caught thator(x, ~0)still returned an instruction instead of the constant0xffffffff. Restored the clean head afterward.Not tested
GPU shader execution, performance, retail titles, or the full workspace suite.
AI use
OpenAI Codex (GPT-6.2 Sol) prepared and ran the tests, verified the results, and wrote this report.
@DavidM1911 on GitHub · 2026-11-25 17:05 UTC · original
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.)Thanks!
@emirduran707 on GitHub · 2026-11-25 18:00 UTC · original
Independent AMD RDNA4 (native wave64) test report on exact head
38f47bfaf1d00332560535c8f202482cf77d630e(clean detached checkout, no local changes).Tested
stable-x86_64-pc-windows-msvc), DXC 1.9.2602.17; tests debug, smoke release.cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4: 1249 passed, 2 failed, 46 ignored; 8 SKIPPED (6 inlower_dxil::tests::{f16,f32}_programs_on_the_gpurefused by per-lane form;heap_window_out_of_memory_falls_back_to_the_switch_form;pso_measurement_compiles_an_exact_synthetic_record). All native wave64 GPU tests ran and passed.gpu::dxil::module::opt::tests::simplify_op_folds_bitmasks_double_xor_and_all_ones_or.gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1seed 722 andfuzz_validate_and_gpu_3seed 1599) are pre-existing on unmodifiedmainon this GPU.Regression run (60 s retail-title smoke,
XCL_NETWORK=0, release)(Matched
main68a284abaseline on the same machine today: 1573 frames, 14420 MB peak, 0 device removals, 0 crashes.)Not tested
AI use