[llvm] [LangRef] Clarify nsz semantics (PR #180906)

James Y Knight via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 11 10:49:55 PST 2026


jyknight wrote:

> > This refinement still doesn't work for `select/phi nsz`, right?
> 
> What do you mean by "doesn't work"? For select/phi the semantics stay the same (the input/output distinction is not relevant there).

ISTM that a guarantee of consistent output (from e.g. `fabs`) isn't be particularly useful from a _user_ point-of-view, so long as a phi (marked nsz) can change the sign arbitrarily anyhow.

Having phi, a pseudo-operation, defined as able to change values is just fundamentally weird. I understand the motivation based on wanting to transform `x < 0 ? -x : x` into `abs`, but it doesn't make it not weird...And the concrete implications on Clang's behavior are also odd: under `-fno-unsigned-zeros`, `float f(float a) { return a < 0 ? -a : a; }` can optimize to fabs (because clang emits phi nsz), yet `float f(float a) { float r; if(a < 0) r = -a; else r = a; return r; }` cannot (because there was no `phi nsz` in the input IR).

That said, since this clarification seems aimed at making it easier to write correct analyses easier inside LLVM, rather than making user-level semantics easier to understand, it does seem plausible.

> It may make sense to also allow nsz to change the input sign of an infinity if that would change the sign of a -0.0 or +0.0 result.

Do you have a particular transform in mind where that allowance would be used/useful? I didn't see any transform in current LLVM that looked to depend on that, but I could've missed it.  


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


More information about the llvm-commits mailing list