perf(shader): drop flushes of f32 results that cannot be denormal #4278

Closed
Friesmaniac wants to merge 1 commit from upstream-pr/4278 into main
Friesmaniac commented 2026-10-12 03:56:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Friesmaniac on 2026-10-12T03:56:09Z.


What

DenormalFlushEliminator removes 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, FPMedTri32 of denormal-free operands: EmitMinMaxF32Value and EmitFPMedTri32 select operand bits, or the AND/OR of two zeros.
  • BitwiseAnd32 with 0x80000000 (always ±0), and BitwiseOr32 with a constant that has an exponent bit set (the exponent stays non-zero). This covers the sign and signed-infinity arms that unaryFloatSpecials builds, so the flushes after v_sqrt_f32, v_rsq_f32 and v_floor_f32 go away as well.

FPFract32, FPRecip32 and 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-seh r4; not the supported 15.2.0 r7), Release with BUILD_TESTING=ON, NVIDIA GeForce RTX 4070 SUPER (driver 32.0.16.1714).

  • agc_denormal_flush_elimination has three new cases. All three fail against main's DenormalFlushEliminator.cpp and pass with this change.
  • Full 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.
  • The 440 tests matching agc|shader|vector|recompil|scalar|pixel|interp, run on the RTX 4070 SUPER, all pass, including agc_driver_f32_denormal_flush.
  • With a local counter (not part of this PR) after the eliminator, over the shaders those 440 tests compile: removed flushes 2229 → 2345, IR instructions after the pass 292,777 → 292,402 (−375). These are small test shaders; no title was run, and pipeline compile time was not measured.
  • python3 tools/check_conventions.py --base origin/main and git diff --check pass.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes (Claude Code)

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4824731109 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4278). Originally posted by [Friesmaniac](https://github.com/Friesmaniac) on 2026-10-12T03:56:09Z. --- ### What `DenormalFlushEliminator` removes 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`, `FPMedTri32` of denormal-free operands: `EmitMinMaxF32Value` and `EmitFPMedTri32` select operand bits, or the AND/OR of two zeros. - `BitwiseAnd32` with `0x80000000` (always ±0), and `BitwiseOr32` with a constant that has an exponent bit set (the exponent stays non-zero). This covers the sign and signed-infinity arms that `unaryFloatSpecials` builds, so the flushes after `v_sqrt_f32`, `v_rsq_f32` and `v_floor_f32` go away as well. `FPFract32`, `FPRecip32` and 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-seh` r4; not the supported 15.2.0 r7), Release with `BUILD_TESTING=ON`, NVIDIA GeForce RTX 4070 SUPER (driver 32.0.16.1714). - `agc_denormal_flush_elimination` has three new cases. All three fail against `main`'s `DenormalFlushEliminator.cpp` and pass with this change. - Full `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. - The 440 tests matching `agc|shader|vector|recompil|scalar|pixel|interp`, run on the RTX 4070 SUPER, all pass, including `agc_driver_f32_denormal_flush`. - With a local counter (not part of this PR) after the eliminator, over the shaders those 440 tests compile: removed flushes 2229 → 2345, IR instructions after the pass 292,777 → 292,402 (−375). These are small test shaders; no title was run, and pipeline compile time was not measured. - `python3 tools/check_conventions.py --base origin/main` and `git diff --check` pass. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes (Claude Code) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-actions[bot] commented 2026-10-12 03:56:26 +00:00 (Migrated from github.com)

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 main can 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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6117461188 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4278#issuecomment-6117461188). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-12T03:56:26Z. --- Thank you for your contribution! Authors with no pull requests merged into `main` can 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.
oneandonlydean commented 2026-10-17 23:57:53 +00:00 (Migrated from github.com)

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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6243431724 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4278#issuecomment-6243431724). Originally posted by [oneandonlydean](https://github.com/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.
xXPBSXx commented 2026-10-20 22:14:21 +00:00 (Migrated from github.com)

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): branch xXPBSXx:fix/denormal-flush-more-cases (da67f279f1, one commit, authorship kept, Friesmaniac and Claude as co-authors).

As the review noted, main already skips the flush for floor/ceil/min/max/med, the sign-bit masks (clearsSignificand) and phis. The rebase keeps only what main does not cover yet: FPTrunc32, FPRoundEven32, FPSqrt, FPRecipSqrt32 (their results cannot be denormal) and a BitwiseOr32 with an exponent bit set. FPFract32 and FPRecip32 still keep their flush, and the tests say so.

Windows 10 19045, WinLibs GCC 15.2.0, Release, BUILD_TESTING=ON, merged on main 339217ebc9 (clean merge):

  • Re-run on main 339217ebc9: agc_denormal_flush_elimination passes 3 of 3 with the change and fails 3 of 3 with main's eliminator. The wider f32 test family was not re-run.
  • tools/check_conventions.py clean; merge-tree clean; pr_overlap only compares against this PR itself.
  • Not tested: GPU runs, any title.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6302970070 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4278#issuecomment-6302970070). Originally posted by [xXPBSXx](https://github.com/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): branch `xXPBSXx:fix/denormal-flush-more-cases` (`da67f279f1`, one commit, authorship kept, Friesmaniac and Claude as co-authors). As the review noted, `main` already skips the flush for floor/ceil/min/max/med, the sign-bit masks (`clearsSignificand`) and phis. The rebase keeps only what `main` does not cover yet: `FPTrunc32`, `FPRoundEven32`, `FPSqrt`, `FPRecipSqrt32` (their results cannot be denormal) and a `BitwiseOr32` with an exponent bit set. `FPFract32` and `FPRecip32` still keep their flush, and the tests say so. Windows 10 19045, WinLibs GCC 15.2.0, Release, `BUILD_TESTING=ON`, merged on `main` `339217ebc9` (clean merge): - Re-run on `main` `339217ebc9`: `agc_denormal_flush_elimination` passes 3 of 3 with the change and fails 3 of 3 with `main`'s eliminator. The wider f32 test family was not re-run. - `tools/check_conventions.py` clean; merge-tree clean; `pr_overlap` only compares against this PR itself. - Not tested: GPU runs, any title. AI-assisted (Claude Code).

Pull request closed

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
boykopovar/AnyPS5!4278
No description provided.