Recompiler: drop redundant IsNaN checks in direct DXIL cvt_u32 and f16_rtz #2289

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

@⁠ramon-victor on GitHub · 2026-11-25 12:28 UTC · original
ramon-victor:opt/dxil-drop-redundant-isnan-cvt → main · +72 −7 · 1 files · 1 commits · open

Removes redundant explicit dx.op.isSpecialFloat(IsNaN) guards in two hot direct DXIL float-conversion helpers (Lw::cvt_u32 and Lw::f16_rtz):

  • Lw::cvt_u32 (v_cvt_u32_f32): replaces isnan(f) || (f <=o 0.0) (3 ops) with a single unordered fcmp ule float %f, 0.0 (Pred::FULe, 1 op), which already evaluates to true for both NaN and f <= 0.0.
  • Lw::f16_rtz (v_cvt_pkrtz_f16_f32): drops !isnan(f) from (!isnan(f)) && nz && (abs(back) >o abs(f)) (3 ops removed per half, 6 per v_cvt_pkrtz_f16_f32), because ordered fcmp ogt (Pred::FOGt) already evaluates to false when f (and therefore abs(f)) is NaN.

Part of #1269.

What is in it

  • crates/xcl/src/gpu/dxil/prelude.rs:
    • Simplify Lw::cvt_u32 to Pred::FULe and Lw::f16_rtz to self.land(nz, gt) (+5/-8 lines in production code).
    • Add cvt_isnan_tests::gpu_direct_cvt_u32_and_pkrtz_drop_isnan_and_match_isa verifying DXIL validation, disassembly (zero dx.op.isSpecialFloat calls, fcmp ule float emitted), and GPU execution across ±0.0, negative values, rounding boundaries, >= 2^32, ±Inf, qNaN, and sNaN.

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 -> 41,224,580 B (-99,156 B, -0.24%)
  • Translation time p95: 263.12 ms -> 255.59 ms (-2.9%)

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::prelude::cvt_isnan_tests (debug): 1 passed; 0 failed (DXIL validation, disassembly check, and RTX 3070 GPU verification).
  • .\scripts\test.ps1 (debug, full workspace): 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: eaa509ddbcb77ef688895a73873bc446e3afb7fa
gpu: NVIDIA GeForce RTX 3070
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1616 (PresentX 1616)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14419 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): simplified Lw::cvt_u32 and Lw::f16_rtz in prelude.rs, added DXIL disassembly and GPU execution tests, and ran the workspace test suite, 573-shader validation benchmark, and 60 s smoke regression run.
**@⁠ramon-victor** on GitHub · 2026-11-25 12:28 UTC · [original](https://github.com/xcl-dev/xcl/pull/2289) `ramon-victor:opt/dxil-drop-redundant-isnan-cvt` → `main` · +72 −7 · 1 files · 1 commits · open Removes redundant explicit `dx.op.isSpecialFloat(IsNaN)` guards in two hot direct DXIL float-conversion helpers (`Lw::cvt_u32` and `Lw::f16_rtz`): - `Lw::cvt_u32` (`v_cvt_u32_f32`): replaces `isnan(f) || (f <=o 0.0)` (3 ops) with a single unordered `fcmp ule float %f, 0.0` (`Pred::FULe`, 1 op), which already evaluates to `true` for both `NaN` and `f <= 0.0`. - `Lw::f16_rtz` (`v_cvt_pkrtz_f16_f32`): drops `!isnan(f)` from `(!isnan(f)) && nz && (abs(back) >o abs(f))` (3 ops removed per half, 6 per `v_cvt_pkrtz_f16_f32`), because ordered `fcmp ogt` (`Pred::FOGt`) already evaluates to `false` when `f` (and therefore `abs(f)`) is `NaN`. Part of #1269. **What is in it** - `crates/xcl/src/gpu/dxil/prelude.rs`: - Simplify `Lw::cvt_u32` to `Pred::FULe` and `Lw::f16_rtz` to `self.land(nz, gt)` (`+5/-8` lines in production code). - Add `cvt_isnan_tests::gpu_direct_cvt_u32_and_pkrtz_drop_isnan_and_match_isa` verifying DXIL validation, disassembly (zero `dx.op.isSpecialFloat` calls, `fcmp ule float` emitted), and GPU execution across `±0.0`, negative values, rounding boundaries, `>= 2^32`, `±Inf`, `qNaN`, and `sNaN`. 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 -> 41,224,580 B` (`-99,156 B`, `-0.24%`) - Translation time p95: `263.12 ms -> 255.59 ms` (`-2.9%`) **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::prelude::cvt_isnan_tests` (debug): `1 passed; 0 failed` (DXIL validation, disassembly check, and RTX 3070 GPU verification). - `.\scripts\test.ps1` (debug, full workspace): `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: eaa509ddbcb77ef688895a73873bc446e3afb7fa gpu: NVIDIA GeForce RTX 3070 title: 3c290c16 seconds: 60 exit: 0x0 frames shown: 1616 (PresentX 1616) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14419 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): simplified `Lw::cvt_u32` and `Lw::f16_rtz` in `prelude.rs`, added DXIL disassembly and GPU execution tests, and ran the workspace test suite, 573-shader validation benchmark, and 60 s smoke regression run.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:25:51 +00:00
Author
Owner

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

The AMD native wave64 run listed as untested, plus an RTX 3060: passes on both. I checked this one closely on AMD because #2258 (removing NaN guards from float compares) fails there; here, with the NaN checks dropped from cvt_u32 and f16_rtz, the NaN cases still come out right on the RX 9070 XT.

Head eaa509d applied on main 1a0bbe3, debug, Windows 11 Pro 26200:

  • cargo test -p xcl --lib -- gpu:: --test-threads=4: gpu_direct_cvt_u32_and_pkrtz_drop_isnan_and_match_isa ok on both cards. RX 9070 XT (RDNA4, 32.0.32029.2010, waves 32..64): 630 passed, 2 failed, 22 ignored (the 2 are the AMD fuzz seeds tracked in #2115, the same on main). RTX 3060 (32.0.16.1088): 632 passed, 0 failed.
  • Paired against main with XCL_DIRECT_DXIL=1 for the whole gpu:: filter: on both cards the only difference is the new test (ok); no existing test changes result or skip state.

Not tested: a title with XCL_DIRECT_DXIL=1.
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:59 UTC · [original](https://github.com/xcl-dev/xcl/pull/2289#issuecomment-7163136434) The AMD native wave64 run listed as untested, plus an RTX 3060: passes on both. I checked this one closely on AMD because #2258 (removing NaN guards from float compares) fails there; here, with the NaN checks dropped from `cvt_u32` and `f16_rtz`, the NaN cases still come out right on the RX 9070 XT. Head `eaa509d` applied on `main` `1a0bbe3`, debug, Windows 11 Pro 26200: - `cargo test -p xcl --lib -- gpu:: --test-threads=4`: `gpu_direct_cvt_u32_and_pkrtz_drop_isnan_and_match_isa` ok on both cards. RX 9070 XT (RDNA4, 32.0.32029.2010, waves 32..64): 630 passed, 2 failed, 22 ignored (the 2 are the AMD fuzz seeds tracked in #2115, the same on `main`). RTX 3060 (32.0.16.1088): 632 passed, 0 failed. - Paired against `main` with `XCL_DIRECT_DXIL=1` for the whole `gpu::` filter: on both cards the only difference is the new test (ok); no existing test changes result or skip state. Not tested: a title with `XCL_DIRECT_DXIL=1`. AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report.
Author
Owner

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

Independent GPU check on eaa509ddbcb77ef688895a73873bc446e3afb7fa, with extra packed-half boundary values.

Tested

  • Windows 11 25H2 build 26200.9974, Ryzen 7 9800X3D, Rust 1.100.0 MSVC, SDK DXC/DXIL 1.8.2502.11, unoptimized profile. Radeon(TM) Graphics driver 32.0.21042.62 and RTX 5090 driver 32.0.16.1742.
  • Added five temporary input pairs to the existing direct-DXIL fixture. The additions covered negative signaling and quiet NaNs, signed values immediately below and at the minimum half subnormal, the normal/subnormal boundary, and signed finite overflow. Checked the unsigned conversion reference, NaN classification and exact packed halves for the four finite pairs.
  • cargo test --locked -p xcl --lib cvt_isnan_tests -- --nocapture --test-threads=1 with each GPU selected via XCL_ADAPTER gave 1 passed, 0 failed, 0 ignored and no skips on each. All 15 input pairs and the existing validator and disassembly assertions passed. The temporary fixture changes were restored.

Not tested

Retail inputs, performance, the parent, native wave64 execution of this wave32 fixture, and the full workspace suite.

AI use

OpenAI Codex (GPT-6.2 Sol) added the temporary boundary values, ran the tests and wrote this report.

**@⁠nnonno91** on GitHub · 2026-11-25 15:00 UTC · [original](https://github.com/xcl-dev/xcl/pull/2289#issuecomment-7166150569) Independent GPU check on `eaa509ddbcb77ef688895a73873bc446e3afb7fa`, with extra packed-half boundary values. **Tested** - Windows 11 25H2 build 26200.9974, Ryzen 7 9800X3D, Rust 1.100.0 MSVC, SDK DXC/DXIL 1.8.2502.11, unoptimized profile. Radeon(TM) Graphics driver 32.0.21042.62 and RTX 5090 driver 32.0.16.1742. - Added five temporary input pairs to the existing direct-DXIL fixture. The additions covered negative signaling and quiet NaNs, signed values immediately below and at the minimum half subnormal, the normal/subnormal boundary, and signed finite overflow. Checked the unsigned conversion reference, NaN classification and exact packed halves for the four finite pairs. - `cargo test --locked -p xcl --lib cvt_isnan_tests -- --nocapture --test-threads=1` with each GPU selected via `XCL_ADAPTER` gave 1 passed, 0 failed, 0 ignored and no skips on each. All 15 input pairs and the existing validator and disassembly assertions passed. The temporary fixture changes were restored. **Not tested** Retail inputs, performance, the parent, native wave64 execution of this wave32 fixture, and the full workspace suite. **AI use** OpenAI Codex (GPT-6.2 Sol) added the temporary boundary values, ran the tests and wrote this report.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-25 17:17 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 17:17 UTC · [original](https://github.com/xcl-dev/xcl/pull/2289#issuecomment-7169290193) 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!
Author
Owner

@⁠raylitebull on GitHub · 2026-11-25 18:41 UTC · original

Diff review, CI, and both AMD and NVIDIA checks passed on eaa509d, but recent origin/main merges turned this branch CONFLICTING/DIRTY. Please rebase onto origin/main so it becomes mergeable again.

**@⁠raylitebull** on GitHub · 2026-11-25 18:41 UTC · [original](https://github.com/xcl-dev/xcl/pull/2289#issuecomment-7171247996) Diff review, CI, and both AMD and NVIDIA checks passed on `eaa509d`, but recent `origin/main` merges turned this branch `CONFLICTING/DIRTY`. Please rebase onto `origin/main` so it becomes mergeable again.
This pull request has changes conflicting with the target branch.
  • crates/xcl/src/gpu/dxil/prelude.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/2289/head:github-bot/gh-2289'
git switch 'github-bot/gh-2289'

Merge

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