Skip to content

startup: keep gfx2hlsl f32 n-forms, o and u exact under FXC and DXC - #1949

Merged
R0Y00 merged 1 commit into
R0Y00:mainfrom
MasterDomino:startup/gfx2hlsl-f32-nan-forms
Nov 24, 2026
Merged

R0Y00 merged 1 commit into
R0Y00:mainfrom
MasterDomino:startup/gfx2hlsl-f32-nan-forms

Conversation

@MasterDomino

@MasterDomino MasterDomino commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #1936. Builds on the bit test from #1930 (merged); rebased onto main cd5508e9.

What

This is the narrow per-predicate fix agreed on #1936. Compiler flags are unchanged.

Condition Before After
nlt nle ngt nge !(a OP b) !(ORDERED && a OP b)
o (a == a && b == b) ORDERED
u (a != a || b != b) !ORDERED

ORDERED is the integer test (w & 0x7fffffffu) <= 0x7f800000u on both source words, read before neg/abs, as lg/nlg use since #1930. neq and the ordered relations are unchanged: both compilers keep them exact on NaN (measured below).

Why

The startup cache compiles every gfx2hlsl pair with FXC and no flags (translate_to). Neither compiler keeps float compares IEEE-strict unless asked:

  • FXC compiles !(a < b) to ge a, b, and likewise for <=, >, >=. So nlt/nle/ngt/nge gave 0 on every NaN pair, where the ISA gives 1.
  • DXC folds a != a and a == a. So u was constant 0 and o constant 1.

With the integer NaN test in front, any rewrite of the float relation keeps the ISA result.

Tests

tests/startup_gfx2hlsl_f32_nan_check.py:

  • Controls (pure Python, also in the CI Python job):
    • All 510 f32 forms (v_cmp and v_cmpx; e32, and e64 under every neg/abs combination) are translated and evaluated over the 256 pairs of ±0, ±min denormal, ±1.0, ±max finite, ±inf, ±quiet, signalling and payload NaN.
    • Each form is evaluated under three models: IEEE compares; the FXC rewrite (a negation pushed into the opposite relation); and the DXC folds (reflexive float relations folded, and less-or-greater read as unordered not-equal, as in startup: gfx2hlsl lowers f32 lg/nlg compares as unordered (wrong for NaN) #1920). Every form equals the ISA reference under all three.
    • The pre-fix text of the six conditions holds under IEEE and fails all 204 of its forms under the model of the compiler that broke it.
    • The models themselves are checked against the pre-fix text.
    • An EXEC-masked lane check.
    • Run against the unfixed gfx2hlsl.py, the controls fail.
  • Draws (_warp, _hardware):
    • Every lowered condition except lg/nlg (13 of them) writes four results per pixel: e32, and e64 with (-a, |b|), (-|a|, -b) and (|a|, b). The six also keep pixels through v_cmpx_*_e64. 16 × 16 pixels cover every source pair, compiled with default-flag FXC ps_5_1 and DXC ps_6_0.
    • Every pixel must match the ISA image, and the report says whether the denormal-kept or the denormal-flushed image matched. The choice must be the same across the fixtures whose image depends on it (f, o and u don't).
    • Negative control: on the compiler that rewrote it, the pre-fix text must fail against both images and must match the image of that compiler's rewrite.
    • Diagnostic (recorded, not checked): the pre-fix and the fixed text drawn with /Gis and -Gis.
  • binary <llvm-mc> and decode <libLLVM> round-trip the 19 fixtures through LLVM 15. Both are added to the CI LLVM job.

tests/startup_gfx2hlsl_f32_lg_check.py pinned the old text of these six conditions. That pin moves to the new test; the other 7 conditions stay pinned there.

Results

Commit 583178d4 (on main cd5508e9); Windows 11 build 26300; Windows SDK 10.0.26100.0 FXC and DXC; D3D12 debug layer on.

  • WARP: Microsoft Basic Render Driver, 10.0.26100.9818.
  • Hardware: AMD Radeon RX 9070 XT (1002:7550), driver 32.0.31044.16.
ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_' -j 6
100% tests passed out of 39        (startup_gfx2hlsl_f32_nan, _warp, _hardware among them)
python -B tests/startup_gfx2hlsl_f32_nan_check.py draw <dxc> <offscreen_check> warp|hardware <fxc>
PASS                               (171 checks on each adapter, 0 skips)
python -B tests/startup_gfx2hlsl_f32_nan_check.py binary <llvm-mc 15.0.7>        PASS
python -B tests/startup_gfx2hlsl_f32_nan_check.py decode <LLVM-C.dll>            PASS
FXC (default) DXC (default) FXC /Gis (recorded) DXC -Gis (recorded)
Fixed text, all 13 conditions every pixel, both adapters every pixel, both adapters every pixel every pixel
Pre-fix nlt nle ngt nge fails, 156 NaN pixels; matches the NaN-blind image matched (recorded) every pixel every pixel
Pre-fix o u matched (recorded) fails, 156 NaN pixels; matches the folded image every pixel every pixel

Both backends flushed denormal compare sources to signed zero, which D3D allows, consistently across fixtures. WARP and the RX 9070 XT agree in every cell, so the bytecode decides it.

Not covered

  • f16/f64 compares and v_cmp_class_*, which are not lowered.
  • Other float operations under FXC's default flags. This PR changes no compiler policy.

🤖 Generated with Claude Code

The startup cache compiles gfx2hlsl pairs with FXC and no flags, and
neither compiler keeps float compares IEEE-strict unless asked. FXC
compiled !(a < b) to ge (and likewise for <=, >, >=), so v_cmp nlt, nle,
ngt and nge gave 0 on every NaN pair; DXC folded a != a and a == a, so u
was constant 0 and o constant 1. WARP and an RX 9070 XT agreed, and
/Gis or -Gis restored the ISA result.

The n-forms now read !(ORDERED && a OP b), and o and u read ORDERED and
!ORDERED, with ORDERED the bit test of both source words that lg uses
since R0Y00#1920. neq is unchanged. Compiler flags are unchanged.

tests/startup_gfx2hlsl_f32_nan_check.py evaluates every f32 form under
IEEE compares and under models of both rewrites, and draws every lowered
condition but lg/nlg with FXC and DXC; the pre-fix text fails on the
compiler that rewrote it and matches that rewrite's image. Strict-flag
runs are recorded as a diagnostic.

Fixes R0Y00#1936

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@MasterDomino
MasterDomino force-pushed the startup/gfx2hlsl-f32-nan-forms branch from dfdcb7e to 583178d Compare November 24, 2026 22:09
@R0Y00
R0Y00 merged commit 4c4502b into R0Y00:main Nov 24, 2026
5 checks passed
@ChazY11

ChazY11 commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Ran both checks and broke all six changed predicates one at a time

Windows 11 build 26300.9974, device-free:

out/pe-env/Scripts/python.exe -B tests/startup_gfx2hlsl_f32_nan_check.py    # exit 0
out/pe-env/Scripts/python.exe -B tests/startup_gfx2hlsl_f32_lg_check.py     # exit 0

Each predicate reverted to its pre-#1936 text, one at a time, running only the new check:

mutation result
nlt → !({0} < {1}) caught
nle → !({0} <= {1}) caught
ngt → !({0} > {1}) caught
nge → !({0} >= {1}) caught
o → ({0} == {0} && {1} == {1}) caught
u → `({0} != {0}
u → ({2}) (the negation dropped, i.e. u becomes o) caught

The last one matters: o and u are complements, so a test that only compared each against its own expected string would let a
swapped pair through if both were wrong the same way. Yours catches the single-character version.

The edit to the existing lg check does not weaken it

Removing six conditions from UNCHANGED and skipping them in the changed loop is the kind of edit that quietly drops coverage, so
I checked it two ways:

  • the set assertion in the same file now unions {'lg', 'nlg'} | set(NAN_FORMS), so a condition missing from both tables still
    fails the coverage line rather than being silently unchecked;
  • mutating the conditions that stayed in that file still fails it: neq → ({0} == {1}) caught, lt → {0} <= {1}
    caught.

So the six moved out, six moved in, and nothing fell between them.

What I like about the shape

o = ORDERED and u = !ORDERED reuses the integer test rather than writing a second NaN predicate, which is the reason a
backend cannot fold either to a constant. The comment names the two compiler behaviours (!Gis / -Gis) that forced this, so a
later reader knows why the text is not simply a == a.

What this does not establish

The whole point is what FXC and DXC emit, and this check compares emitted text and evaluates it on the CPU — the compiler side
rests on the measurements in the description. x != x folding under DXC without -Gis is asserted there, not re-measured here; I
have no DXC in this environment. That limitation is the honest one for this PR, and it is stated.

Verdict

Reviewed. Six behaviours, seven mutations, all caught, and the neighbouring check keeps its teeth.

Notes

  • AI-assisted review.

@legacy-code-archaeologist

Copy link
Copy Markdown
Contributor

Hardware run of head 583178d on two GPU families the PR text does not list, plus WARP. Windows 11 Pro 26100.9168, DXC and FXC from Windows SDK 10.0.26100, dev preset, debug layer unavailable here. The adapter was selected with XBOX2WINDOWS_ADAPTER.

Adapter Driver startup_gfx2hlsl_f32_nan_* startup_gfx2hlsl_f32_lg_*
WARP 10.0.26100.8972 Passed Passed
NVIDIA Quadro M1000M (Maxwell, 10de:13b1) 32.0.15.7371 Passed Passed
Intel HD Graphics 530 (Gen9, 8086:191b) 31.0.101.2111 Passed Passed
  • Device-free checks: startup_gfx2hlsl_f32_nan and startup_gfx2hlsl_f32_lg pass.
  • Controls: every "old text fails against the ieee/flushed image" control mismatched as required, on all three adapters.
  • The 70 recorded: observations (old and new text with and without /Gis, and "without the NaN bit test" under FXC and DXC) are identical across the three adapters. Each is "all 256 pixels matched", with the same denormal note.

LLVM 15 (local):

  • decode with LLVM-C.dll 15.0.7: PASS.
  • binary not run. My local llvm-mc is a stand-in over clang -cc1as, which does not support -show-encoding, so the failure there is mine, not the PR's.

No changes made.

R0Y00 pushed a commit that referenced this pull request Nov 25, 2026
compare() refused every v_cmp_*_f32_sdwa and v_cmpx_*_f32_sdwa until the
f32 predicates were exact on NaN (#1930, #1949). DWORD selections now
read the register as binary32 with neg/abs as in the e64 form, so a
src0_sel:DWORD src1_sel:DWORD compare emits the e64 text, NaN bit test
included.

Byte and word selections are refused: the selected field is always +0 or
a denormal, so the result depends on the binary32 denormal mode, which
gfx2hlsl does not read. pixel_aot refuses the same forms. sext() is
integer-only and refused; LLVM 15 does not decode the bit on a float
source. clamp, omod, dst_sel and dst_unused stay refused, and class
compares are unchanged. LLVM's SIPeepholeSDWA models the sub-dword case
as zero-extension read as binary32 bits; the RDNA 2 ISA guide gives only
the SDWAB fields.

tests/startup_gfx2hlsl_f32_sdwa_check.py:
- builds every f32 SDWA form and checks the 720 DWORD/DWORD forms against
  the e64 text and the ISA reference: 256 NaN/denormal pairs under the
  IEEE, FXC and DXC models;
- refuses all 34,560 byte/word forms with the denormal-mode message;
- uses the text before #1930/#1949 as its negative control;
- draws 30 DWORD fixtures with default-flag FXC ps_5_1 and DXC ps_6_0.

The vopc_sdwa and f32_lg checks no longer assert the blanket refusal.
They now check that DWORD selections lower as the e64 form and that
byte/word selections are refused with the new message.

Refs #1906

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

startup: gfx2hlsl f32 nlt/nle/ngt/nge (FXC) and u/o (DXC) compares are wrong on NaN without IEEE-strict compiles

4 participants