Recompiler: fold zext(i1) boolean comparisons and trunc in direct DXIL opt #2268
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/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?
Imported from ivall/xcl. Originally posted by ramon-victor on 2026-11-25T12:06:21Z.
Folds
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.Imported from ivall/xcl. Originally posted by itsSio on 2026-11-25T12:34:03Z.
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.Imported from ivall/xcl. Originally posted by nnonno91 on 2026-11-25T15:10:36Z.
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.
Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-25T17:05:12Z.
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!
Imported from ivall/xcl. Originally posted by raylitebull on 2026-11-25T18:41:02Z.
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.Imported from ivall/xcl. Originally posted by emirduran707 on 2026-11-25T18:46:49Z.
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
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T07:44:02Z.
Triage (#1607) – head
cbfb4eeNo open or merged PR makes the same change. Main's
simplify_opingpu/dxil/module/opt.rsfolds compares only when both operands are constants or the same value, and does not foldtrunc(zext i1). The new fold evaluates the compare for 0 and 1, folds it to a constant or to the i1 when that is valid, and leaves the negated case alone. The swapped predicates and signed evaluation look right. The PR conflicts with main.Recommendation: keep open.
AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.