[PATCH] Optimize a >= 0 && a < b if VR info says b >= 0 (PR tree-optimization/77664)

Jakub Jelinek jakub@redhat.com
Thu Oct 6 22:01:00 GMT 2016


On Thu, Oct 06, 2016 at 11:55:00PM +0200, Marc Glisse wrote:
> On Thu, 6 Oct 2016, Jakub Jelinek wrote:
> 
> >For signed a, if we see a >= 0 && a < b and from VR know that b >= 0,
> >we can optimize those 2 comparisons into one unsigned -
> >(unsigned) a < (unsigned) b.  Similarly for a < 0 || a > b (and also
> >for a <= b in the first and a >= b in the second).
> 
> I guess that the slightly more general:
> X >= A && X < B where we know that A <= B
> --> (unsigned)X - (unsigned)A < (unsigned)B - (unsigned)A
> 
> generates too many operations and does not gain anything? 

Yeah, I think replacing 2 comparisons and one && with 2 subtractions and one
comparison isn't a clear win.
For constant A and B the reassoc optimize_range_tests of course handles it
for a long time already.

> The case where A
> and B are constants seems to be handled by ifcombine, currently.

	Jakub



More information about the Gcc-patches mailing list