Recompiler: fold zext(i1) boolean comparisons and trunc in direct DXIL opt #2278
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!2278
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2278"
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:06 UTC · original
ramon-victor:opt/dxil-fold-zext-bool-cmp→main· +135 −0 · 1 files · 1 commits · openFolds
icmpcomparisons against integer constants andtrunc ... to i1onzext i1 %c to iNinsideModule::simplify_op(gpu::dxil::module::opt).In direct DXIL lowering, scalar condition codes (
SCC) and boolean results stored in integer registers are widened withzext i1 %c to i32and subsequently tested withicmp ne %scc, 0(e.g. fors_cbranch_scc1,s_cselect_b32,s_cmov_b32). Evaluating the comparison against{0, 1}directly collapses identity tests (ne 0,eq 1,ugt 0,uge 1,sgt 0,sge 1, and their commuted forms) back to%cand always-true/always-false range tests (eq 2,ne 2,ult 2,slt 0, etc.) toi1constants without creating new instructions, letting DCE remove the deadzextandicmp.Part of #1269.
What is in it
crates/xcl/src/gpu/dxil/module/opt.rs:Module::zext_i1_innerto matchCastOp::ZExtfromi1.Module::simplify_op, foldOp::Cmpwhen one operand iszext i1 %c to iW(2 <= W <= 32) and the other is an integer constant, returning%cor a constanti1whenever the{0, 1}truth table requires no new instruction (leaving negated compares such aszext(c) == 0intact).Module::simplify_op, foldtrunc (zext i1 %c to iW) to i1directly to%c.simplify_op_folds_zext_i1_comparisons_and_truncanddirect_scc_branch_drops_zext_icmp_roundtripunit + DXIL validation/disassembly tests.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,249,464 B(-74,272 B,-0.18%)263.12 ms -> 260.53 msTested
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):8 passed; 0 failed(including both new tests)..\scripts\test.ps1(debug, full workspace):1252 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
zext(i1)comparison andtruncfolding inmodule/opt.rs, added IR and DXIL disassembly/validation tests, and ran the workspace test suite, 573-shader validation benchmark, and 60 s smoke regression run.@itsSio on GitHub · 2026-11-25 12:34 UTC · original
Tested
Clean PR head
cbfb4ee11d758687e5a8b0d842a8e5a53d9621f8, Windows 11 Pro build 26200, x64 MSVC, unoptimized dev/test profiles with debug info off.cargo build --workspace --lockedpassed on both PCs.cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --nocapture:SKIPPED32.0.16.108832.0.16.1088cargo test -p xcl --lib --locked gpu::dxil::module::opt::tests -- --test-threads=1 --nocapture: 8 / 0 / 0, no runtime skips, on both PCs. Both new tests passed: boolean folding and direct SCC branch lowering. They check the optimizer and generated DXIL, not GPU readback.The RTX 2080 SUPER workspace failed at
vfs_hooks::tests::move_with_locked_overlay_source_preserves_destination: “move should succeed after the source handle closes.” Running that test alone on the same head (cargo test -p xcl --lib --locked vfs_hooks::tests::move_with_locked_overlay_source_preserves_destination -- --exact --test-threads=1 --nocapture) passed on both PCs (1 / 0 / 0, no skips). The original workspace failure stands; the isolated passes do not establish its cause.Not tested
Exact parent, AMD, native wave64, retail samples, and performance.
AI use
Ran via Samaritan:
openai/gpt-6.2-sol): ran both PCs' checks, audited logs, and wrote this report. No subagents contributed.@nnonno91 on GitHub · 2026-11-25 15:10 UTC · original
Independent Windows test of
cbfb4ee11d758687e5a8b0d842a8e5a53d9621f8. The optimized comparison selected the expected value for true and false inputs on both adapters.Tested
cargo test --locked -p xcl --lib gpu::dxil::module::opt::tests -- --nocapture --test-threads=1once per explicitly selected adapter. Each run reported 8 passed, 0 failed, 0 ignored, and no logged skips.u32::MAX. The logs confirmed all four results on Radeon integrated graphics and RTX 5090.Not tested
A separate GPU control-flow branch fixture, the parent revision, retail titles, or the full workspace suite. The fixture extension was temporary.
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!
@raylitebull on GitHub · 2026-11-25 18:41 UTC · original
Diff review, CI, and both AMD and NVIDIA checks passed on
cbfb4ee, but recentorigin/mainmerges turned this branchCONFLICTING/DIRTY. Please rebase ontoorigin/mainso it becomes mergeable again.@emirduran707 on GitHub · 2026-11-25 18:46 UTC · original
Independent AMD RDNA4 (native wave64) test report on exact head
cbfb4ee11d758687e5a8b0d842a8e5a53d9621f8(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: 1250 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_zext_i1_comparisons_and_truncanddirect_scc_branch_drops_zext_icmp_roundtrip.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
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.Merge
Merge the changes and update on Forgejo.