This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Move X - (X / Y) * Y folding to match.pd
- From: Richard Biener <rguenther at suse dot de>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Cc: Marek Polacek <polacek at redhat dot com>
- Date: Tue, 30 Jun 2015 09:35:16 +0200 (CEST)
- Subject: Re: [PATCH] Move X - (X / Y) * Y folding to match.pd
- Authentication-results: sourceware.org; auth=none
- References: <20150626162940 dot GI10139 at redhat dot com> <alpine dot DEB dot 2 dot 20 dot 1506271524590 dot 1949 at laptop-mg dot saclay dot inria dot fr> <alpine dot LSU dot 2 dot 11 dot 1506290931290 dot 26650 at zhemvz dot fhfr dot qr> <20150629140133 dot GM10139 at redhat dot com> <alpine dot DEB dot 2 dot 20 dot 1506300015130 dot 18941 at laptop-mg dot saclay dot inria dot fr>
On Tue, 30 Jun 2015, Marc Glisse wrote:
> On Mon, 29 Jun 2015, Marek Polacek wrote:
>
> > On Mon, Jun 29, 2015 at 09:36:59AM +0200, Richard Biener wrote:
> > > > Anything wrong with this?
> > > >
> > > > +/* X - (X / Y) * Y is the same as X % Y. */
> > > > +(simplify
> > > > + (minus (convert? @0) (convert? (mult (trunc_div @0 @1) @1)))
> > > > + (if (INTEGRAL_TYPE_P (type) || VECTOR_INTEGER_TYPE_P (type))
> > > > + (convert (trunc_mod @0 @1))))
> >
> > That looks awfully similar to a variant I also tried (but I remember
> > having convert1? and convert2? in it). Not sure what was wrong with
> > that one; certainly yours seems to work fine.
>
> Afterwards I thought of a limitation. Nothing bad, but it highlights a trap I
> regularly fall into: several @0 in the same pattern may have different types
> (for INTEGER_CST, operand_equal_p mostly ignores the type). So for an int x,
> 42L-42/x*x should fail to match, while using convert1? and convert2? should
> match.
Indeed that's a subtle issue with using operand_equal_p for matching
operands. Note that 42L-42/x*x will appear as
42L-(long)(42/x*x) in the IL just in case that wasn't obvious.
Thus ok to adjust the pattern to convert1? / convert2? if you add such
a testcase (maybe also add the one that the variants you tried on
originally failed to match).
Richard.