<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">
Dear Craig,
<div class="">I have an other small question if possibile. In my case also branches and stores follows the same rule (second source register must be moved into W).</div>
<div class=""><br class="">
</div>
<div class="">I have this pattern:</div>
<div class=""><br class="">
</div>
<div class="">
<div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal;" class="">
<font face="Menlo" class="">def : Pat<</font></div>
<div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal;" class="">
<font face="Menlo" class="">  (brcond GPR:$cond, bb:$imm),</font></div>
<div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal;" class="">
<font face="Menlo" class="">  (PseudoBNE GPR:$cond, 0, imm16bb:$imm)</font></div>
<div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal;" class="">
<font face="Menlo" class="">>;</font></div>
<div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: "Helvetica Neue";" class="">
<br class="">
</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
Used for brcond without sect (i.e. condition calculated elsewhere). I’d like to remove the PseudoBNE and use BNE (with a single source register). But I cannot figure out how to tell TableGen that 0 must be moved into R14.</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
Other patterns I need to convert are:</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
<br class="">
</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal;" class="">
<div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal;" class="">
<font face="Menlo" class="">def : Pat<</font></div>
<div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal;" class="">
<font face="Menlo" class="">  (truncstorei8 GPR:$src, (i16 (isabella_wrapper tglobaladdr:$dst))),</font></div>
<div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal;" class="">
<font face="Menlo" class="">  (PseudoSB GPR:$src, R0, tglobaladdr:$dst)</font></div>
<div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal;" class="">
<font face="Menlo" class="">>;</font></div>
<div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal;" class="">
<font face="Menlo" class="">def : Pat<</font></div>
<div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal;" class="">
<font face="Menlo" class="">  (store GPR:$src, (i16 (isabella_wrapper tglobaladdr:$dst))),</font></div>
<div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal;" class="">
<font face="Menlo" class="">  (PseudoSW GPR:$src, R0, tglobaladdr:$dst)</font></div>
<div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal;" class="">
<font face="Menlo" class="">>;</font></div>
</div>
<div><br class="">
</div>
<div><span style="font-family: "Helvetica Neue";" class="">R0 is a constant register = 0.</span></div>
<div><span style="font-family: "Helvetica Neue";" class=""><br class="">
</span></div>
<div><span style="font-family: "Helvetica Neue";" class="">The 3 patterns have in common the fact that zero must be moved into R14.</span></div>
<div><span style="font-family: "Helvetica Neue";" class=""><br class="">
</span></div>
<div><span style="font-family: "Helvetica Neue";" class="">For the first pattern (PseudoBNE): is it possibile to transform the dag from </span></div>
<div><span style="font-family: Menlo; font-size: 13px;" class=""><br class="">
</span></div>
<div><span style="font-family: Menlo; font-size: 13px;" class="">(brcond GPR:$cond, bb:$imm)</span></div>
<div><span style="font-family: "Helvetica Neue";" class=""><br class="">
</span></div>
<div><span style="font-family: "Helvetica Neue";" class="">to:</span></div>
<div><span style="font-family: "Helvetica Neue";" class=""><br class="">
</span></div>
<div><span style="font-family: Menlo; font-size: 13px;" class="">(brcond (i16 (setne </span><span style="font-family: Menlo; font-size: 13px;" class="">GPR:$cond, 0</span><span style="font-family: Menlo; font-size: 13px;" class="">)), bb:$imm) </span><span style="font-family: "Helvetica Neue";" class="">?</span></div>
<div><br class="">
</div>
<div><font face="Helvetica Neue" class="">In that way the BNE instruction would be selected automatically. The same for the other two, I’d just need to convert:</font></div>
<div><font face="Helvetica Neue" class=""><br class="">
</font></div>
<div><span style="font-family: Menlo; font-size: 13px;" class="">(store GPR:$src, (i16 (isabella_wrapper tglobaladdr:$dst)))</span></div>
<div><span style="font-family: Menlo; font-size: 13px;" class=""><br class="">
</span></div>
<div><span style="font-family: "Helvetica Neue";" class="">to:</span></div>
<div><span style="font-family: "Helvetica Neue";" class=""><br class="">
</span></div>
<div><span style="font-family: Menlo; font-size: 13px;" class="">(store GPR:$src, (add 0, (i16 (isabella_wrapper tglobaladdr:$dst)))</span></div>
<div><br class="">
</div>
<div>I also tried to do:</div>
<div><br class="">
</div>
<div>
<div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal;" class="">
<font face="Menlo" class="">def : Pattern<</font></div>
<div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal;" class="">
<font face="Menlo" class="">  (brcond GPR:$cond, bb:$imm),</font></div>
<div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal;" class="">
<font face="Menlo" class="">  [</font></div>
<div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal;" class="">
<font face="Menlo" class="">    (set R14, 0),</font></div>
<div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal;" class="">
<font face="Menlo" class="">    (BNE GPR:$cond, imm16bb:$imm)</font></div>
<div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal;" class="">
<font face="Menlo" class="">  ]</font></div>
<div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal;" class="">
<font face="Menlo" class="">>;</font></div>
</div>
<div><br class="">
</div>
<div><font face="Helvetica Neue" class="">Unfortunately since R14 is not directly used by BNE, TableGen complains about temporaries not supported.</font></div>
<div><br class="">
</div>
<div><span style="font-family: "Helvetica Neue";" class="">Thanks for all the help.</span></div>
<div><span style="font-family: "Helvetica Neue";" class=""><br class="">
</span></div>
<div><span style="font-family: "Helvetica Neue";" class="">Marco Speziali</span></div>
<div><br class="">
<blockquote type="cite" class="">
<div class="">On 11 Apr 2021, at 12:31, Marco Speziali <<a href="mailto:marco.speziali@mail.polimi.it" class="">marco.speziali@mail.polimi.it</a>> wrote:</div>
<br class="Apple-interchange-newline">
<div class="">
<div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">
Dear Craig,
<div class="">it now works as intended.</div>
<div class=""><br class="">
</div>
<div class="">Thank you so much,</div>
<div class="">Marco Speziali</div>
<div class=""><br class="">
</div>
<div class="">
<div class=""><br class="">
<blockquote type="cite" class="">
<div class="">On 11 Apr 2021, at 00:06, Craig Topper <<a href="mailto:craig.topper@gmail.com" class="">craig.topper@gmail.com</a>> wrote:</div>
<br class="Apple-interchange-newline">
<div class="">
<div dir="ltr" class="">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 class=""><br class="">
</div>
<div class="">let Uses = [XMM0], Constraints = "$src1 = $dst" in {<br class="">
  multiclass SS41I_ternary<bits<8> opc, string OpcodeStr, ValueType VT,<br class="">
                           PatFrag mem_frag, X86MemOperand x86memop,<br class="">
                           SDNode OpNode, X86FoldableSchedWrite sched> {<br class="">
    def rr0 : SS48I<opc, MRMSrcReg, (outs VR128:$dst),<br class="">
                    (ins VR128:$src1, VR128:$src2),<br class="">
                    !strconcat(OpcodeStr,<br class="">
                     "\t{%xmm0, $src2, $dst|$dst, $src2, xmm0}"),<br class="">
                    [(set VR128:$dst,<br class="">
                      (VT (OpNode XMM0, VR128:$src2, VR128:$src1)))]>,<br class="">
                    Sched<[sched]>;<br class="">
<br class="">
    def rm0 : SS48I<opc, MRMSrcMem, (outs VR128:$dst),<br class="">
                    (ins VR128:$src1, x86memop:$src2),<br class="">
                    !strconcat(OpcodeStr,<br class="">
                     "\t{%xmm0, $src2, $dst|$dst, $src2, xmm0}"),<br class="">
                    [(set VR128:$dst,<br class="">
                      (OpNode XMM0, (mem_frag addr:$src2), VR128:$src1))]>,<br class="">
                    Sched<[sched.Folded, sched.ReadAfterFold]>;<br class="">
  }<br class="">
}<br class="">
</div>
<div class=""><br class="">
</div>
<div class="">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 class=""><br class="">
</div>
<div class="">let Defs = [AL,EFLAGS,AX], Uses = [AL] in<br class="">
def MUL8r  : I<0xF6, MRM4r, (outs),  (ins GR8:$src), "mul{b}\t$src",<br class="">
               // FIXME: Used for 8-bit mul, ignore result upper 8 bits.<br class="">
               // This probably ought to be moved to a def : Pat<> if the<br class="">
               // syntax can be accepted.<br class="">
               [(set AL, (mul AL, GR8:$src)),<br class="">
                (implicit EFLAGS)]>, Sched<[WriteIMul8]>;<br class="">
</div>
<div class=""><br clear="all" class="">
<div class="">
<div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature">~Craig</div>
</div>
<br class="">
</div>
</div>
<br class="">
<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" class="">marco.speziali@mail.polimi.it</a>> wrote:<br class="">
</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;" class="">Dear Craig,
<div class="">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 class=""><br class="">
</div>
<div class="">
<blockquote type="cite" class="">
<div dir="auto" class=""><span style="border-color:rgb(0,0,0) rgb(0,0,0) rgb(0,0,0) rgb(204,204,204)" class="">(set GPR:$rd, (add GPR:$rs1, R14))</span></div>
</blockquote>
<br class="">
</div>
<div class="">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 class=""><br class="">
</div>
<div class="">add rd, rs1, rs2</div>
<div class=""><br class="">
</div>
<div class="">Should become:</div>
<div class=""><br class="">
</div>
<div class="">mv R14, rs2</div>
<div class="">add rd, rs1</div>
<div class=""><br class="">
</div>
<div class="">Is there a way to automate this process using TableGen?</div>
<div class=""><br class="">
</div>
<div class="">Thanks,</div>
<div class="">Marco Speziali</div>
<div class="">
<div class=""><br class="">
<blockquote type="cite" class="">
<div class="">On 10 Apr 2021, at 19:09, Craig Topper <<a href="mailto:craig.topper@gmail.com" target="_blank" class="">craig.topper@gmail.com</a>> wrote:</div>
<br class="">
<div class="">
<div dir="auto" class="">In tablegen you can write</div>
<div dir="auto" class=""><br class="">
</div>
<div dir="auto" class=""><span style="border-color:rgb(0,0,0) rgb(0,0,0) rgb(0,0,0) rgb(204,204,204)" class="">(set GPR:$rd, (add GPR:$rs1, R14))</span></div>
<div class=""><br class="">
<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" class="">llvm-dev@lists.llvm.org</a>> wrote:<br class="">
</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 class="">
<br class="">
I need to implement the following behavior for all instructions that <br class="">
require two source operands:<br class="">
<br class="">
%1 = add i16 %a, %b<br class="">
<br class="">
Should match the ADD instruction which has 1 outs and 1 ins. The second <br class="">
operand %b should be moved into the implicit register R14 (fixed).<br class="">
For now I implemented the PseudoADD instruction which gets expanded into <br class="">
a move plus the mentioned ADD instruction.<br class="">
This obviously creates a low of unnecessary moves and prevents any <br class="">
optimizations of the register R14 (e.g. R14 could be used as destination <br class="">
register in previous operations without the need for a move).<br class="">
<br class="">
I'd like to transform the dag:<br class="">
<br class="">
(set GPR:$rd, (add GPR:$rs1, GPR:$rs2))<br class="">
<br class="">
to something like:<br class="">
<br class="">
(set R14, GPR:$rs2), (set GPR:$rd, (add GPR:$rs1))<br class="">
<br class="">
Is it possible to specify this transformation using TableGen? If now how <br class="">
could I achieve this?<br class="">
<br class="">
<br class="">
Thanks.<br class="">
<br class="">
Best Regards,<br class="">
Marco Speziali<br class="">
<br class="">
_______________________________________________<br class="">
LLVM Developers mailing list<br class="">
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank" class="">llvm-dev@lists.llvm.org</a><br class="">
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank" class="">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br class="">
</blockquote>
</div>
</div>
-- <br class="">
<div dir="ltr" class="">~Craig</div>
</div>
</blockquote>
</div>
<br class="">
</div>
</div>
</blockquote>
</div>
</div>
</blockquote>
</div>
<br class="">
</div>
</div>
</div>
</blockquote>
</div>
<br class="">
</div>
</body>
</html>