Recompiler: direct f32 compares test for NaN explicitly again #3539
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3539"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ivall/xcl. Originally posted by ArtuArtaza on 2026-11-30T17:38:27Z.
Since
a899ec90(#3269) three GPU tests fail on my RX 6700 XT (driver 32.0.21045.29003):gpu_f32_compares_with_nan,gpu_float_compares_randomandf32_programs_on_the_gpu. That commit lowered the direct translator's f32 compares (f16 ones go through f32) to onefcmpeach and dropped the explicit NaN tests, which the translators have because of an AMD driver bug (#46). This PR puts the explicit form back for f32. Related: #46, #3269, #2258, #3023, #42.The DXIL of
a899ec90is right; the driver does two wrong things with it:fcmp one(whatv_cmp_lgbecame) forune: a NaN operand gives true instead of false;oltandult,oeqandueq, ...) the first one's result, in either order, also when one of them is written with its operands swapped (olt a, bandugt b, a).v_cmp_lt_f32thenv_cmp_nge_f32is such a pair.How it was narrowed (local probes, not in this PR):
5b0d5fa3(the parent) passes the three tests,a899ec90fails them (2 runs), main9dfbe3eawith only this change passes them.fcmps of the same two loaded floats in a compute kernel with no wave operation, all 182 ordered pairs of the 14 predicates, results against IEEE: RX 6700 XT 36 pairs wrong (26 of them containone, 10 are the merged ones), WARP 0 wrong, from the same DXIL. The translator's own kernels give the same 36 in wave32 and wave64, also withXCL_DXIL_NO_OPT=all: no optimizer pass takes part.!(a >= b)intofcmp ult. #2258 (the same change as ina899ec90, open) was reported failing on an RX 9070 XT and an RX 6800M. #3269 lists AMD GPUs under "Not tested".GetCachedBlobholds only a key), so "merges" is read from the results.Other forms tried on this card:
fcmp)lgasoltorogt, the rest onefcmp(amd-dev's form)nX=xor (oX), true,lg=oltorogtThe third form is much smaller, but it relies on the driver not folding the
xorback into an unordered compare, and I can only measure one driver. The explicit form does not depend on what the driver makes of anfcmpof a NaN, and it is what main emitted untila899ec90. If the third form also passes on RDNA3 / RDNA4 drivers, it could replace this one.What is in it
crates/xcl/src/gpu/dxil/lower_valu.rs:float_compareloses its f32 branch, so f32 takes the explicit form that f64 already takes; the comment gives the reason.f32_compares_use_no_predicate_that_amd_merges: the 14 f32 compares, wave32 and wave64, must not disassemble toone,ueq,ugt,uge,ultorule. It needs no GPU: #3269's NVIDIA runs of the GPU tests passed, so they did not show this.TRANSLATOR_VERSIONbump: agpu/dxiledit changes the direct translations' cache identity by itself.Tested
CARGO_PROFILE_DEV_DEBUG=0,CARGO_PROFILE_RELEASE_DEBUG=0).cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4one921d6a9(on main9dfbe3ea): 2884 passed, 4 failed, 51 ignored (44 test binaries). The 4 are 3 tests, and all 3 fail with the same values on unmodified main9dfbe3eaon this card (ran them there alone):gpu_compact_form_with_micro_blocks_and_literal_table_runs_as_the_plain_form(what #3473 fixes),gpu_direct_image_get_resinfo_d16(see #3513) andtwo_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobs(parent and child run). 4SKIPPED(2 no heap windows, 1 no GPU_UPLOAD heaps, 1 cannot disable the driver cache).cargo test -p xcl --lib -- gpu_f32_compares_with_nan gpu_float_compares_random f32_programs_on_the_gpu --test-threads=1): pass oncfb9753aand5b0d5fa3, fail ona899ec90, pass here. The new test fails with main'sfloat_compare(fcmp one) and passes with this one.xcl shaders <archive> --direct --sample 600 --seed 3 --max-bytes 40000 --split 0 --timeout 120, summed DXIL, both forms from one local build of9dfbe3eawith a switch): 24,387,884 B on main, 24,789,936 B here (+1.65 %).--sample 4000 --seed 11 --max-bytes 60000 --split 0): 1,925 programs hold anfcmp one(15,852 of 929,962 f32fcmps), 5 hold a pair the driver would merge. It only matters in lanes where an operand is NaN; whether the picture changes was not measured.Regression run
60 s (menus),
scripts/smoke.ps1,XCL_DEVICE_TYPE=lockhart XCL_PREPARE=0, A pressed every 15 s from 30 s: main9dfbe3ea, then this PR's head (which ran first).Not tested
a899ec90).AI use
🤖 Generated with Claude Code
Imported from ivall/xcl. Originally posted by Zippp69 on 2026-11-30T19:06:45Z.
Review: COMMENTED
Skip the predicate regression test when DXC is unavailable
The new predicate regression test fails on hosts without DXC before it can check the predicates. Check
dxc::location()up front and useskip_test("no DXC")if the compiler is unavailable. Keep validation and disassembly failures visible when DXC is installed.Local verification on Windows 11, DXC 1.9.2602.17. I applied the PR diff to
9dfbe3e, verified that the changed source file matchese921d6a, and ran the original and guarded variants separately withcargo test --offline --locked -p xcl --lib <test> -- --exact --nocapture.1 passedeach).dxcompiler.dll not found. The guarded variant reportedSKIPPED: no DXCand exited successfully.Codex assisted with the review, patch, and targeted test runs.
Imported from ivall/xcl. Originally posted by Gevroska on 2026-11-30T20:23:56Z.
@ArtuArtaza I ran your predicate test unchanged on parent
9dfbe3eaand PR heade921d6a9. On the parent, DXIL validation succeeded, but the assertion caughtfcmp onein the wave32 disassembly (wave64 false: fcmp one). On the head, the assertion passed in both wave32 and wave64 emission modes.I also ran the three existing numerical tests on my RTX 3080 (driver 616.92, DXC
1.9.2609.5,XCL_DIRECT_DXIL=1). All three passed on both revisions. The random test checked 1,600 lanes × 33 comparisons per precision with zero distinct failures. The program test passed the same six wave32 cases and skipped the same six native-wave64 cases on both builds.The regression test catches the old instruction on the parent. The numerical results showed no regression on this NVIDIA adapter. I didn’t test the reported AMD driver behavior.
I used Codex GPT-6.2 Sol to run the comparison. A separate GPT-6.2 Sol agent reviewed the source and test evidence. Codex GPT-6.2 Astra drafted this comment.
I reviewed and approved this comment before posting.
Imported from ivall/xcl. Originally posted by andresd-cerebras on 2026-11-30T21:49:37Z.
Code review location:
crates/xcl/src/gpu/dxil/lower_valu.rs; line 1552Suggest also asserting the IsNaN
dx.opcall is present. As written, a form with no NaN test at all passes.Imported from ivall/xcl. Originally posted by andresd-cerebras on 2026-11-30T21:49:37Z.
Review: COMMENTED
Withdrawn.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T07:36:25Z.
Review (head
261483f8, diff read, not a merge-check: thePR descriptioncheck fails, so not built or run here yet):e921d6a9, not the head261483f8, which is whyPR descriptionfails. The two differ only in the new test's DXCskip_testguard, so rerunningscripts/smoke.ps1on the head and updating the counts should do.lower_image.rs~473 still emitsfcmp une.Fine: removing the f32 branch brings back exactly the explicit NaN form (
isnanthroughisSpecialFloatplus ordered compares) main had beforea899ec90(#3269); f16 compares become f32 first and f64 already used this form (lower_wide.rs~889); thefcmpthe translator emits carries no fast-math flags (lower.rs~722);f32_compares_use_no_predicate_that_amd_mergesfails on main'sfcmp one, needs no GPU and skips without DXC, and its positivefcmp olt floatcheck keeps the other assertions from passing vacuously. The cost is about twoisnanand one or two logic ops per compare (+1.65 % DXIL as measured by the author, not checked here).AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T10:10:50Z.
Triage (#1607) – head
261483fNo other open PR restores the explicit NaN tests for f32 compares. #2258 goes the other way: one
fcmpper compare, for f64 too.a899ec90(#3269) brought that form to main for f32, and this PR reverts it for f32.No problems found in the diff: f32 now goes through the same
rel/isnan_anypath as f64.f32_compares_use_no_predicate_that_amd_mergeschecks, after the optimizer, that noone/ueq/ugt/uge/ult/ulecomes back in wave32 or wave64.Recommendation: keep open.
AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T14:11:44Z.
@Prime1997 could you take a look at this one for review and merge? My automated review notes are above, if any.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.