<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=utf-8"><meta name=Generator content="Microsoft Word 15 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:Wingdings;
        panose-1:5 0 0 0 0 0 0 0 0 0;}
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:"Book Antiqua";
        panose-1:2 4 6 2 5 3 5 3 3 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman",serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-reply;
        font-family:"Book Antiqua",serif;
        color:#943634;
        font-weight:normal;
        font-style:normal;
        text-decoration:none none;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-IE link=blue vlink=purple><div class=WordSection1><p class=MsoNormal><span style='font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US'>Thanks again for your help Steve,<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US'>I’m thinking perhaps my “</span><span style='font-family:"Courier New";color:black;mso-fareast-language:EN-US'>SelectADDRrr</span><span style='font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US'>” pattern is inadequate.  The sign-extension is at the hardware level, the code generator sees (should see) it as a 16-bit signed register value.  My implementation is just:<o:p></o:p></span></p><p class=MsoNormal style='margin-left:36.0pt'><span style='font-family:"Courier New";color:black;mso-fareast-language:EN-US'><o:p> </o:p></span></p><p class=MsoNormal style='margin-left:36.0pt'><span style='font-family:"Courier New";color:black;mso-fareast-language:EN-US'>bool SHAVEISelDAGtoDAG::SelectADDRrr(SDValue &Addr, SDValue &Base, SDValue &Offset) {<o:p></o:p></span></p><p class=MsoNormal style='margin-left:36.0pt'><span style='font-family:"Courier New";color:black;mso-fareast-language:EN-US'>  if ((Addr.getOpcode() == ISD::ADD) {<o:p></o:p></span></p><p class=MsoNormal style='margin-left:36.0pt'><span style='font-family:"Courier New";color:black;mso-fareast-language:EN-US'>    Base = Addr.getOperand(0);<o:p></o:p></span></p><p class=MsoNormal style='margin-left:36.0pt'><span style='font-family:"Courier New";color:black;mso-fareast-language:EN-US'>    Offset = Addr.getOperand(1);<o:p></o:p></span></p><p class=MsoNormal style='margin-left:36.0pt'><span style='font-family:"Courier New";color:black;mso-fareast-language:EN-US'>    return true;<o:p></o:p></span></p><p class=MsoNormal style='margin-left:36.0pt'><span style='font-family:"Courier New";color:black;mso-fareast-language:EN-US'>  }<o:p></o:p></span></p><p class=MsoNormal style='margin-left:36.0pt'><span style='font-family:"Courier New";color:black;mso-fareast-language:EN-US'><o:p> </o:p></span></p><p class=MsoNormal style='margin-left:36.0pt'><span style='font-family:"Courier New";color:black;mso-fareast-language:EN-US'>  return false;<o:p></o:p></span></p><p class=MsoNormal style='margin-left:36.0pt'><span style='font-family:"Courier New";color:black;mso-fareast-language:EN-US'>}<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US'>I don’t have any special checks on the offset (or the base for that matter) on the naive assumption that it would not have been invoked if the constraints were not already met.  But don’t worry about it, you’ve given me a fresh avenue to investigate - a few </span><span style='font-family:"Courier New";color:black;mso-fareast-language:EN-US'>DEBUG</span><span style='font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US'> dumps should show me the error of my ways </span><span style='font-family:Wingdings;color:#943634;mso-fareast-language:EN-US'>J</span><span style='font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US'>  I’m guessing that I need to check that the offset operand is truly a 16-bit register and return </span><span style='font-family:"Courier New";color:black;mso-fareast-language:EN-US'>false</span><span style='font-family:"Book Antiqua",serif;color:black;mso-fareast-language:EN-US'> </span><span style='font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US'>if it isn’t.  A nice simple fix if that is all that is needed - thanks again for shedding light on this for me.<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US'>            MartinO<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US'><o:p> </o:p></span></p><div><div style='border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0cm 0cm 0cm'><p class=MsoNormal><b><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri",sans-serif'>From:</span></b><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri",sans-serif'> Steve Montgomery [mailto:stephen.montgomery3@btinternet.com] <br><b>Sent:</b> 02 November 2015 20:25<br><b>To:</b> Martin J. O'Riordan <martin.oriordan@movidius.com><br><b>Cc:</b> LLVM Developers <llvm-dev@lists.llvm.org><br><b>Subject:</b> Re: [llvm-dev] Questions about load/store incrementing address modes<o:p></o:p></span></p></div></div><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><o:p> </o:p></p><div><blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'><div><p class=MsoNormal>On 2 Nov 2015, at 10:27, Martin J. O'Riordan <<a href="mailto:martin.oriordan@movidius.com">martin.oriordan@movidius.com</a>> wrote:<o:p></o:p></p></div><p class=MsoNormal><o:p> </o:p></p><div><div><p class=MsoNormal><span style='font-family:"Book Antiqua",serif;color:#1F497D'>Thanks Steve, I will try this out.  I hadn’t realised that TableGen was restricted to matching instructions with more than one output operand.  I’m assuming that this is only a limitation for inferring an instruction from the patterns, because it does seem to manage schedules okay.</span><o:p></o:p></p></div></div></blockquote><div><p class=MsoNormal><o:p> </o:p></p></div><p class=MsoNormal>I’m basing my statement on the material at the end of the “Selection DAG Select Phase” in “The LLVM Target-Independent Code Generator”, <a href="http://llvm.org/docs/CodeGenerator.html#selectiondag-select-phase">http://llvm.org/docs/CodeGenerator.html#selectiondag-select-phase</a>. I’ve not actually checked TableGen though so can’t be 100% sure that the documentation is still in date.<o:p></o:p></p></div><div><p class=MsoNormal><span style='font-family:"Book Antiqua",serif;color:#1F497D'> </span><br><br><o:p></o:p></p><blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'><div><p class=MsoNormal><span style='font-family:"Book Antiqua",serif;color:#1F497D'>Curiously, my memory Reg32+Reg16 pattern is very similar to yours (the 16-bit offset is sign-extended though):</span><o:p></o:p></p></div><div><p class=MsoNormal><span style='font-family:"Book Antiqua",serif;color:#1F497D'> </span><o:p></o:p></p></div><div style='margin-left:36.0pt'><p class=MsoNormal><span style='font-family:"Courier New"'>// Memory address: 32-bit base register + 16-bit offset register</span><o:p></o:p></p></div><div style='margin-left:36.0pt'><p class=MsoNormal><span style='font-family:"Courier New"'>def ADDRrr : ComplexPattern<iPTR, 2, "SelectADDRrr", []>;</span><o:p></o:p></p></div><div style='margin-left:36.0pt'><p class=MsoNormal><span style='font-family:"Courier New"'>def MEMrr : Operand<iPTR> {</span><o:p></o:p></p></div><div style='margin-left:36.0pt'><p class=MsoNormal><span style='font-family:"Courier New"'>  let PrintMethod = "printMemOffsetOperand";</span><o:p></o:p></p></div><div style='margin-left:36.0pt'><p class=MsoNormal><span style='font-family:"Courier New"'>  let MIOperandInfo = (ops RC32, RC16_l);</span><o:p></o:p></p></div><div style='margin-left:36.0pt'><p class=MsoNormal><span style='font-family:"Courier New"'>}</span><o:p></o:p></p></div><div><p class=MsoNormal><span style='font-family:"Book Antiqua",serif;color:#1F497D'> </span><o:p></o:p></p></div><div><p class=MsoNormal><span style='font-family:"Book Antiqua",serif;color:#1F497D'>but it is still happy to select for offset’s > 16-bits.  There is something I am just not yet getting right, but it looks like I am on the right track.</span><o:p></o:p></p></div></blockquote><div><p class=MsoNormal><o:p> </o:p></p></div></div><p class=MsoNormal>I believe that the MIOperandInfo will constrain the register class for your 16-bit offset operand to RC16_1 but in itself it won’t affect the matching of the operand. Your SelectADDRrr will need to contain code to match an i32 added to a sign-extended i16. If you’ve already done that, then I’m out of ideas, sorry.<o:p></o:p></p><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>Steve<o:p></o:p></p></div></div></body></html>