This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Transform (x / y) != 0 to x >=y and (x / y) == 0 to x < y if x, y are unsigned
- From: Jeff Law <law at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org, Marc Glisse <marc dot glisse at inria dot fr>, Prathamesh Kulkarni <prathamesh dot kulkarni at linaro dot org>
- Cc: Richard Biener <rguenther at suse dot de>
- Date: Fri, 15 Sep 2017 09:10:33 -0600
- Subject: Re: Transform (x / y) != 0 to x >=y and (x / y) == 0 to x < y if x, y are unsigned
- Authentication-results: sourceware.org; auth=none
- Authentication-results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com
- Authentication-results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=law at redhat dot com
- Dmarc-filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 44E3D8046E
- References: <CAAgBjMk7p7xR2Zk4uqWhyoXsAzehN+vo53yUoNb2RiXdxxs5MQ@mail.gmail.com> <alpine.DEB.2.20.1709151458100.3518@stedding.saclay.inria.fr>
On 09/15/2017 07:09 AM, Marc Glisse wrote:
> On Fri, 15 Sep 2017, Prathamesh Kulkarni wrote:
>
> +/* (X / Y) == 0 -> X < Y if X, Y are unsigned. */
> +(simplify
> + (eq (trunc_div @0 @1) integer_zerop)
> + (if (TYPE_UNSIGNED (TREE_TYPE(@0)) && TYPE_UNSIGNED (TREE_TYPE (@1)))
> + (lt @0 @1)))
> +
> +/* (X / Y) != 0 -> X >= Y, if X, Y are unsigned. */
> +(simplify
> + (ne (trunc_div @0 @1) integer_zerop)
> + (if (TYPE_UNSIGNED (TREE_TYPE(@0)) && TYPE_UNSIGNED (TREE_TYPE (@1)))
> + (ge @0 @1)))
> +
>
> Hello,
>
> you can merge the 2 transforms using "for". Also, no need to test the
> type of @1 since you are already testing @0.
Right.
>
> - do we want a single_use restriction on the result of the division?
I think so. If x/y is a common subexpression, then ideally we'd compute
it once.
> - do we also want to handle (x>>4)==0?
I think so, but that can be a follow-up IMHO.
> - do we also want a special case when X is 1 that produces Y==1, as
> asked in a recent PR?
Seems like a reasonable follow-up as well.
The other follow-up to consider is detecting these cases in VRP to
produce suitable ASSERT_EXPRs and ranges.
> - once in a while, someone mentions that eq, on vectors, can either do
> elementwise comparison and return a vector, or return a single boolean,
> which would fail here. However, I don't remember ever seeing an example.
We could always restrict to the integral types. Probably wise to
explicitly do that anyway.
jeff