<div class="gmail_quote">On 22 June 2011 14:09, 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;">

Here goes the patch along with a test for ConstantRange::sub.  Thanks.<br></blockquote><div><br></div><div>Thanks! Committed as r133648.</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;">


<br>
<br><br>
On Jun 22, 2011, at 3:57 PM, Nick Lewycky wrote:<br>
<br>
> On 22 June 2011 12:51, Xi Wang <<a href="mailto:xi.wang@gmail.com">xi.wang@gmail.com</a>> wrote:<br>
> Sure.  I will submit a patch.<br>
><br>
> BTW, what's the difference between the bounds I was expecting<br>
><br>
> APInt NewLower = getLower() - Other.getUpper() + 1;<br>
> APInt NewUpper = getUpper() - Other.getLower();<br>
><br>
> and the two you mentioned<br>
><br>
> NewLower = Lower - (Upper-1)<br>
> NewUpper = (Upper-1) - Lower + 1<br>
><br>
> They look equivalent to me.  Did I miss anything?  Thanks.<br>
><br>
> ... 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.<br>
><br>
> It sounds to me like you've got this one handled. :-)<br>
><br>
> Nick<br>
><br>
><br>
> - xi<br>
><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>
><br>
<br>
<br></blockquote></div><br>