This is an archive of the discontinued LLVM Phabricator instance.

[RFC][IR] llvm.minimum/maximum NaN propagation.
AbandonedPublic

Authored by samparker on Feb 1 2023, 2:00 AM.

Details

Summary

Further align the semantics of minimum and maximum with IEEE-754-2019.

From Section 6.2.3,

An operation that propagates a NaN operand to its result and has a single NaN
as an input should produce a NaN with the payload of the input NaN if
representable in the destination format.

`If two or more inputs are NaN, then the payload of the resulting NaN should be
identical to the payload of one of the input NaNs if representable in the
destination format. This standard does not specify which of the input NaNs
will provide the payload.

This will enable us to, in some specific circumstances, to combine fcmp -> select into an intrinsic, just as what has been done for integer operations.

But do these semantics work for all our backends that use them?

For AArch64, I think this is okay for both scalar, NEON and SVE (although the textual SVE description looks like it has a bug in it, it shares the same pseudo code).

For WebAssembly, this aligns with propagating a canonical NaN but otherwise the return value is picked non-deterministically. Is it okay that LLVM IR is stricter in this case?

I haven't looked at other ISAs...

Diff Detail

Unit TestsFailed

Event Timeline

samparker created this revision.Feb 1 2023, 2:00 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 1 2023, 2:00 AM
samparker requested review of this revision.Feb 1 2023, 2:00 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 1 2023, 2:00 AM
Herald added a subscriber: wdng. · View Herald Transcript
arsenm added a comment.Feb 1 2023, 2:30 AM

I would remove the RFC, this isn’t a behavior change and is just inlining the definition into the LangRef

llvm/docs/LangRef.rst
14844

Are the payload bits really guaranteed?

samparker added inline comments.Feb 1 2023, 3:30 AM
llvm/docs/LangRef.rst
14844

That's the purpose of this RFC, no? The proposal would allow minimum/maximum to behave as fcmp + select and, as the select is bitwise, the payload should be identical.

sunfish added inline comments.Feb 1 2023, 10:12 AM
llvm/docs/LangRef.rst
14809

Requiring the output NaN to be one of the input NaNs is stronger than what IEEE 754 requires (it describes NaN propagation as a recommendation but not as a requirement). And, it prevents implementing these intrinsics efficiently on ARM CPUs configured for Default NaN mode, RISC-V (as far I can tell from the manual), and Wasm.

samparker abandoned this revision.Feb 2 2023, 1:41 AM
samparker added inline comments.
llvm/docs/LangRef.rst
14809

Okay, thanks.