<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Oct 4, 2016 at 12:07 PM, Tim Northover <span dir="ltr"><<a href="mailto:t.p.northover@gmail.com" target="_blank">t.p.northover@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On 3 October 2016 at 17:16, Phil Tomson via llvm-dev<br>
<span class="gmail-"><<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br>
> As the comment says, I'm not sure what code should go into the case where<br>
> it's possibly a load.idx - Base and Offset are SDValues not SDNodes so I<br>
> don't see how I could modify the DAG here to eliminate the shl - any ideas?<br>
<br>
</span>The shift-handling code would go into a different complex pattern that<br>
only ever applied to the instruction variant that did the shift<br>
(SelectAddrShlImm in your case by the looks of it).<br></blockquote><div><br></div><div>Yeah, that's what I tried initially. But that pattern never even gets tested for that particular load. Some of that code is posted below in this thread,  but here i'll post the CheckComplexPattern from the TargetGenDAGISel.inc:<br><br>bool CheckComplexPattern(SDNode *Root, SDNode *Parent,<br>                         SDValue N, unsigned PatternNo,<br>         SmallVectorImpl<std::pair<SDValue, SDNode*> > &Result) override {<br>  unsigned NextRes = Result.size();<br>  switch (PatternNo) {<br>  default: llvm_unreachable("Invalid pattern # in table?");<br>  case 0:<br>    Result.resize(NextRes+3);<br>    return SelectAddrShlImm(Parent, N, Result[NextRes+0].first, Result[NextRes+1].first, Result[NextRes+2].first);<br>  case 1:<br>    Result.resize(NextRes+2);<br>    return SelectAddrRegReg(Parent, N, Result[NextRes+0].first, Result[NextRes+1].first);<br>  case 2:<br>    Result.resize(NextRes+2);<br>    return SelectAddrRegImm(Parent, N, Result[NextRes+0].first, Result[NextRes+1].first);<br>  case 3:<br>    Result.resize(NextRes+1);<br>    return SelectAddrImmLocal(Parent, N, Result[NextRes+0].first);<br>  case 4:<br>    Result.resize(NextRes+1);<br>    return SelectAddrRegAny(Parent, N, Result[NextRes+0].first);<br>  }<br>}<br><br> <br></div><div>Case 0 isn't even tried for this part of the DAG (PatternNo is 1 so it goes directly to case 1). Meaning that SelectAdrShlImm isn't called for it.<br><br></div><div>This is the relevant part of the DAG:<br><br>          0x2385990: i64 = Constant<3> [ID=2]<br><br>        0x2385dd0: i64 = shl 0x2385bb0, 0x2385990 [ORD=3] [ID=13]<br><br>      0x2385ee0: i64 = add 0x2386650, 0x2385dd0 [ORD=3] [ID=14]<br><br>      0x2385880: <multiple use><br>    0x2386540: i32,ch = load 0x2356e90, 0x2385ee0, 0x2385880<LD4[%arrayidx16(addrspace=4)](align=8)(tbaa=<0x2335188>)> [ORD=4] [ID=15]<br><br>  0x2386320: ch,glue = CopyToReg 0x2356e90, 0x2386210, 0x2386540 [ORD=6]<br><br>    0x2386210: <multiple use><br>    0x2386320: <multiple use><br>    0x2386320: <multiple use><br>  0x2386430: ch = RET 0x2386210, 0x2386320, 0x2386320:1 [ORD=6]<br><br><br>SelectAddrRegReg called: 0x2386540: i32,ch = load 0x2356e90, 0x2385ee0, 0x2385880<LD4[%arrayidx16(addrspace=4)](align=8)(tbaa=<0x2335188>)> [ORD=4] [ID=15]<br><br>SelectAddrRegRegCommon called:<br>  Morphed node: 0x2386540: i32,ch = LOADI32_RR 0x2386650, 0x2385dd0, 0x2356e90<Mem:LD4[%arrayidx16(addrspace=4)](align=8)(tbaa=<0x2335188>)> [ORD=4]<br><br><br></div><div>So it morphs it into a LOADI32_RR which isn't what I'd like it to do... I'm not sure what I'm missing - do I need to try to match a bigger piece of the DAG, or something? (which I tried to do earlier (see early part of the thread), but that didnt' work out for other reasons)<br></div><div><br></div><div>Phil<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
You don't need to actually change the DAG here, just set the Base and<br>
Offset parameters correctly (after checking the shift amount matches<br>
too!). The generic code will use those operands instead of the SHL in<br>
the selected instruction, and if the SHL ends up unused (often the<br>
case, but not always since a value can be used multiple times) it'll<br>
just be dropped for the final output.<br>
<span class="gmail-HOEnZb"><font color="#888888"><br>
Tim.<br>
</font></span></blockquote></div><br></div></div>