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

Open
ramon-victor wants to merge 1 commit from upstream-pr/2289 into main
ramon-victor commented 2026-11-25 12:28:18 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by ramon-victor on 2026-11-25T12:28:18Z.


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.
<!-- greyfinch-sync:ivall/xcl:issue:5491321933 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2289). Originally posted by [ramon-victor](https://github.com/ramon-victor) on 2026-11-25T12:28:18Z. --- 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.
DarkPanda69 commented 2026-11-25 13:05:19 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DarkPanda69 on 2026-11-25T12:59:29Z.


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.

<!-- greyfinch-sync:ivall/xcl:comment:7163136434 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2289#issuecomment-7163136434). Originally posted by [DarkPanda69](https://github.com/DarkPanda69) on 2026-11-25T12:59:29Z. --- 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.
nnonno91 commented 2026-11-25 15:08:04 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by nnonno91 on 2026-11-25T15:00:16Z.


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.

<!-- greyfinch-sync:ivall/xcl:comment:7166150569 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2289#issuecomment-7166150569). Originally posted by [nnonno91](https://github.com/nnonno91) on 2026-11-25T15:00:16Z. --- 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.
DavidM1911 commented 2026-11-25 18:04:32 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-25T17:17:38Z.


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!

<!-- greyfinch-sync:ivall/xcl:comment:7169290193 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2289#issuecomment-7169290193). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-25T17:17:38Z. --- 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 commented 2026-11-25 19:09:10 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by raylitebull on 2026-11-25T18:41:00Z.


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.

<!-- greyfinch-sync:ivall/xcl:comment:7171247996 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2289#issuecomment-7171247996). Originally posted by [raylitebull](https://github.com/raylitebull) on 2026-11-25T18:41:00Z. --- 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.
Foniass commented 2026-12-01 07:45:22 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T07:45:22Z.


Triage (#1607) – head eaa509d

No open or merged PR makes the same change. Main's cvt_u32 and f16_rtz in gpu/dxil/prelude.rs still call isnan. fcmp ule f, 0.0 is true for NaN and for f <= 0, and the ordered ogt in f16_rtz is already false for NaN, so the results stay the same. Unordered predicates are already used elsewhere in direct DXIL (v_cmp_n*). 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.

<!-- greyfinch-sync:ivall/xcl:comment:7304441143 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2289#issuecomment-7304441143). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T07:45:22Z. --- **Triage (#1607)** – head eaa509d No open or merged PR makes the same change. Main's `cvt_u32` and `f16_rtz` in `gpu/dxil/prelude.rs` still call `isnan`. `fcmp ule f, 0.0` is true for NaN and for `f <= 0`, and the ordered `ogt` in `f16_rtz` is already false for NaN, so the results stay the same. Unordered predicates are already used elsewhere in direct DXIL (`v_cmp_n*`). 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.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/2289:upstream-pr/2289'
git switch 'upstream-pr/2289'

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.

git switch 'main'
git merge --no-ff 'upstream-pr/2289'
git switch 'upstream-pr/2289'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2289'
git switch 'upstream-pr/2289'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2289'
git switch 'main'
git merge --squash 'upstream-pr/2289'
git switch 'main'
git merge --ff-only 'upstream-pr/2289'
git switch 'main'
git merge 'upstream-pr/2289'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl!2279
No description provided.