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

Closed
ErenYeager1836 wants to merge 1 commit from upstream-pr/5086 into main
ErenYeager1836 commented 2026-10-13 11:11:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ErenYeager1836 on 2026-10-13T11:11:35Z.


What

DenormalFlushEliminator removes the f32 denormal flush (and, iequal, and, select, 4 IR instructions) on values it can prove are not denormal. Narrowed to avoid overlap with #4490, #4737, and #4539:

  • FPTrunc32, FPRoundEven32: the result is integral, ±0, ±inf or NaN.
  • FPSqrt, FPRecipSqrt32: the square root of the smallest denormal is ~2^-74.5, and the reciprocal square root of the largest float is ~2^-64, so neither produces an f32 denormal.
  • 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, allowing flushes after v_sqrt_f32, v_rsq_f32 and v_floor_f32 to be eliminated.
  • Unit test cases in core/libs/prx/libSceAgcDriver/tests/DenormalFlushElimination.cpp.

Carried from @Friesmaniac with attribution preserved.

Tested

Linux and Windows: core/libs/prx/libSceAgcDriver/tests/DenormalFlushElimination.cpp test suite passes.

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 under Silent stubs in their library's technical debt file
  • 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: #4490, #4539, #4737
  • Unblocks: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4842327687 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5086). Originally posted by [ErenYeager1836](https://github.com/ErenYeager1836) on 2026-10-13T11:11:35Z. --- ### What `DenormalFlushEliminator` removes the f32 denormal flush (`and`, `iequal`, `and`, `select`, 4 IR instructions) on values it can prove are not denormal. Narrowed to avoid overlap with #4490, #4737, and #4539: - `FPTrunc32`, `FPRoundEven32`: the result is integral, ±0, ±inf or NaN. - `FPSqrt`, `FPRecipSqrt32`: the square root of the smallest denormal is ~2^-74.5, and the reciprocal square root of the largest float is ~2^-64, so neither produces an f32 denormal. - `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, allowing flushes after `v_sqrt_f32`, `v_rsq_f32` and `v_floor_f32` to be eliminated. - Unit test cases in `core/libs/prx/libSceAgcDriver/tests/DenormalFlushElimination.cpp`. Carried from @Friesmaniac with attribution preserved. ### Tested Linux and Windows: `core/libs/prx/libSceAgcDriver/tests/DenormalFlushElimination.cpp` test suite passes. ### 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 under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [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: #4490, #4539, #4737 - [x] Unblocks: none - [x] AI-assisted: yes
karanvora2599 commented 2026-10-13 15:56:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by karanvora2599 on 2026-10-13T15:56:35Z.


@ErenYeager1836, this overlaps three open PRs that change the same switch in DenormalFreeValues:

  • #4490 (opened 2026-10-12) already adds FPMin32, FPMax32, FPMinTri32, FPMaxTri32 and FPMedTri32 when every operand is denormal-free, plus FPFloor32 and FPCeil32, with tests in DenormalFlushElimination.cpp.
  • #4737, stacked on #4490, adds FPFract32, FPSin and FPCos. The first new test here expects the flush after FPFract32 to stay, so it fails once #4737 is in.
  • #4705 removes EmitFlushF32DenormToSignedZero, which is the reason given here for FPSqrt and FPRecipSqrt32. Both rules still hold without it: the square root of the smallest denormal is about 2^-74.5, and the reciprocal square root of the largest float is about 2^-64. Only the description's reason would change.
  • #4539 adds an FPMul32 case to the same switch.

What's new here is FPTrunc32, FPRoundEven32, FPSqrt, FPRecipSqrt32 and the BitwiseAnd32/BitwiseOr32 masks. Could you narrow this PR to those and list #4490 under Depends on? Then the two won't conflict. If this one lands first, I'll rebase #4737 onto it.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6149622980 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5086#issuecomment-6149622980). Originally posted by [karanvora2599](https://github.com/karanvora2599) on 2026-10-13T15:56:35Z. --- @ErenYeager1836, this overlaps three open PRs that change the same switch in `DenormalFreeValues`: - #4490 (opened 2026-10-12) already adds `FPMin32`, `FPMax32`, `FPMinTri32`, `FPMaxTri32` and `FPMedTri32` when every operand is denormal-free, plus `FPFloor32` and `FPCeil32`, with tests in `DenormalFlushElimination.cpp`. - #4737, stacked on #4490, adds `FPFract32`, `FPSin` and `FPCos`. The first new test here expects the flush after `FPFract32` to stay, so it fails once #4737 is in. - #4705 removes `EmitFlushF32DenormToSignedZero`, which is the reason given here for `FPSqrt` and `FPRecipSqrt32`. Both rules still hold without it: the square root of the smallest denormal is about 2^-74.5, and the reciprocal square root of the largest float is about 2^-64. Only the description's reason would change. - #4539 adds an `FPMul32` case to the same switch. What's new here is `FPTrunc32`, `FPRoundEven32`, `FPSqrt`, `FPRecipSqrt32` and the `BitwiseAnd32`/`BitwiseOr32` masks. Could you narrow this PR to those and list #4490 under **Depends on**? Then the two won't conflict. If this one lands first, I'll rebase #4737 onto it.
ErenYeager1836 commented 2026-10-13 16:04:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ErenYeager1836 on 2026-10-13T16:04:59Z.


Thanks for the thorough breakdown @karanvora2599!

I have rebased onto current main and narrowed this PR specifically to the non-overlapping operations:

  • Kept FPTrunc32, FPRoundEven32, FPSqrt, FPRecipSqrt32, and the bitwise mask handling (BitwiseAnd32 with 0x80000000 and BitwiseOr32 setting exponent bits).
  • Removed the min/max/med cases and FPFloor32/FPCeil32 that are covered by #4490, as well as the test asserting on FPFract32 to avoid conflicts with #4737.
  • Updated the PR description checklist with Depends on: #4490.
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6149785307 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5086#issuecomment-6149785307). Originally posted by [ErenYeager1836](https://github.com/ErenYeager1836) on 2026-10-13T16:04:59Z. --- Thanks for the thorough breakdown @karanvora2599! I have rebased onto current `main` and narrowed this PR specifically to the non-overlapping operations: - Kept `FPTrunc32`, `FPRoundEven32`, `FPSqrt`, `FPRecipSqrt32`, and the bitwise mask handling (`BitwiseAnd32` with `0x80000000` and `BitwiseOr32` setting exponent bits). - Removed the min/max/med cases and `FPFloor32`/`FPCeil32` that are covered by #4490, as well as the test asserting on `FPFract32` to avoid conflicts with #4737. - Updated the PR description checklist with `Depends on: #4490`.
karanvora2599 commented 2026-10-13 21:53:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by karanvora2599 on 2026-10-13T21:53:53Z.


Thanks @ErenYeager1836. I checked the narrowed diff and each new rule holds:

  • FPSqrt is f32-only (FPSqrt64 is a separate opcode).
  • An OR with a constant that has an exponent bit set leaves the exponent non-zero.
  • An AND with 0x80000000 gives ±0.

It no longer overlaps #4490 or #4737 beyond neighbouring lines.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6155999271 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5086#issuecomment-6155999271). Originally posted by [karanvora2599](https://github.com/karanvora2599) on 2026-10-13T21:53:53Z. --- Thanks @ErenYeager1836. I checked the narrowed diff and each new rule holds: - `FPSqrt` is f32-only (`FPSqrt64` is a separate opcode). - An OR with a constant that has an exponent bit set leaves the exponent non-zero. - An AND with `0x80000000` gives ±0. It no longer overlaps #4490 or #4737 beyond neighbouring lines.
oneandonlydean commented 2026-10-14 02:33:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T02:33:43Z.


Closing: no title is known to reach this. With the queue at 700+ open PRs, please hold off on new PRs that don't name a title needing the change until it's down. If a title stops on this on current main, reopen with the title ID and the log line.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6159596712 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5086#issuecomment-6159596712). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-14T02:33:43Z. --- Closing: no title is known to reach this. With the queue at 700+ open PRs, please hold off on new PRs that don't name a title needing the change until it's down. If a title stops on this on current main, reopen with the title ID and the log line.

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!5086
No description provided.