<div dir="ltr">Thank you for the fast answer.<div class="gmail_extra"><br><div class="gmail_quote">On Tue, Aug 9, 2016 at 6:51 PM, Michael Zolotukhin <span dir="ltr"><<a href="mailto:mzolotukhin@apple.com" target="_blank">mzolotukhin@apple.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"><div style="word-wrap:break-word">Hi,<div><br><div><span class=""><blockquote type="cite"><div>On Aug 9, 2016, at 6:39 PM, Alexandre Isoard via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:</div><br><div><div dir="ltr">Hello,<div><br></div><div>I was doing some experiments with SCEV and especially the loop trip count.</div><div>Sorry for the dumb question, what is the easiest way to dump SCEV analysis results on a .bc file?</div></div></div></blockquote></span>opt -analyze -scalar-evolution < file.bc</div></div></div></blockquote><div>Perfect. Thank you.</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="word-wrap:break-word"><div><div><span class=""><blockquote type="cite"><div><div dir="ltr"><div><br></div><div>On a side note, I wanted to see if we could optimize this function:</div><div><br></div><div><div><font face="monospace, monospace">unsigned long kernel(long w, long h, long d) {</font></div><div><font face="monospace, monospace"><span style="white-space:pre-wrap">    </span>unsigned long count = 0;</font></div><div><font face="monospace, monospace"><span style="white-space:pre-wrap">  </span>for(int i = 0; i < w; ++i)</font></div><div><font face="monospace, monospace"><span style="white-space:pre-wrap">             </span>for(int j = i; j < h; ++j)</font></div><div><font face="monospace, monospace"><span style="white-space:pre-wrap">                     </span>for(int k = j; k < d; ++k)</font></div><div><font face="monospace, monospace"><span style="white-space:pre-wrap">                             </span>++count;</font></div><div><font face="monospace, monospace"><span style="white-space:pre-wrap">  </span>return count;</font></div><div><font face="monospace, monospace">}</font></div></div></div></div></blockquote><blockquote type="cite"><div><div dir="ltr"><div><div><br></div><div>into this (it might not take into account overflows, it was generated using the barvinok library):</div></div></div></div></blockquote></span>Looks like we can not, but I haven’t examined why. Overflows might indeed get into the way.</div></div></div></blockquote><div>Also I wrongfully used int as induction variables instead of long.</div><div>But even after this correction, playing with unsignedness does not improve the situation. (even with all signed or all unsigned)<br><br>However, I came to realise that the first code could be improved into:</div><div><br></div><div><div><font face="monospace, monospace">long kernel2(long w, long h, long d) {</font></div><div><font face="monospace, monospace"><span class="" style="white-space:pre">        </span>using std::min;</font></div><div><font face="monospace, monospace"><span class="" style="white-space:pre">     </span>long count = 0;</font></div><div><font face="monospace, monospace"><span class="" style="white-space:pre">     </span>for (long i = 0; i < min(min(w, h), d); ++i)</font></div><div><font face="monospace, monospace"><span class="" style="white-space:pre">             </span>for (long j = i; j < min(h, d); ++j)</font></div><div><font face="monospace, monospace"><span class="" style="white-space:pre">                     </span>for (long k = j; k < d; ++k)</font></div><div><font face="monospace, monospace"><span class="" style="white-space:pre">                             </span>++count;</font></div><div><font face="monospace, monospace"><span class="" style="white-space:pre">    </span>return count;</font></div><div><font face="monospace, monospace">}</font></div><br></div><div>That is, removing dead loop iterations. Do we perform this kind of transformation? (when we can compute SCEV)</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="word-wrap:break-word"><div><div><br></div><div>Michael</div><div><br><blockquote type="cite"><div dir="ltr"><div></div></div></blockquote><blockquote type="cite"><div><span class=""><div dir="ltr"><div><div><div><font face="monospace, monospace">unsigned long kernel2(long w, long h, long d) {</font></div><div><font face="monospace, monospace"><span style="white-space:pre-wrap">       </span>return</font></div><div><font face="monospace, monospace"><span style="white-space:pre-wrap">            </span>(-1 + w >= 0 && -1 - w + h >= 0 && -1 - h + d >= 0)</font></div><div><font face="monospace, monospace"><span style="white-space:pre-wrap">              </span>? (((((2 * w - 3 * w*w + w*w*w) + 3 * w * h + -3 * w * h*h) + ((3 * w - 3 * w*w) + 6 * w * h) * d))/6)</font></div><div><font face="monospace, monospace"><span style="white-space:pre-wrap">            </span>: (-1 + w >= 0 && -1 - w + d >= 0 && h - d >= 0)</font></div><div><font face="monospace, monospace"><span style="white-space:pre-wrap">         </span>? ((((2 * w - 3 * w*w + w*w*w) + (6 * w - 3 * w*w) * d + 3 * w * d*d))/6)</font></div><div><font face="monospace, monospace"><span style="white-space:pre-wrap">         </span>: (-1 + h >= 0 && w - h >= 0 && -1 - h + d >= 0)</font></div><div><font face="monospace, monospace"><span style="white-space:pre-wrap">         </span>? ((((2 * h - 2 * h*h*h) + (3 * h + 3 * h*h) * d))/6)</font></div><div><font face="monospace, monospace"><span style="white-space:pre-wrap">             </span>: (-1 + d >= 0 && h - d >= 0 && w - d >= 0)</font></div><div><font face="monospace, monospace"><span style="white-space:pre-wrap">              </span>? (((2 * d + 3 * d*d + d*d*d))/6)</font></div><div><font face="monospace, monospace"><span style="white-space:pre-wrap">         </span>: 0;</font></div><div><font face="monospace, monospace">}</font></div></div><div><br></div><div>I am not sure how advanced are SCEV-based trip counts.</div><div><br></div><div>Best regards.</div><div><br>-- </div><div data-smartmail="gmail_signature"><div dir="ltr"><b>Alexandre Isoard</b><br></div></div>
</div></div></span>
______________________________<wbr>_________________<br>LLVM Developers mailing list<br><a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br></div></blockquote></div><br></div></div></blockquote></div><br>Regards.<br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><b>Alexandre Isoard</b><br></div></div>
</div></div>