<div dir="ltr">Here's an example from X86 that reads XMM0. The "let Uses = [XMM0]" adds an implicit physical register input for XMM0. The outs and ins list the other virtual register inputs. The pattern uses XMM0 as an operand like the (set GPR:$rd, (add GPR:$rs1, R14)).<div><br></div><div>let Uses = [XMM0], Constraints = "$src1 = $dst" in {<br>  multiclass SS41I_ternary<bits<8> opc, string OpcodeStr, ValueType VT,<br>                           PatFrag mem_frag, X86MemOperand x86memop,<br>                           SDNode OpNode, X86FoldableSchedWrite sched> {<br>    def rr0 : SS48I<opc, MRMSrcReg, (outs VR128:$dst),<br>                    (ins VR128:$src1, VR128:$src2),<br>                    !strconcat(OpcodeStr,<br>                     "\t{%xmm0, $src2, $dst|$dst, $src2, xmm0}"),<br>                    [(set VR128:$dst,<br>                      (VT (OpNode XMM0, VR128:$src2, VR128:$src1)))]>,<br>                    Sched<[sched]>;<br><br>    def rm0 : SS48I<opc, MRMSrcMem, (outs VR128:$dst),<br>                    (ins VR128:$src1, x86memop:$src2),<br>                    !strconcat(OpcodeStr,<br>                     "\t{%xmm0, $src2, $dst|$dst, $src2, xmm0}"),<br>                    [(set VR128:$dst,<br>                      (OpNode XMM0, (mem_frag addr:$src2), VR128:$src1))]>,<br>                    Sched<[sched.Folded, sched.ReadAfterFold]>;<br>  }<br>}<br></div><div><br></div><div>Here's another more complex example. This one has an input in AL and an output in AL, EFLAGS, and AH. We listed AX in the implicit defs for both AL and AH for some reason.</div><div><br></div><div>let Defs = [AL,EFLAGS,AX], Uses = [AL] in<br>def MUL8r  : I<0xF6, MRM4r, (outs),  (ins GR8:$src), "mul{b}\t$src",<br>               // FIXME: Used for 8-bit mul, ignore result upper 8 bits.<br>               // This probably ought to be moved to a def : Pat<> if the<br>               // syntax can be accepted.<br>               [(set AL, (mul AL, GR8:$src)),<br>                (implicit EFLAGS)]>, Sched<[WriteIMul8]>;<br></div><div><br clear="all"><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature">~Craig</div></div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Apr 10, 2021 at 2:46 PM Marco Speziali <<a href="mailto:marco.speziali@mail.polimi.it">marco.speziali@mail.polimi.it</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 style="overflow-wrap: break-word;">
Dear Craig,
<div>Thanks for the reply. I tried to use the pattern you provided to set list<pattern> inside the ADD instruction. Unfortunately the pattern:</div>
<div><br>
</div>
<div>
<blockquote type="cite">
<div dir="auto"><span style="border-color:rgb(0,0,0) rgb(0,0,0) rgb(0,0,0) rgb(204,204,204)">(set GPR:$rd, (add GPR:$rs1, R14))</span></div>
</blockquote>
<br>
</div>
<div>Does not generate a move of $rs2 to R14. It, for some reason, produces an add with 3 register operands. Which we do not support. The only way to use 2 source registers is to move the second one to R14. For example:</div>
<div><br>
</div>
<div>add rd, rs1, rs2</div>
<div><br>
</div>
<div>Should become:</div>
<div><br>
</div>
<div>mv R14, rs2</div>
<div>add rd, rs1</div>
<div><br>
</div>
<div>Is there a way to automate this process using TableGen?</div>
<div><br>
</div>
<div>Thanks,</div>
<div>Marco Speziali</div>
<div>
<div><br>
<blockquote type="cite">
<div>On 10 Apr 2021, at 19:09, Craig Topper <<a href="mailto:craig.topper@gmail.com" target="_blank">craig.topper@gmail.com</a>> wrote:</div>
<br>
<div>
<div dir="auto">In tablegen you can write</div>
<div dir="auto"><br>
</div>
<div dir="auto"><span style="border-color:rgb(0,0,0) rgb(0,0,0) rgb(0,0,0) rgb(204,204,204)">(set GPR:$rd, (add GPR:$rs1, R14))</span></div>
<div><br>
<div class="gmail_quote">
<div dir="ltr" class="gmail_attr">On Sat, Apr 10, 2021 at 9:19 AM Marco Speziali via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</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">
Dear all,<br>
<br>
I need to implement the following behavior for all instructions that <br>
require two source operands:<br>
<br>
%1 = add i16 %a, %b<br>
<br>
Should match the ADD instruction which has 1 outs and 1 ins. The second <br>
operand %b should be moved into the implicit register R14 (fixed).<br>
For now I implemented the PseudoADD instruction which gets expanded into <br>
a move plus the mentioned ADD instruction.<br>
This obviously creates a low of unnecessary moves and prevents any <br>
optimizations of the register R14 (e.g. R14 could be used as destination <br>
register in previous operations without the need for a move).<br>
<br>
I'd like to transform the dag:<br>
<br>
(set GPR:$rd, (add GPR:$rs1, GPR:$rs2))<br>
<br>
to something like:<br>
<br>
(set R14, GPR:$rs2), (set GPR:$rd, (add GPR:$rs1))<br>
<br>
Is it possible to specify this transformation using TableGen? If now how <br>
could I achieve this?<br>
<br>
<br>
Thanks.<br>
<br>
Best Regards,<br>
Marco Speziali<br>
<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote>
</div>
</div>
-- <br>
<div dir="ltr">~Craig</div>
</div>
</blockquote>
</div>
<br>
</div>
</div>

</blockquote></div>