Recompiler: lower direct DXIL float_compare to ordered/unordered fcmp #2258

Open
github-bot wants to merge 1 commit from github-bot/gh-2258 into main AGit
Owner

@⁠ramon-victor on GitHub · 2026-11-25 11:40 UTC · original
ramon-victor:opt/dxil-float-compare-fcmp → main · +115 −50 · 1 files · 1 commits · open

Lowers RDNA2 floating-point comparisons (Lw::float_compare, covering v_cmp*_f16, v_cmp*_f32, and v_cmp*_f64) in the direct DXIL translator directly to IEEE-754 ordered (FO*) and unordered (FU*) LLVM fcmp predicates instead of emitting explicit dx.op.isSpecialFloat(IsNaN) / splitDouble NaN checks around each compare.

Because the direct DXIL builder emits fcmp with zero fast-math flags, LLVM/DXIL olt, oeq, ole, ogt, one, oge, ord, uno, ult, ueq, ule, ugt, une, and uge already define exact NaN semantics in a single instruction (1 instruction instead of 3–8 per compare).

Part of #1269.

What is in it

  • crates/xcl/src/gpu/dxil/lower_valu.rs:
    • Replace Lw::float_compare's explicit isnan_any + or + xor + and wrapper with direct 1-to-1 Pred::FO* / Pred::FU* fcmp emission, and remove the now-unused Lw::isnan_any helper (+18/-51 production lines).
    • Add float_compare_tests::gpu_direct_float_compare_uses_fcmp_and_matches_ieee verifying DXIL validation and disassembly (every predicate emits the expected fcmp with no dx.op.isSpecialFloat or splitDouble NaN guards) and checking all 14 v_cmp_*_f32 predicates on the GPU across ±0.0, finite, ±Inf, qNaN, and sNaN pairs.

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 (0 validator failures):

  • Total emitted DXIL: 41,323,736 B -> 40,857,992 B (-465,744 B, -1.13%)

Tested

  • Hardware and toolchain: NVIDIA GeForce RTX 3070 (8 GiB, driver 621.24, wave32), AMD Ryzen 7 5700X, Windows 11 Pro 26300, rustc 1.99.0 (x86_64-pc-windows-msvc), DXC/DXIL 1.8.2502.11 (Windows SDK 10.0.26100.0).
  • cargo test -p xcl --lib gpu::dxil::lower_valu::float_compare_tests (debug): 1 passed; 0 failed.
  • XCL_DIRECT_DXIL=1 cargo test -p xcl --lib gpu_f32_compares (debug): 1 passed; 0 failed (gpu_f32_compares_with_nan on RTX 3070).
  • .\scripts\test.ps1 (debug, full workspace on head c204653): 1251 passed; 0 failed; 46 ignored (25 GPU sub-checks skipped on this wave32 adapter: 21 no wave64, 1 no heap windows, 3 per-lane #1426 refusals).
  • cargo build --release -p xcl + direct DXIL validation sweep on 573 sampled retail shader programs: 573/573 translated and dxil.dll-validated (0 failures).

Regression run

xcl-smoke v1
commit: f087b998d0d51a9f11bbfa0761967a63e778edd9
gpu: NVIDIA GeForce RTX 3070
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1618 (PresentX 1618)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14467 MB
xcl-smoke v1
commit: c2046530321844e65a64df2ef2ff78e15ac095ea
gpu: NVIDIA GeForce RTX 3070
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1618 (PresentX 1618)
presents per 2 s (last 3): 61 60 60
device removals: 0
crashes: 0
peak commit: 14470 MB

Not tested

  • Native wave64 GPU hardware (AMD/Intel): RTX 3070 only supports wave32, so native wave64 tests skip on this adapter.
  • Sample-gated tests (XCL_SAMPLE_* env vars unset).

AI use

  • Antigravity (Gemini 4 Neon): analyzed float_compare in lower_valu.rs, simplified it to direct LLVM fcmp predicates, wrote unit and GPU tests, rebased onto origin/main (1a0bbe3), and ran XCL_DIRECT_DXIL=1 compare tests, the full workspace test suite, the 573-shader validation benchmark, and the 60 s smoke regression run.
**@⁠ramon-victor** on GitHub · 2026-11-25 11:40 UTC · [original](https://github.com/xcl-dev/xcl/pull/2258) `ramon-victor:opt/dxil-float-compare-fcmp` → `main` · +115 −50 · 1 files · 1 commits · open Lowers RDNA2 floating-point comparisons (`Lw::float_compare`, covering `v_cmp*_f16`, `v_cmp*_f32`, and `v_cmp*_f64`) in the direct DXIL translator directly to IEEE-754 ordered (`FO*`) and unordered (`FU*`) LLVM `fcmp` predicates instead of emitting explicit `dx.op.isSpecialFloat(IsNaN)` / `splitDouble` NaN checks around each compare. Because the direct DXIL builder emits `fcmp` with zero fast-math flags, LLVM/DXIL `olt`, `oeq`, `ole`, `ogt`, `one`, `oge`, `ord`, `uno`, `ult`, `ueq`, `ule`, `ugt`, `une`, and `uge` already define exact NaN semantics in a single instruction (1 instruction instead of 3–8 per compare). Part of #1269. **What is in it** - `crates/xcl/src/gpu/dxil/lower_valu.rs`: - Replace `Lw::float_compare`'s explicit `isnan_any` + `or` + `xor` + `and` wrapper with direct 1-to-1 `Pred::FO*` / `Pred::FU*` `fcmp` emission, and remove the now-unused `Lw::isnan_any` helper (`+18/-51` production lines). - Add `float_compare_tests::gpu_direct_float_compare_uses_fcmp_and_matches_ieee` verifying DXIL validation and disassembly (every predicate emits the expected `fcmp` with no `dx.op.isSpecialFloat` or `splitDouble` NaN guards) and checking all 14 `v_cmp_*_f32` predicates on the GPU across `±0.0`, finite, `±Inf`, `qNaN`, and `sNaN` pairs. 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 (`0` validator failures): - Total emitted DXIL: `41,323,736 B -> 40,857,992 B` (`-465,744 B`, `-1.13%`) **Tested** - Hardware and toolchain: NVIDIA GeForce RTX 3070 (8 GiB, driver `621.24`, wave32), AMD Ryzen 7 5700X, Windows 11 Pro `26300`, `rustc 1.99.0` (`x86_64-pc-windows-msvc`), DXC/DXIL `1.8.2502.11` (Windows SDK `10.0.26100.0`). - `cargo test -p xcl --lib gpu::dxil::lower_valu::float_compare_tests` (debug): `1 passed; 0 failed`. - `XCL_DIRECT_DXIL=1 cargo test -p xcl --lib gpu_f32_compares` (debug): `1 passed; 0 failed` (`gpu_f32_compares_with_nan` on RTX 3070). - `.\scripts\test.ps1` (debug, full workspace on head `c204653`): `1251 passed; 0 failed; 46 ignored` (25 GPU sub-checks skipped on this wave32 adapter: 21 `no wave64`, 1 `no heap windows`, 3 per-lane `#1426` refusals). - `cargo build --release -p xcl` + direct DXIL validation sweep on 573 sampled retail shader programs: `573/573` translated and `dxil.dll`-validated (`0` failures). **Regression run** ``` xcl-smoke v1 commit: f087b998d0d51a9f11bbfa0761967a63e778edd9 gpu: NVIDIA GeForce RTX 3070 title: 3c290c16 seconds: 60 exit: 0x0 frames shown: 1618 (PresentX 1618) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14467 MB ``` ``` xcl-smoke v1 commit: c2046530321844e65a64df2ef2ff78e15ac095ea gpu: NVIDIA GeForce RTX 3070 title: 3c290c16 seconds: 60 exit: 0x0 frames shown: 1618 (PresentX 1618) presents per 2 s (last 3): 61 60 60 device removals: 0 crashes: 0 peak commit: 14470 MB ``` **Not tested** - Native wave64 GPU hardware (AMD/Intel): RTX 3070 only supports wave32, so native wave64 tests skip on this adapter. - Sample-gated tests (`XCL_SAMPLE_*` env vars unset). **AI use** - Antigravity (Gemini 4 Neon): analyzed `float_compare` in `lower_valu.rs`, simplified it to direct LLVM `fcmp` predicates, wrote unit and GPU tests, rebased onto `origin/main` (`1a0bbe3`), and ran `XCL_DIRECT_DXIL=1` compare tests, the full workspace test suite, the 573-shader validation benchmark, and the 60 s smoke regression run.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:24:51 +00:00
Author
Owner

@⁠DarkPanda69 on GitHub · 2026-11-25 12:35 UTC · original

Fails on AMD (native wave64), passes on NVIDIA. On an RX 9070 XT, the ordered not-equal compare returns true for a NaN input, in the new test and in the existing f32_programs_on_the_gpu, which passes on main.

Tested at head c204653 (as is, on main 1a0bbe3), debug, Windows 11 Pro 26200, DXC 1.9.2602.17, cargo test -p xcl --lib -- gpu_direct_float_compare_uses_fcmp_and_matches_ieee f32_programs_on_the_gpu --test-threads=1:

  • RX 9070 XT (RDNA4, driver 32.0.32029.2010, waves 32..64): 2 failed, 3 of 3 runs (also on the earlier head c7940b3):
    • gpu_direct_float_compare_uses_fcmp_and_matches_ieee: V_CMP_LG_F32 lane 8 (NaN, 0.0): got true, want false (core_tests.rs:673).
    • f32_programs_on_the_gpu: f32 compares, wave32: s10, left: 4294967291, right: 4008636138 (lower_dxil.rs:738).
  • RX 9070 XT on main 1a0bbe3: f32_programs_on_the_gpu passes, so this PR introduces the second failure.
  • RTX 3060 (driver 32.0.16.1088): both pass, at this head and on main.

So on this AMD driver the fcmp one (ordered not-equal) that V_CMP_LG_F32 now lowers to does not come out false for a NaN operand, where the removed explicit isnan guard did. Whole gpu:: filter at c7940b3: RX 9070 XT 625 passed, 5 failed (these 2, plus the #2115 fuzz seeds and gpu_image_get_resinfo_past_last_level that its old base still had); RTX 3060 630 passed, 0 failed.

Not tested: the other 13 predicates past the first failing assertion on AMD, RDNA2/RDNA3.
AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report.

**@⁠DarkPanda69** on GitHub · 2026-11-25 12:35 UTC · [original](https://github.com/xcl-dev/xcl/pull/2258#issuecomment-7162573382) **Fails on AMD (native wave64), passes on NVIDIA.** On an RX 9070 XT, the ordered not-equal compare returns true for a NaN input, in the new test and in the existing `f32_programs_on_the_gpu`, which passes on `main`. **Tested** at head `c204653` (as is, on `main` `1a0bbe3`), debug, Windows 11 Pro 26200, DXC 1.9.2602.17, `cargo test -p xcl --lib -- gpu_direct_float_compare_uses_fcmp_and_matches_ieee f32_programs_on_the_gpu --test-threads=1`: - **RX 9070 XT** (RDNA4, driver 32.0.32029.2010, waves 32..64): **2 failed**, 3 of 3 runs (also on the earlier head `c7940b3`): - `gpu_direct_float_compare_uses_fcmp_and_matches_ieee`: `V_CMP_LG_F32 lane 8 (NaN, 0.0): got true, want false` (`core_tests.rs:673`). - `f32_programs_on_the_gpu`: `f32 compares, wave32: s10`, `left: 4294967291`, `right: 4008636138` (`lower_dxil.rs:738`). - **RX 9070 XT on `main` `1a0bbe3`:** `f32_programs_on_the_gpu` passes, so this PR introduces the second failure. - **RTX 3060** (driver 32.0.16.1088): both pass, at this head and on `main`. So on this AMD driver the `fcmp one` (ordered not-equal) that `V_CMP_LG_F32` now lowers to does not come out false for a NaN operand, where the removed explicit `isnan` guard did. Whole `gpu::` filter at `c7940b3`: RX 9070 XT 625 passed, 5 failed (these 2, plus the #2115 fuzz seeds and `gpu_image_get_resinfo_past_last_level` that its old base still had); RTX 3060 630 passed, 0 failed. Not tested: the other 13 predicates past the first failing assertion on AMD, RDNA2/RDNA3. AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report.
Author
Owner

@⁠luckyteagirl on GitHub · 2026-11-25 12:47 UTC · original

Independent RDNA2 confirmation of the AMD NaN regression reported above, at exact PR head c2046530321844e65a64df2ef2ff78e15ac095ea versus main 1a0bbe3a2ba91ea8f5b6fc29130a053868d3c9e6.

Environment: Windows 11 build 26200; Ryzen 9 5980HX; Radeon RX 6800M driver 30.0.13002.13003 (native wave64); Rust 1.99.0 MSVC; DXC/DXIL 1.9.2609.5. Isolated worktrees and Cargo targets. Debug tests use XCL_ADAPTER=6800M, XCL_REQUIRE_GPU=wave64, -j 2, --test-threads=1, --show-output.

Results

  • On this PR, cargo test --locked -p xcl --lib gpu_direct_float_compare_uses_fcmp_and_matches_ieee with XCL_DIRECT_DXIL=1: 0 passed, 1 failed, 0 ignored, no skip. The assertion is exactly V_CMP_LG_F32 lane 8 (NaN, 0.0): got true, want false at lower_valu.rs:1420. This is a value mismatch after GPU execution, not a PSO/device-removal failure.
  • Existing f32_programs_on_the_gpu: main 1/0/0, PR 0/1/0 with XCL_DIRECT_DXIL=1. The PR fails f32 compares, wave32: s10 (left: 4294967291, right: 4008636138) at lower_dxil.rs:738.
  • The same existing-test control with XCL_DIRECT_DXIL=0 also passes on main 1/0/0 and fails on this PR 0/1/0 with the same s10 values. That test exercises its own DXIL path, so changing the environment flag does not remove the regression.

This extends the reported failure from RX 9070 XT/RDNA4 to RX 6800M/RDNA2. It is a reproducible PR-head regression against this main revision. I ran focused synthetic tests only; no full workspace suite or retail-title smoke on this head. No game data was used.

AI use: OpenAI Codex (GPT-6; exact variant not exposed in this session) ran the native Windows GPU tests and main/PR controls, checked the exact assertions, and drafted this report.

**@⁠luckyteagirl** on GitHub · 2026-11-25 12:47 UTC · [original](https://github.com/xcl-dev/xcl/pull/2258#issuecomment-7162851757) Independent RDNA2 confirmation of the AMD NaN regression reported above, at exact PR head `c2046530321844e65a64df2ef2ff78e15ac095ea` versus main `1a0bbe3a2ba91ea8f5b6fc29130a053868d3c9e6`. **Environment:** Windows 11 build 26200; Ryzen 9 5980HX; Radeon RX 6800M driver `30.0.13002.13003` (native wave64); Rust 1.99.0 MSVC; DXC/DXIL 1.9.2609.5. Isolated worktrees and Cargo targets. Debug tests use `XCL_ADAPTER=6800M`, `XCL_REQUIRE_GPU=wave64`, `-j 2`, `--test-threads=1`, `--show-output`. **Results** - On this PR, `cargo test --locked -p xcl --lib gpu_direct_float_compare_uses_fcmp_and_matches_ieee` with `XCL_DIRECT_DXIL=1`: **0 passed, 1 failed, 0 ignored**, no skip. The assertion is exactly `V_CMP_LG_F32 lane 8 (NaN, 0.0): got true, want false` at `lower_valu.rs:1420`. This is a value mismatch after GPU execution, not a PSO/device-removal failure. - Existing `f32_programs_on_the_gpu`: main **1/0/0**, PR **0/1/0** with `XCL_DIRECT_DXIL=1`. The PR fails `f32 compares, wave32: s10` (`left: 4294967291`, `right: 4008636138`) at `lower_dxil.rs:738`. - The same existing-test control with `XCL_DIRECT_DXIL=0` also passes on main **1/0/0** and fails on this PR **0/1/0** with the same `s10` values. That test exercises its own DXIL path, so changing the environment flag does not remove the regression. This extends the reported failure from RX 9070 XT/RDNA4 to RX 6800M/RDNA2. It is a reproducible PR-head regression against this main revision. I ran focused synthetic tests only; no full workspace suite or retail-title smoke on this head. No game data was used. **AI use:** OpenAI Codex (GPT-6; exact variant not exposed in this session) ran the native Windows GPU tests and main/PR controls, checked the exact assertions, and drafted this report.
Author
Owner

@⁠nnonno91 on GitHub · 2026-11-25 15:21 UTC · original

Independent Windows check of c2046530321844e65a64df2ef2ff78e15ac095ea and parent 1a0bbe3a2ba91ea8f5b6fc29130a053868d3c9e6. The Radeon iGPU also reproduces the NaN comparison regression in a wave32 fixture. The RTX 5090 passed the two focused head tests I ran there.

Tested

  • Windows 11 25H2 (26200.9974), Ryzen 7 9800X3D, Radeon integrated graphics (32.0.21042.62), RTX 5090 (32.0.16.1742), Rust 1.100.0 x64 MSVC, Windows SDK DXC/DXIL 1.8.2502.11. Unoptimized test profile.
  • Ran cargo test --locked -p xcl --lib <filter> -- --nocapture --test-threads=1 with XCL_DIRECT_DXIL=1 and explicit adapter selection.
  • float_compare_tests on the head: Radeon 0 passed, 1 failed. V_CMP_LG_F32 lane 8 returned true for (NaN, 0.0), expected false. The RTX 5090 reported 1 passed, 0 failed. The new fixture uses wave32.
  • gpu_f32_compares_with_nan: Radeon parent 1 passed, 0 failed; head 0 passed, 1 failed. On the head, all three NaN input pairs returned true for v_cmp_lt_f32 and false for v_cmp_nlg_f32, opposite the expected values. RTX 5090 head reported 1 passed, 0 failed.
  • f32_programs_on_the_gpu on Radeon: parent 1 passed, 0 failed with two logged skips for unsupported per-lane f16 conversions; head 0 passed, 1 failed at f32 compares, wave32: s10 (4294967291 vs 4008636138).
  • All runs had 0 ignored. No other skips were logged.

Not tested

RTX 5090 parent or its broader f32 fixture, double-precision GPU execution, retail titles, or the full workspace suite.

AI use

OpenAI Codex (GPT-6.2 Sol) ran the tests, verified the results, and wrote this report.

**@⁠nnonno91** on GitHub · 2026-11-25 15:21 UTC · [original](https://github.com/xcl-dev/xcl/pull/2258#issuecomment-7166712061) Independent Windows check of `c2046530321844e65a64df2ef2ff78e15ac095ea` and parent `1a0bbe3a2ba91ea8f5b6fc29130a053868d3c9e6`. The Radeon iGPU also reproduces the NaN comparison regression in a wave32 fixture. The RTX 5090 passed the two focused head tests I ran there. **Tested** - Windows 11 25H2 (26200.9974), Ryzen 7 9800X3D, Radeon integrated graphics (32.0.21042.62), RTX 5090 (32.0.16.1742), Rust 1.100.0 x64 MSVC, Windows SDK DXC/DXIL 1.8.2502.11. Unoptimized test profile. - Ran `cargo test --locked -p xcl --lib <filter> -- --nocapture --test-threads=1` with `XCL_DIRECT_DXIL=1` and explicit adapter selection. - `float_compare_tests` on the head: Radeon 0 passed, 1 failed. `V_CMP_LG_F32` lane 8 returned true for `(NaN, 0.0)`, expected false. The RTX 5090 reported 1 passed, 0 failed. The new fixture uses wave32. - `gpu_f32_compares_with_nan`: Radeon parent 1 passed, 0 failed; head 0 passed, 1 failed. On the head, all three NaN input pairs returned true for `v_cmp_lt_f32` and false for `v_cmp_nlg_f32`, opposite the expected values. RTX 5090 head reported 1 passed, 0 failed. - `f32_programs_on_the_gpu` on Radeon: parent 1 passed, 0 failed with two logged skips for unsupported per-lane f16 conversions; head 0 passed, 1 failed at `f32 compares, wave32: s10` (4294967291 vs 4008636138). - All runs had 0 ignored. No other skips were logged. **Not tested** RTX 5090 parent or its broader f32 fixture, double-precision GPU execution, retail titles, or the full workspace suite. **AI use** OpenAI Codex (GPT-6.2 Sol) ran the tests, verified the results, and wrote this report.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-25 16:53 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!

**@⁠DavidM1911** on GitHub · 2026-11-25 16:53 UTC · [original](https://github.com/xcl-dev/xcl/pull/2258#issuecomment-7168687982) 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!
This pull request has changes conflicting with the target branch.
  • crates/xcl/src/gpu/dxil/lower_valu.rs
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.
git fetch -u origin '+refs/pull/2258/head:github-bot/gh-2258'
git switch 'github-bot/gh-2258'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2258'
git switch 'github-bot/gh-2258'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2258'
git switch 'github-bot/gh-2258'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2258'
git switch 'main'
git merge --squash 'github-bot/gh-2258'
git switch 'main'
git merge --ff-only 'github-bot/gh-2258'
git switch 'main'
git merge 'github-bot/gh-2258'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.