<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div>Thanks for the reply. I should say I'm actually working on 6.0, but I don't think this part of the code changed much since. These are traces I made with GDB optimizing a loop with floats and then integers, showing where they diverge:</div><div><a href="https://gist.github.com/nlw0/58ed9fda8e8944a9cb5e5a20f6038fcf" target="_blank">https://gist.github.com/nlw0/58ed9fda8e8944a9cb5e5a20f6038fcf</a><br></div><div><br></div><div>This is the point I believe we need to set the function attribute for the vectorization to work with floats:</div><div><a href="https://github.com/llvm/llvm-project/blob/fd254e429ea103be8bab6271855c04919d33f9fb/llvm/lib/Analysis/IVDescriptors.cpp#L590" target="_blank">https://github.com/llvm/llvm-project/blob/fd254e429ea103be8bab6271855c04919d33f9fb/llvm/lib/Analysis/IVDescriptors.cpp#L590</a><br></div><div dir="ltr"><br></div><div>Could this be a bug? It seems to me it just wasn't changed yet to depend only on instruction flags.</div><div><br></div><div>I would gladly work on refactoring this if there's an opportunity, but I'm a complete newbie in this project. It would be great to hear from someone more knowledgeable what can be done about this issue, especially if turns out to be a very small patch!</div><div><br></div><div><br></div></div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, May 4, 2019 at 3:41 PM Finkel, Hal J. <<a href="mailto:hfinkel@anl.gov" target="_blank">hfinkel@anl.gov</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">



<div bgcolor="#FFFFFF">
<div class="m_-3936762248986267557gmail-m_4822098874121832953moz-cite-prefix">On 5/4/19 6:36 AM, llvm-dev wrote:<br>
</div>
<blockquote type="cite">
<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.
</div>
</div>
</div>
</blockquote>
<p><br>
</p>
<p>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.<br>
</p>
<p><br>
</p>
<blockquote type="cite">
<div dir="ltr">
<div dir="ltr">
<div>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" target="_blank">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>
</div>
</blockquote>
<p><br>
</p>
<p>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.</p>
<p> -Hal<br>
</p>
<blockquote type="cite">
<div dir="ltr">
<div dir="ltr">
<div><br>
</div>
<div>Thanks,</div>
<div><br>
</div>
<div>-- <br>
</div>
<div>
<div dir="ltr" class="m_-3936762248986267557gmail-m_4822098874121832953gmail_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>
<br>
<fieldset class="m_-3936762248986267557gmail-m_4822098874121832953mimeAttachmentHeader"></fieldset>
<pre class="m_-3936762248986267557gmail-m_4822098874121832953moz-quote-pre">_______________________________________________
LLVM Developers mailing list
<a class="m_-3936762248986267557gmail-m_4822098874121832953moz-txt-link-abbreviated" href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>
<a class="m_-3936762248986267557gmail-m_4822098874121832953moz-txt-link-freetext" href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a>
</pre>
</blockquote>
<p><br>
</p>
</div>

</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="m_-3936762248986267557gmail_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>