[mlir][tosa] Extend allow-non-finites to max_pool2d (#229869)
`TosaToLinalgNamed` seeds float max pooling with `APFloat::getLargest`,
i.e. `-3.40282347E+38` for f32. The spec asks for `-infinity`:
MAX_POOL2D (§2.3.8) initializes its accumulator with
`minimum_s<in_out_t>()`, and Table 5 (§1.9) defines that as `-infinity`
for the floating-point types.
This adds an `allow-non-finites` option to `tosa-to-linalg-named` that
selects the conforming seed, mirroring the option added to
`tosa-to-linalg` in #222140. It is off by default, so nothing changes
unless you ask for it — the finite seed stays available for targets that
can't represent infinities, which includes TOSA's own `fp8e4m3_t`.
This is the follow-up I mentioned on #222140, where `max_pool2d` was
left out to keep that review small.
The `nan_mode = IGNORE` arm is deliberately untouched. The spec requires
a NaN seed there and #225744 already implements it, so between the two
patches both arms of that one spec line are now covered. Tests assert
the NaN seed under *both* settings to pin that down.
One refactor came along for the ride: `getFloatMinMaxIdentity` moves out
of `TosaToLinalg.cpp` into `Tosa/Utils/ConversionUtils`, which both
conversions already include. The `semanticsHasInf` guard inside it is
load-bearing — `APFloat::getInf` silently returns a NaN under NanOnly
semantics — so one shared copy is better than two that can drift.
Testing: `tosa-to-linalg-named.mlir` gains a fourth RUN line with
`allow-non-finites=true`, so every existing case in the file is now
checked under both settings. Only the four seed constants differ, split
`FINITE`/`NONFINITE`. Added PROPAGATE-mode bf16 and f16 cases, which had
no coverage before and are what pin the non-f32 encodings. `check-mlir`
is clean.
---
Parts of this patch were drafted with AI assistance (Claude). I
reviewed, tested, and edited the result, and I'm accountable for it.
Co-authored-by: Hariprasad Ravishankar <hravisha@ls-01-1c-a0-b8-77-e7-5d.dhcp.mathworks.com>
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>