perf(shader): drop flushes of f32 results that cannot be denormal #4278
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4278"
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 boykopovar/AnyPS5. Originally posted by Friesmaniac on 2026-10-12T03:56:09Z.
What
DenormalFlushEliminatorremoves the f32 denormal flush (and,iequal,and,select, 4 IR instructions) on values it can prove are not denormal. It now also recognises:FPFloor32,FPCeil32,FPTrunc32,FPRoundEven32: the result is integral, ±0, ±inf or NaN.FPSqrt,FPRecipSqrt32: the backend flushes the input first (EmitFlushF32DenormToSignedZero), and the result of a non-zero normal input stays at or above 2^-75 (rsq of the largest finite value is about 2^-64).FPMin32,FPMax32,FPMinTri32,FPMaxTri32,FPMedTri32of denormal-free operands:EmitMinMaxF32ValueandEmitFPMedTri32select operand bits, or the AND/OR of two zeros.BitwiseAnd32with0x80000000(always ±0), andBitwiseOr32with a constant that has an exponent bit set (the exponent stays non-zero). This covers the sign and signed-infinity arms thatunaryFloatSpecialsbuilds, so the flushes afterv_sqrt_f32,v_rsq_f32andv_floor_f32go away as well.FPFract32,FPRecip32and an OR with a mantissa-only constant (the IEEE-mode NaN quieting,| 0x00400000) are not treated as denormal-free; the tests pin that.Part of the compile-cost side of #2682: the issue lists the denormal-flush selects as one of the remaining large costs in float-heavy pixel shaders.
Tested
Windows 11 Pro, WinLibs GCC 16.1.0 (
x86_64-ucrt-posix-sehr4; not the supported 15.2.0 r7), Release withBUILD_TESTING=ON, NVIDIA GeForce RTX 4070 SUPER (driver 32.0.16.1714).agc_denormal_flush_eliminationhas three new cases. All three fail againstmain'sDenormalFlushEliminator.cppand pass with this change.ctest: 918 of 923 passed. The 5 failures are the Python tool tests (pr_overlap_encoding,progress_encoding,conventions_function_bodies,conventions_wrapped_declarations,check_skips), which failed to launch subprocesses with the interpreter available here (LibreOffice's bundled Python 3.12); no C++ code is involved.agc|shader|vector|recompil|scalar|pixel|interp, run on the RTX 4070 SUPER, all pass, includingagc_driver_f32_denormal_flush.python3 tools/check_conventions.py --base origin/mainandgit diff --checkpass.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-12T03:56:26Z.
Thank you for your contribution! Authors with no pull requests merged into
maincan have 1 open pull request at a time, authors with at least 1 merged can have 20, and from 20 merged there is no limit. This PR has been automatically closed and labeled "open PR limit" because that limit was reached. This is not a judgment of the quality of your changes: reopen it once one of your open pull requests is merged or closed.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-17T23:57:53Z.
Thanks for reopening this. It no longer merges cleanly into current main. Could you rebase onto current main? Note that main already skips the denormal flush for floor/ceil/min/max, so after the rebase this PR only needs the cases main doesn't cover yet. We'll review and run full CI on the new head.
Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-20T22:14:21Z.
Rebase of this PR onto current
main, offered because it has been quiet since the 17.10. rebase request (happy to drop it if the author updates the PR): branchxXPBSXx:fix/denormal-flush-more-cases(da67f279f1, one commit, authorship kept, Friesmaniac and Claude as co-authors).As the review noted,
mainalready skips the flush for floor/ceil/min/max/med, the sign-bit masks (clearsSignificand) and phis. The rebase keeps only whatmaindoes not cover yet:FPTrunc32,FPRoundEven32,FPSqrt,FPRecipSqrt32(their results cannot be denormal) and aBitwiseOr32with an exponent bit set.FPFract32andFPRecip32still keep their flush, and the tests say so.Windows 10 19045, WinLibs GCC 15.2.0, Release,
BUILD_TESTING=ON, merged onmain339217ebc9(clean merge):main339217ebc9:agc_denormal_flush_eliminationpasses 3 of 3 with the change and fails 3 of 3 withmain's eliminator. The wider f32 test family was not re-run.tools/check_conventions.pyclean; merge-tree clean;pr_overlaponly compares against this PR itself.AI-assisted (Claude Code).
Pull request closed