[llvm] LangRef: Clarify behaviors of nsz in fast math flag (PR #137567)

Joshua Cranmer via llvm-commits llvm-commits at lists.llvm.org
Fri May 30 14:24:44 PDT 2025


jcranmer-intel wrote:

To me, the primary goal of `nsz`, to me, is to allow the interconversion of `fsub 0, x` and `fneg x`; the select form of `abs(x)` to `fabs(x)`, and (in conjunction with `nnan`) between any of the ways to write a min/max operation. For the latter case in particular, I think either direction is necessary to support, as the user intent is to get whichever hardware minimum instruction is implemented, and these do vary in which of the versions is actually implemented in hardware.

I'm also understanding that part of the point of this PR is to clarify that `nsz` can't "invent" a `-0.0` out-of-thin-air, for some definition of the latter term. (Note that it can't just be a straight "`-0.0` results become `+0.0`, since `fsub +0.0, +0.0` -> `fneg +0.0` turns `+0.0` to `-0.0`).

I'm not entirely happy with the proposed wording, it's a bit of a weird interlude into the definition. My first cut for a better replacement is that non-computational instructions like minimum or select can only return a `-0.0` if one of its inputs was `-0.0`, but I've noticed that the proposal here allows `select nsz i1 %cond, +0.0, +0.0` to be `-0.0`, and I don't know if there is an optimization that actually requires that to be the case.

https://github.com/llvm/llvm-project/pull/137567


More information about the llvm-commits mailing list