<div dir="ltr"><div dir="ltr">Greetings,<div><br></div><div>The LLVM loop vectorizer does a great job handling reductions with the `min(a, b)` function over an array of integers or floats. This finds the smallest value of a list exploiting SIMD instructions, and works just as well as a summation.</div><div><br></div><div>Specifically with floats, though, using the `fcmp` instruction, the vectorization seems to require the function attribute "no-nans-fp-math" to be set. Just setting instruction flags is not enough. This forces us to give up on fine-grained control of fast-math in the code in order to benefit from this vectorization.</div><div><br></div><div>How to overcome this? LLVM has intrinsic functions such as `minnum` and `minimum` (`minnan`) that accurately represent the operation. This could permit fine-grained control of fast-math flags, although the vectorizer seems to ignore these intrinsics.</div><div><br></div><div>Beyond this specific case, it would be nice to be sure when is it ever necessary to set these function attributes, e.g.</div><div><a href="https://github.com/llvm/llvm-project/blob/8205a814a691bfa62fed911b58b0a306ab5efe31/clang/lib/CodeGen/CGCall.cpp#L1743-L1750">https://github.com/llvm/llvm-project/blob/8205a814a691bfa62fed911b58b0a306ab5efe31/clang/lib/CodeGen/CGCall.cpp#L1743-L1750</a><br></div><div><br></div><div>What would be a way to control the vectorization for `min` without having to rely on that function attribute? And furthermore, could LLVM optimizations conceivably depend only on instruction flags, and not ever on function attributes? What would be necessary to achieve this?</div><div><br></div><div>Thanks,</div><div><br></div><div>-- <br></div><div><div dir="ltr" class="gmail_signature"><div dir="ltr"><div>Nicolau Werneck <<a href="mailto:nwerneck@gmail.com" target="_blank">nwerneck@gmail.com</a>><br><a href="http://nwerneck.sdf.org" target="_blank">http://n</a><a href="http://ic.hpavc.net" target="_blank">ic.hpavc.net</a><br></div></div></div></div></div></div>