[llvm] [InstSimplify] Optimize maximumnum and minimumnum (PR #139581)

Artem Belevich via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 20 12:19:58 PDT 2025


Artem-B wrote:

> PTX does not treat sNaN/qNaN differently, and will return the other non-NaN input, whereas LLVM's maxnum/minnum intrinsics state that they must return NaN if either operand is sNaN. 

So, the practical impact is that the code that currently uses `nvvm_fmin/fmax` will end up always propagating sNaNs, while the actual `fmax/fmin` PTX instruction would not.

The actual problem is that the users never got the "just fmax/fmin instruction" they intended to have, and by now that behavior has effectively become part of the API. The good news is that nvvm.fmin/fmax do not appear to be widely used. At least I can't find any references to them outside of LLVM/clang and their tests, in our code base.

> So the maximumnum/minimumnum intrinsics match the semantics of PTX better since they don't make any distinction between sNaNs and qNaNs.

Agreed. The switch itself is trivial, so we should be able to revert the change easily, if there are problems.

Adding lowering of maximumnum/minimumnum -> fmax.f32/fmin.f32 should be pretty straightforward, too.


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


More information about the llvm-commits mailing list