<div dir="ltr">Hi,<div><br></div><div style>I was recently looking into the translation of LLVM-IR vector instructions to ARM NEON assembly. Specifically, when this is legal to do and when we need to be careful.</div><div style>
<br></div><div style>I attached a very simple test case:</div><div style><br></div><div style><div>define <4 x float> @fooP(<4 x float> %A, <4 x float> %B)</div><div>{</div><div><span class="" style="white-space:pre"> </span>%C = fmul <4 x float> %A, %B</div>
<div><span class="" style="white-space:pre"> </span>ret <4 x float> %C<br></div><div>}</div><div><br></div><div style>If fooP is compiled with "llc -march=arm -mattr=+vfp3,+neon" LLVM happily uses ARM NEON instructions to implement the vector multiply. This is obviously the fastest code that we can generate, but on the other hand we loose precision compared to non-NEON code (NEON flushes denormals to zero).</div>
<div style><br></div><div style>As LLVM has now support for IR level fast-math flags, I am wondering if it now would make sense to only create NEON instructions if the relevant fast math flags are set on the IR level?</div>
<div style><br></div><div style>The reason behind my question is that at the moment the only way to get IEEE 754 floating point operations on ARM is to fully disable NEON. However, NEON can be safely used for integer computations as well as for LLVM-IR instructions with the appropriate fast math flags. The attached test case contains an example of a floating point operation that requires IEEE 754 compliance, a floating point operation that does not require IEEE 754 as well as an integer computation. It is a perfect mixed use case, where we really do not want to globally disable NEON.</div>
<div style><br></div><div style>I understand that some users do not require 754 compliant floating point behavior (clang on darwin?), which means they would probably not need this change. However, it should also not hurt them performance-wise as such users would probably set the relevant global fast-math flags to reduce the precision requirements, such that NEON instructions would be chosen anyway.</div>
<div style><br></div><div style>I am very interested in opinions on the general topic as well as how to actually implement this in the ARM target.<br></div><div style><br></div><div style>All the best,<br></div><div style>
Tobias</div><div style><br></div><div style>[1] <a href="http://llvm.org/docs/LangRef.html#fast-math-flags">http://llvm.org/docs/LangRef.html#fast-math-flags</a></div></div></div>