Repository navigation
startup: lower gfx2hlsl f32 lg/nlg compares as ordered - #1930
Conversation
V_CMP_LG_F32 is less or greater: ordered and not equal, false when either source is NaN; V_CMP_NLG_F32 is its negation. compare() lowered them as a != b and !(a != b), and HLSL != is unordered, so both gave the opposite result on every NaN pair (plain and e64 forms, v_cmp and v_cmpx). They now read (ORDERED && (a < b || a > b)) and its negation, ORDERED testing both source words for NaN on their bits before the neg/abs modifiers. Without the bit test, the DXC build (fast compares unless -Gis) of the v_cmp fixture returned 1 for both lg and nlg on all 156 NaN pairs on an RX 9070 XT. The other conditions and the refused f32 SDWA forms are unchanged. tests/startup_gfx2hlsl_f32_lg_check.py decodes every f32 condition of the table (e32 and e64 under every neg/abs, 510 forms), evaluates the emitted HLSL over all 256 pairs of +-0, +-min denormal, +-1, +-max, +-inf and quiet, signalling and payload NaNs against a reference built from the ISA definitions, round-trips the forms through LLVM 15, and draws 16 x 16 pixels covering every pair on WARP and hardware with FXC ps_5_1 and DXC ps_6_0, checked pixel by pixel. The old != lowering fails all 68 lg/nlg forms and every draw. Fixes R0Y00#1920 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Ran it, broke the ordered lowering four waysWindows 11 build 26300.9974, device-free: out/pe-env/Scripts/python.exe -B tests/startup_gfx2hlsl_f32_lg_check.py
PASS exit 0Mutations to
The third is the one I wanted: What I checked by reading, not by guessing
What I cannot verifyThe DXC One small note
!((w0 & 0x7fffffffu) <= 0x7f800000u && … && (a < b || a > b))Correct, and the evaluator in the test covers it. If the emitted text ever gets long enough to matter for VerdictReviewed. The NaN semantics are the whole point of the change and they are pinned on both ends of the ORDERED test, in both Notes
|
|
Resolved the workflow overlap with #1925, keeping both Python and LLVM registrations. The integrated candidate passes the lg/nlg, scalar complement and class comparison controls. Default FXC/DXC draws passed on WARP and RTX 4060 Laptop with the expected old-lowering mismatches. This keeps the remaining predicate work in #1936 independent. |
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>
Fixes #1920
What / Why
In the gfx10 ISA
V_CMP_LG_F32is "less or greater": ordered and not equal, false when either source is NaN.V_CMP_NLG_F32is its negation, true when either source is NaN.compare()intools/startup/gfx2hlsl.pylowered them asa != band!(a != b). HLSL!=is unordered, so both gave the opposite result on every NaN pair, in the plain and_e64forms ofv_cmpandv_cmpx.Change
lgis now(ORDERED && (a < b || a > b))andnlgis!(ORDERED && (a < b || a > b)). ORDERED is(w & 0x7fffffffu) <= 0x7f800000ufor both source words, taken before the neg/abs modifiers (the modifiers never change whether a word is NaN).-Gisemitsfcmp fast/fcmp onefor the plain less-or-greater. On the RX 9070 XT (driver 32.0.31044.16), that build of thecmpfixture returned 1 for both lg and nlg on all 156 NaN pairs. FXC on both backends and DXC on WARP gave the ordered result. This is recorded by the draw (see below). The production path compiles with FXCps_5_1.Tests
Commit under test:
fc9517aaonmainb96960b7(rebased after #1915 merged; the change itself is unchanged froma22cfaa8). After the rebase:startup_gfx2hlsl_*33/33 including both draws,binarywith llvm-mc 15.0.7 PASS.tests/startup_gfx2hlsl_f32_lg_check.py(no arguments, pure Python):510 f32 forms x 256 pairs (130560 evaluations) equal the ISA reference: ok.binary <llvm-mc>/decode <libLLVM>: LLVM 15 assembles the 510 decoded forms and the 5 pixel fixtures to the same words. The LLVM C API disassembles them to the same text. tools/disasm_rdna2.py prints the unuseds0sdst of a gfx10v_cmpx_*_e64; this is normalized as a known difference.draw, registered asstartup_gfx2hlsl_f32_lg_{warp,hardware}):cmpwritesv_cmp_lg_f32_e32,v_cmp_nlg_f32_e64 -a, |b|,v_cmp_lg_f32_e64 -|a|, -bandv_cmp_nlg_f32_e32as 1.0/0.0.cmpx_{lg,nlg}_{e32,e64}keep or discard pixels.ps_5_1and DXCps_6_0and checked pixel by pixel withoffscreen_check --startup-pixel-words. lg is 1 on unequal pairs and 0 on equal and NaN pairs; nlg is the opposite.startup_gfx2hlsl_f32_lgstartup_gfx2hlsl_f32_lg_warp: WARP (Microsoft Basic Render Driver, 10.0.26100.9818), debug layer on, 0 errorsstartup_gfx2hlsl_f32_lg_hardware: AMD Radeon RX 9070 XT (1002:7550), driver 32.0.31044.16, debug layer on, 0 errorsEnvironment: Windows 11 Home 10.0.26300, Windows SDK 10.0.26100.0 fxc/dxc, LLVM 15 (llvm-mc), LLVM C API.
Other runs:
ctest --preset dev --no-tests=error -R '^startup_' -j 4: 262 passed, 0 failed, 4 skipped. The skips are capability skips (77) instartup_view_heap_{warp,hardware}andstartup_logical_view_{warp,hardware}, unrelated to this change. This includes all 30startup_gfx2hlsl_*tests.tests/startup_gfx2hlsl_f32_lg_check.py binary <llvm-mc>anddecode <LLVM-C.dll>: PASS.tests/docs_links_check.pyandtests/bidi_controls_check.py: pass.Negative controls
!=lowering restored.v_cmp_lg_f32_e32 vcc_lo, v1, v2withF(v1) != F(v2), a=00000000 b=7fc00000 gives 1, the ISA gives 0. It matches its own unordered model.cmpon the RX 9070 XT with FXC givespixel mismatch (10,0): expected 00000000,3f800000,00000000,3f800000 actual 3f800000,00000000,3f800000,00000000 / 156 of 256 pixels differ. Acmpx_*fixture gives 166 differing pixels against the denormals-kept image.'{0} != {1}'/'!({0} != {1})', the pure-Python check fails (510 f32 forms ... : MISMATCH, firstv_cmp_lg_f32_e32a=00000000 b=7fc00000 gives 1, ISA 0), and so does the WARP FXCcmpdraw.cmpfails withpixel mismatch (10,0): expected 00000000,3f800000,00000000,3f800000 actual 3f800000,3f800000,3f800000,3f800000 / 156 of 256 pixels differ.Not covered
tools/pixel_aot.pydoes not have this bug. ItsCOMPAREtable already lowerslgas({0} < {1} || {0} > {1})behind the same bit-level ordered test (f32_comparison), andnlgas({0} == {1} || isnan({0}) || isnan({1})). No change was made there./Gis/-Gis), observed in compiler output only and not yet in a draw:!(a < b)(nlt) to DXBCge, which is ordered, so it is false on NaN where nlt is true. The same pattern likely affectsnle,ngtandnge.u(a != a || b != b) to the constant 0 (andopresumably to true).🤖 Generated with Claude Code