<div class="gmail_quote">On 22 June 2011 12:51, Xi Wang <span dir="ltr"><<a href="mailto:xi.wang@gmail.com">xi.wang@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

Sure.  I will submit a patch.<br>
<br>
BTW, what's the difference between the bounds I was expecting<br>
<div class="im"><br>
APInt NewLower = getLower() - Other.getUpper() + 1;<br>
APInt NewUpper = getUpper() - Other.getLower();<br>
<br>
</div>and the two you mentioned<br>
<div class="im"><br>
NewLower = Lower - (Upper-1)<br>
NewUpper = (Upper-1) - Lower + 1<br>
<br>
</div>They look equivalent to me.  Did I miss anything?  Thanks.<br></blockquote><div><br></div><div>... they are. Sorry, I was just surprised to see the +1 on the NewLower (it always goes on the NewUpper instead, right), but I didn't actually simplify the expressions.</div>

<div><br></div><div>It sounds to me like you've got this one handled. :-)</div><div><br></div><div>Nick</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">


<font color="#888888"><br>
- xi<br>
</font><div><div></div><div class="h5"><br>
On Jun 22, 2011, at 2:39 PM, Nick Lewycky wrote:<br>
<br>
> Thanks, I think you've found a serious bug!<br>
><br>
> Would you be willing to fix it? Please add a test to unittests/Support/ConstantRangeTest.cpp and then mail llvm-commits with the patch to fix it and add the test.<br>
><br>
> On 20 June 2011 23:09, Xi Wang <<a href="mailto:xi.wang@gmail.com">xi.wang@gmail.com</a>> wrote:<br>
> Hi,<br>
><br>
> I have a question about ConstantRange::sub(const ConstantRange &Other) at lib/Support/ConstantRange.cpp:524.  The code computes the new bounds as follows.<br>
><br>
>  APInt NewLower = getLower() - Other.getLower();<br>
>  APInt NewUpper = getUpper() - Other.getUpper() + 1;<br>
><br>
> Could someone explain this to me?  I was expecting something like<br>
><br>
>  APInt NewLower = getLower() - Other.getUpper() + 1;<br>
>  APInt NewUpper = getUpper() - Other.getLower();<br>
><br>
> These aren't quite right, I think it should be:<br>
><br>
> NewLower = Lower - (Upper-1)<br>
> NewUpper = (Upper-1) - Lower + 1<br>
><br>
> Constant ranges are stored half-open, [lower, upper) which means that the upper value is one past the end of the range. I often think of the formula as newmax = max - min --> newupper - 1 = ((getUpper() - 1) - Other.getLower(). min = lower, while max = upper - 1.<br>


><br>
> Nick<br>
<br>
</div></div></blockquote></div><br>