<div dir="ltr"><div><div><div>Hi Lang,<br><br></div>Unfortunately, I don't have an answer on the commutability question, but I wanted to let you know that I filed a bug on this:<br><a href="http://llvm.org/bugs/show_bug.cgi?id=17229">http://llvm.org/bugs/show_bug.cgi?id=17229</a><br>
<br></div>This also shows a memory operand variant of the fma that you may want to consider in your patch and testcases.<br><br></div>Thanks!<br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Dec 19, 2013 at 10:45 PM, Lang Hames <span dir="ltr"><<a href="mailto:lhames@gmail.com" target="_blank">lhames@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi all,<br>
<br>
The 213 variant of the FMA3 instructions is currently marked<br>
commutable (see X86InstrFMA.td). Is that safe? According to the ISA<br>
the FMA3 instructions aren't commutable for non-numeric results, so<br>
I'd have thought commuting this would only be valid in fast-math mode?<br>
<br>
For the curious, the reason that I'm asking is that we currently<br>
always select the 213 variant, but this introduces an extra copies in<br>
accumulator-style loops. Something like:<br>
<br>
while (...)<br>
  accumulator = x * y + accumulator;<br>
<br>
yields:<br>
<br>
loop:<br>
  vfmadd.213 y, x, acc<br>
  vmovaps acc, x<br>
  decl count<br>
  jne loop<br>
<br>
instead of<br>
<br>
loop:<br>
  vfmadd.231 acc, x, y<br>
  decl count<br>
  jne loop<br>
<br>
I have started writing a patch to generate the 231 variant by default,<br>
and I want to know whether I need to go to the trouble of adding<br>
custom commute logic. If these things aren't commutable then I don't<br>
need to worry at all. If they are commutable, but only in fast-math<br>
mode, then I can support that too.<br>
<br>
Thanks for the help!<br>
<br>
- Lang.<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
</blockquote></div><br></div>