On Tue, Sep 18, 2012 at 10:59 PM, Andrew Trick <span dir="ltr"><<a href="mailto:atrick@apple.com" target="_blank">atrick@apple.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="word-wrap:break-word"><br><div><div><div class="h5"><div>On Sep 18, 2012, at 8:21 PM, Preston Briggs <<a href="mailto:preston.briggs@gmail.com" target="_blank">preston.briggs@gmail.com</a>> wrote:</div><br>
<blockquote type="cite">Given the following SCEV,<div><br></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div><font face="courier new, monospace"><b>(sext i32 {2,+,1}<nw><%for.body> to i64)</b></font></div>

</blockquote><div><br></div><div>from the following C source,</div><div><br></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div><div><font face="courier new, monospace"><b>void strong3(int *A, int *B, int n) {</b></font></div>

</div><div><font face="courier new, monospace"><b>  for (int i = 0; i < n; i++) {</b></font></div><div><font face="courier new, monospace"><b>    A[i + 2] = i;</b></font></div><div><div><font face="courier new, monospace"><b>    ...</b></font></div>

</div><div><font face="courier new, monospace"><b>  }</b></font></div><div><font face="courier new, monospace"><b>}</b></font></div></blockquote><div><br></div><div>Since the No-Wrap flag is set on the addrec, can't I safely rewrite it as</div>

<div><br></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><font face="courier new, monospace"><b>{2,+,1}<nw><%for.body></b></font></blockquote><div><br></div><div>If I can, why isn't the SCEV package simplifying things for me?</div>

</blockquote><div><br></div></div></div><div>The short answer is that SCEV is terrible at preserving NSW flags. I personally don't believe they belong in SCEV but the merits of making any design change here are dubious.</div>
<div><br></div><div>To understand one example of SCEV dropping NSW, see createSCEV for Instruction::Add. Synopsis: your add is not a "basic induction variable" so its NSW flag does not bound the number of loop iterations. We only know that the add's original IR users expect NSW. There could be other IR adds with the same expression, but without the NSW flag. SCEV doesn't know anything about acyclic control flow or IR users, so it must drop the flags.</div>
<div><br></div><div>I would try hard not to rely on NSW flags on arbitrary SCEVs. I would first find the phi or basic induction variable before checking the recurrence's NSW flag. Or, better yet, only rely on SCEVAddRec's NW (no self-wrap flag) rather than NSW. Notice that the NW is preserved in your add's recurrence!</div>
<div><br></div><div>-Andy</div></div><br></div></blockquote></div><br><div>OK.  I think...</div><div>Basically, I'm trying to understand how two subscripts relate to one another. When I find sign and zero extensions, life gets confusing. In an effort to keep life simple, I begin by walking though the expressions, trying to eliminate extensions where it won't change the answer. For example, I think</div>
<blockquote type="cite"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px">
</blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><font face="courier new, monospace"><b>(sext i32 {2,+,1}<nw><%for.body> to i64)<br></b></font></blockquote></blockquote><div>is the same as</div>
<div><blockquote type="cite"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><font face="courier new, monospace"><b>{2,+,1}<nw><%for.body></b></font></blockquote></blockquote></div><div>right?</div>
<div><br></div><div>Mechanically, when I see an sext over an addrec and the addrec has the NW flag, then I can rewrite is as an addrec<nw> with the base and step extended. In this case, the base and step are constants, which are particularly easy.</div>
<div><br></div><div>On the other hand, if the addrec is missing the NW flag, I'd be making a mistake.</div><div><br></div><div>In a similar vein, it seems plausible that I can rewrite a sign-extend over an add (or multiply), as long as the add (multiply) has the NSW flag, right? Same for zero-extend, over add with NUW flag.</div>
<div><br></div><div>Thanks,</div><div>Preston</div><div><br></div>