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

Lewis Crawford via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 22 10:04:30 PDT 2025


LewisCrawford wrote:

> 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.

Yes, although the sNaN propagation issue could only happen in the middle-end, since nvvm_fmax currently becomes PTX max, so it's only during the middle-end time when it is interpreted as llvm.maxnum that there could be any semantic differences (e.g. during constant-folding).

Also, this InstSimplify optimization I'm updating in this patch did not handle maxnum(x, sNaN) -> qNaN before (it used to only do maxnum(x, NaN) -> x in the same way PTX max does), so this different behaviour might become slightly more apparent after the sNaN correctness fixes included in my patch here.

> nvvm.fmin/fmax do not appear to be widely used

They are widely used in NVCC.

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

Yes, I'm working on a patch for this at the moment, which I should hopefully be able to upstream soon. It's 5 lines of code plus some tests, so was very straightforward to add.

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


More information about the llvm-commits mailing list