The default implementation of findCommutedOpIndices returns the first two input operands which works for these instructions. We also have precedent in the commuting of SHRD and SHLD instructions which have a third immediate argument. They have partial custom code, but don't change from the default implementation of findCommutedOpIndices.<br>

<br>I made them commutable so that TwoAddressInstructionPass and optimizeLoadInstr can better optimize them.<br><br>We can still do better here because there are 3 different FMA3 opcodes that vary which operand is the destructive dest and where the load can be folded. Not sure the best way to work some of that into the infrastructure without creating a new pass. I'd appreciate any input you have on that.<br>

<br>~Craig<br><br><div class="gmail_quote">On Tue, Sep 4, 2012 at 10:32 AM, Jakob Stoklund Olesen <span dir="ltr"><<a href="mailto:stoklund@2pi.dk" target="_blank">stoklund@2pi.dk</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<br>
On Aug 31, 2012, at 4:10 PM, Craig Topper <<a href="mailto:craig.topper@gmail.com" target="_blank">craig.topper@gmail.com</a>> wrote:<br>
<br>
> Author: ctopper<br>
> Date: Fri Aug 31 18:10:34 2012<br>
> New Revision: 163035<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=163035&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=163035&view=rev</a><br>
> Log:<br>
> Mark FMA4 instructions as commutable and add them to the folding tables.<br>
><br>
<br>
> multiclass fma4s<bits<8> opc, string OpcodeStr, RegisterClass RC,<br>
>                  X86MemOperand x86memop, ValueType OpVT, SDNode OpNode,<br>
>                  PatFrag mem_frag> {<br>
> +  let isCommutable = 1 in<br>
>   def rr : FMA4<opc, MRMSrcReg, (outs RC:$dst),<br>
>            (ins RC:$src1, RC:$src2, RC:$src3),<br>
>            !strconcat(OpcodeStr,<br>
<br>
Hi Craig,<br>
<br>
I am not sure it is safe to mark 3-input instructions as commutable. See TargetInstrInfoImpl::findCommutedOpIndices().<br>
<br>
Why do you need to do that?<br>
<span><font color="#888888"><br>
/jakob<br>
<br>
</font></span></blockquote></div><br><br clear="all"><br>-- <br>~Craig<br>