<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">HI Martin,<div class=""><br class=""></div><div class="">Since your addresses are i32, I’d imagine that the ADD is i32 and therefore both its operands are also i32. Matching the i32 Offset operand with an i16 register is likely to lead to problems.</div><div class=""><br class=""></div><div class="">Essentially, you need to write code that matches:</div><div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>(add $base (sext (i16 $offset))</div><div class=""><br class=""></div><div class="">so something like:</div><div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre"> </span>if (Addr.getOpcode() == ISD::ADD) {</div><div class=""><span class="Apple-tab-span" style="white-space:pre">       </span>  if (isSextFromi16(Addr.getOperand(1)) {</div><div class=""><span class="Apple-tab-span" style="white-space:pre">    </span>    Base = Addr.getOperand(0);</div><div class=""><span class="Apple-tab-span" style="white-space:pre">  </span>    Offset = Addr.getOperand(1).getOperand(0);<span class="Apple-tab-span" style="white-space:pre">    </span>// unextended i16</div><div class=""><span class="Apple-tab-span" style="white-space:pre"> </span>    return true;</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>  }</div><div class=""><div class=""><span class="Apple-tab-span" style="white-space: pre;">  </span>  if (isSextFromi16(Addr.getOperand(0)) {</div><div class=""><span class="Apple-tab-span" style="white-space: pre;">  </span>    Base = Addr.getOperand(1);</div><div class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>    Offset = Addr.getOperand(0).getOperand(0);</div><div class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>    return true;</div><div class=""><span class="Apple-tab-span" style="white-space: pre;">      </span>  }</div></div><div class=""><span class="Apple-tab-span" style="white-space:pre">      </span>  return false;</div><div class=""><span class="Apple-tab-span" style="white-space:pre">      </span>}</div><div class=""><br class=""></div><div class="">You’ll need to write isSextFromi16 which could be as simple as checking that its parameter is ISD::SIGN_EXTEND whose operand is i16. You could extend it match other operands, such as:</div><div class="">- zext for which bit 15 of the operand is known to be 0 (use SelectionDAG::MaskedValueIsZero)</div><div class="">- sextload of an i16 (if your target supports it)</div><div class="">- any i32 operand for which bits 15-31 are the same (use SelectionDAG::ComputeNumSignBits)</div><div class=""><br class=""></div><div class="">In the last two cases you’d need to turn the sextload into an i16 load and truncate the i32 respectively so that they are i16 operands but I think that’s possible during instruction selection.</div><div class=""><br class=""></div><div class="">Hope that helps.</div><div class=""><br class=""></div><div class="">Steve</div><div class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On 2 Nov 2015, at 21:16, Martin J. O'Riordan <<a href="mailto:martin.oriordan@movidius.com" class="">martin.oriordan@movidius.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="WordSection1" style="page: WordSection1; font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;" class=""><span style="font-family: 'Book Antiqua', serif; color: rgb(148, 54, 52);" class="">Thanks again for your help Steve,<o:p class=""></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;" class=""><span style="font-family: 'Book Antiqua', serif; color: rgb(148, 54, 52);" class=""><o:p class=""> </o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;" class=""><span style="font-family: 'Book Antiqua', serif; color: rgb(148, 54, 52);" class="">I’m thinking perhaps my “</span><span style="font-family: 'Courier New';" class="">SelectADDRrr</span><span style="font-family: 'Book Antiqua', serif; color: rgb(148, 54, 52);" class="">” 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 class=""></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt 36pt; font-size: 12pt; font-family: 'Times New Roman', serif;" class=""><span style="font-family: 'Courier New';" class=""><o:p class=""> </o:p></span></div><div style="margin: 0cm 0cm 0.0001pt 36pt; font-size: 12pt; font-family: 'Times New Roman', serif;" class=""><span style="font-family: 'Courier New';" class="">bool SHAVEISelDAGtoDAG::SelectADDRrr(SDValue &Addr, SDValue &Base, SDValue &Offset) {<o:p class=""></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt 36pt; font-size: 12pt; font-family: 'Times New Roman', serif;" class=""><span style="font-family: 'Courier New';" class="">  if ((Addr.getOpcode() == ISD::ADD) {<o:p class=""></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt 36pt; font-size: 12pt; font-family: 'Times New Roman', serif;" class=""><span style="font-family: 'Courier New';" class="">    Base = Addr.getOperand(0);<o:p class=""></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt 36pt; font-size: 12pt; font-family: 'Times New Roman', serif;" class=""><span style="font-family: 'Courier New';" class="">    Offset = Addr.getOperand(1);<o:p class=""></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt 36pt; font-size: 12pt; font-family: 'Times New Roman', serif;" class=""><span style="font-family: 'Courier New';" class="">    return true;<o:p class=""></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt 36pt; font-size: 12pt; font-family: 'Times New Roman', serif;" class=""><span style="font-family: 'Courier New';" class="">  }<o:p class=""></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt 36pt; font-size: 12pt; font-family: 'Times New Roman', serif;" class=""><span style="font-family: 'Courier New';" class=""><o:p class=""> </o:p></span></div><div style="margin: 0cm 0cm 0.0001pt 36pt; font-size: 12pt; font-family: 'Times New Roman', serif;" class=""><span style="font-family: 'Courier New';" class="">  return false;<o:p class=""></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt 36pt; font-size: 12pt; font-family: 'Times New Roman', serif;" class=""><span style="font-family: 'Courier New';" class="">}<o:p class=""></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;" class=""><span style="font-family: 'Book Antiqua', serif; color: rgb(148, 54, 52);" class=""><o:p class=""> </o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;" class=""><span style="font-family: 'Book Antiqua', serif; color: rgb(148, 54, 52);" class="">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 class="Apple-converted-space"> </span></span><span style="font-family: 'Courier New';" class="">DEBUG</span><span style="font-family: 'Book Antiqua', serif; color: rgb(148, 54, 52);" class=""><span class="Apple-converted-space"> </span>dumps should show me the error of my ways<span class="Apple-converted-space"> </span></span><span style="font-family: Wingdings; color: rgb(148, 54, 52);" class="">J</span><span style="font-family: 'Book Antiqua', serif; color: rgb(148, 54, 52);" class="">  I’m guessing that I need to check that the offset operand is truly a 16-bit register and return<span class="Apple-converted-space"> </span></span><span style="font-family: 'Courier New';" class="">false</span><span style="font-family: 'Book Antiqua', serif;" class=""><span class="Apple-converted-space"> </span></span><span style="font-family: 'Book Antiqua', serif; color: rgb(148, 54, 52);" class="">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 class=""></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;" class=""><span style="font-family: 'Book Antiqua', serif; color: rgb(148, 54, 52);" class=""><o:p class=""> </o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;" class=""><span style="font-family: 'Book Antiqua', serif; color: rgb(148, 54, 52);" class="">            MartinO<o:p class=""></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;" class=""><span style="font-family: 'Book Antiqua', serif; color: rgb(148, 54, 52);" class=""><o:p class=""> </o:p></span></div><div class=""><div style="border-style: solid none none; border-top-color: rgb(225, 225, 225); border-top-width: 1pt; padding: 3pt 0cm 0cm;" class=""><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;" class=""><b class=""><span lang="EN-US" style="font-size: 11pt; font-family: Calibri, sans-serif;" class="">From:</span></b><span lang="EN-US" style="font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span class="Apple-converted-space"> </span>Steve Montgomery [<a href="mailto:stephen.montgomery3@btinternet.com" class="">mailto:stephen.montgomery3@btinternet.com</a>]<span class="Apple-converted-space"> </span><br class=""><b class="">Sent:</b><span class="Apple-converted-space"> </span>02 November 2015 20:25<br class=""><b class="">To:</b><span class="Apple-converted-space"> </span>Martin J. O'Riordan <<a href="mailto:martin.oriordan@movidius.com" class="">martin.oriordan@movidius.com</a>><br class=""><b class="">Cc:</b><span class="Apple-converted-space"> </span>LLVM Developers <<a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a>><br class=""><b class="">Subject:</b><span class="Apple-converted-space"> </span>Re: [llvm-dev] Questions about load/store incrementing address modes<o:p class=""></o:p></span></div></div></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;" class=""><o:p class=""> </o:p></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;" class=""><o:p class=""> </o:p></div><div class=""><blockquote style="margin-top: 5pt; margin-bottom: 5pt;" class="" type="cite"><div class=""><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;" class="">On 2 Nov 2015, at 10:27, Martin J. O'Riordan <<a href="mailto:martin.oriordan@movidius.com" style="color: purple; text-decoration: underline;" class="">martin.oriordan@movidius.com</a>> wrote:<o:p class=""></o:p></div></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;" class=""><o:p class=""> </o:p></div><div class=""><div class=""><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;" class=""><span style="font-family: 'Book Antiqua', serif; color: rgb(31, 73, 125);" class="">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 class=""></o:p></div></div></div></blockquote><div class=""><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;" class=""><o:p class=""> </o:p></div></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;" class="">I’m basing my statement on the material at the end of the “Selection DAG Select Phase” in “The LLVM Target-Independent Code Generator”,<span class="Apple-converted-space"> </span><a href="http://llvm.org/docs/CodeGenerator.html#selectiondag-select-phase" style="color: purple; text-decoration: underline;" class="">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 class=""></o:p></div></div><div class=""><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;" class=""><span style="font-family: 'Book Antiqua', serif; color: rgb(31, 73, 125);" class=""> </span><br class=""><br class=""><o:p class=""></o:p></div><blockquote style="margin-top: 5pt; margin-bottom: 5pt;" class="" type="cite"><div class=""><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;" class=""><span style="font-family: 'Book Antiqua', serif; color: rgb(31, 73, 125);" class="">Curiously, my memory Reg32+Reg16 pattern is very similar to yours (the 16-bit offset is sign-extended though):</span><o:p class=""></o:p></div></div><div class=""><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;" class=""><span style="font-family: 'Book Antiqua', serif; color: rgb(31, 73, 125);" class=""> </span><o:p class=""></o:p></div></div><div style="margin-left: 36pt;" class=""><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;" class=""><span style="font-family: 'Courier New';" class="">// Memory address: 32-bit base register + 16-bit offset register</span><o:p class=""></o:p></div></div><div style="margin-left: 36pt;" class=""><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;" class=""><span style="font-family: 'Courier New';" class="">def ADDRrr : ComplexPattern<iPTR, 2, "SelectADDRrr", []>;</span><o:p class=""></o:p></div></div><div style="margin-left: 36pt;" class=""><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;" class=""><span style="font-family: 'Courier New';" class="">def MEMrr : Operand<iPTR> {</span><o:p class=""></o:p></div></div><div style="margin-left: 36pt;" class=""><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;" class=""><span style="font-family: 'Courier New';" class="">  let PrintMethod = "printMemOffsetOperand";</span><o:p class=""></o:p></div></div><div style="margin-left: 36pt;" class=""><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;" class=""><span style="font-family: 'Courier New';" class="">  let MIOperandInfo = (ops RC32, RC16_l);</span><o:p class=""></o:p></div></div><div style="margin-left: 36pt;" class=""><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;" class=""><span style="font-family: 'Courier New';" class="">}</span><o:p class=""></o:p></div></div><div class=""><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;" class=""><span style="font-family: 'Book Antiqua', serif; color: rgb(31, 73, 125);" class=""> </span><o:p class=""></o:p></div></div><div class=""><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;" class=""><span style="font-family: 'Book Antiqua', serif; color: rgb(31, 73, 125);" class="">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 class=""></o:p></div></div></blockquote><div class=""><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;" class=""><o:p class=""> </o:p></div></div></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;" class="">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 class=""></o:p></div><div class=""><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;" class=""><o:p class=""> </o:p></div></div><div class=""><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;" class="">Steve</div></div></div></div></blockquote></div><br class=""></div></body></html>