[llvm-dev] Vectorizing minimum without function attributes

Finkel, Hal J. via llvm-dev llvm-dev at lists.llvm.org
Sat May 4 06:41:28 PDT 2019


On 5/4/19 6:36 AM, llvm-dev wrote:
Greetings,

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.

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.


fcmp takes fast-math flags now, but that wasn't always true (my recollection is that was a capability added after the arithmetic operations). In any case, I wonder if this is just a hold-over from before fcmp took fast-math flags, or if this is an && condition that should be an || condition.


This forces us to give up on fine-grained control of fast-math in the code in order to benefit from this vectorization.

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.

Beyond this specific case, it would be nice to be sure when is it ever necessary to set these function attributes, e.g.
https://github.com/llvm/llvm-project/blob/8205a814a691bfa62fed911b58b0a306ab5efe31/clang/lib/CodeGen/CGCall.cpp#L1743-L1750

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?


The goal has been to eliminate the dependence on the function attributes once all of the necessary local flags are in place. Obviously I could be missing something, but this just seems like a bug.

 -Hal

Thanks,

--
Nicolau Werneck <nwerneck at gmail.com<mailto:nwerneck at gmail.com>>
http://n<http://nwerneck.sdf.org>ic.hpavc.net<http://ic.hpavc.net>



_______________________________________________
LLVM Developers mailing list
llvm-dev at lists.llvm.org<mailto:llvm-dev at lists.llvm.org>
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190504/d2e28845/attachment.html>


More information about the llvm-dev mailing list