<div dir="ltr"><div>While SCEV provides a generic framework to calculate the loop exit values, may be what zet asking is just an instcomb that replace the loop exit value of zero by 0, when zero is initialized to 0 before the loop?<br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Mar 3, 2016 at 5:23 AM, Sanjoy Das <span dir="ltr"><<a href="mailto:sanjoy@playingwithpointers.com" target="_blank">sanjoy@playingwithpointers.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">[+CC Andy]<br>
<br>
A similar issue also comes up in cases like this:<br>
<br>
int clz(unsigned long val) {<br>
  unsigned result = sizeof(unsigned long);<br>
  if (val) {<br>
    do {<br>
      result--;<br>
      val >>= 1;<br>
    } while (val);<br>
  }<br>
  return result;<br>
}<br>
<br>
where we'd like to be able to compute the tripcount of the loop as<br>
"sizeof(long) - clz(val) - 1" and get rid of the loop entirely via<br>
RewriteLoopExitValues.<br>
<br>
The reason why the above issue is "similar" to wanting a "SCEVPowExpr"<br>
is that both are examples of SCEV node kinds that will be useful in<br>
some very specific cases; but probably is not seen widely enough that<br>
teaching whole of ScalarEvolution how to simplify these is a good<br>
idea.<br>
<br>
To get around this, I've been thinking (and only thinking, no code yet<br>
:) ) about adding a possible "SCEVIntrinsicExpr", parameterized by an<br>
"OpCode", like SCEVIntrinsicExpr::Pow or<br>
SCEVIntrinsicExpr::CountLeadingZeroes.  The idea is that these would<br>
be a low-overhead way of adding new kinds of expressions to the SCEV<br>
hierarchy, with the only constraints being:<br>
<br>
 - They're a pure, mathematically function of their input values<br>
 - SCEVExpander knows how to expand them<br>
 - It is always safe to treat them as SCEVUnknowns<br>
<span class="HOEnZb"><font color="#888888"><br>
-- Sanjoy<br>
</font></span></blockquote></div><br></div>