This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [ABSU_EXPR] Add some of the missing patterns in match,pd


On Fri, Jun 29, 2018 at 4:38 AM Kugan Vivekanandarajah
<kugan.vivekanandarajah@linaro.org> wrote:
>
> Hi Marc,
>
> Thanks for the review.
>
> On 28 June 2018 at 14:11, Marc Glisse <marc.glisse@inria.fr> wrote:
> > (why is there no mention of ABSU_EXPR in doc/* ?)
>
> I will fix this in a separate patch.
> >
> > --- a/gcc/match.pd
> > +++ b/gcc/match.pd
> > @@ -571,10 +571,12 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
> >     (copysigns (op @0) @1)
> >     (copysigns @0 @1))))
> >
> > -/* abs(x)*abs(x) -> x*x.  Should be valid for all types.  */
> > -(simplify
> > - (mult (abs@1 @0) @1)
> > - (mult @0 @0))
> > +/* abs(x)*abs(x) -> x*x.  Should be valid for all types.
> > +   also for absu(x)*absu(x) -> x*x.  */
> > +(for op (abs absu)
> > + (simplify
> > +  (mult (op@1 @0) @1)
> > +  (mult @0 @0)))
> >
> > 1) the types are wrong, it should be (convert (mult @0 @0)), or maybe
> > view_convert if vectors also use absu.
> > 2) this is only valid with -fwrapv (TYPE_OVERFLOW_WRAPS(TREE_TYPE(@0))),
> > otherwise you are possibly replacing a multiplication on unsigned with a
> > multiplication on signed that may overflow. So maybe it is actually supposed
> > to be
> > (mult (convert @0) (convert @0))
> Indeed, I missed it. I have changed it in the attached patch.
> >
> >  /* cos(copysign(x, y)) -> cos(x).  Similarly for cosh.  */
> >  (for coss (COS COSH)
> > @@ -1013,15 +1015,24 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
> >        && tree_nop_conversion_p (type, TREE_TYPE (@2)))
> >    (bit_xor (convert @1) (convert @2))))
> >
> > -(simplify
> > - (abs (abs@1 @0))
> > - @1)
> > -(simplify
> > - (abs (negate @0))
> > - (abs @0))
> > -(simplify
> > - (abs tree_expr_nonnegative_p@0)
> > - @0)
> > +/* Convert abs (abs (X)) into abs (X).
> > +   also absu (absu (X)) into absu (X).  */
> > +(for op (abs absu)
> > + (simplify
> > +  (op (op@1 @0))
> > +  @1))
> >
> > You cannot have (absu (absu @0)) since absu takes a signed integer and
> > returns an unsigned one. (absu (abs @0)) may indeed be equivalent to
> > (convert (abs @0)). Possibly (op (convert (absu @0))) could also be
> > simplified if convert is a NOP.
> >
> > +/* Convert abs[u] (-X) -> abs[u] (X).  */
> > +(for op (abs absu)
> > + (simplify
> > +  (op (negate @0))
> > +  (op @0)))
> > +
> > +/* Convert abs[u] (X)  where X is nonnegative -> (X).  */
> > +(for op (abs absu)
> > + (simplify
> > +  (op tree_expr_nonnegative_p@0)
> > +  @0))
> >
> > Missing convert again.
> >
> > Where are the testcases?
> I have fixed the above and added test-cases.
>
> >
> >> Bootstrap and regression testing on x86_64-linux-gnu. Is this OK if no
> >> regressions.
> >
> >
> > Does it mean you have run the tests or intend to run them in the future? It
> > is confusing.
> Sorry for not being clear.
>
> I have bootstrapped and regression tested with no new regression.
>
> Is this OK?

+/* Convert absu(x)*absu(x) -> x*x.  */
+(simplify
+ (mult (absu@1 @0) @1)
+ (mult (convert @0) (convert @0)))

(mult (convert@2 @0) @2)

+/* Convert abs (abs (X)) into abs (X).
+   also absu (absu (X)) into absu (X).  */
 (simplify
  (abs (abs@1 @0))
  @1)
+
+(simplify
+ (absu (nop_convert (absu@1 @0)))
+ @1)

please use

  (absu (convert@2 (absu@1 @0))
  (if (tree_nop_conversion_p (TREE_TYPE (@2), TREE_TYPE (@1)))
   @1))

as Marc said we can have (absu (abs @0))
which should be equivalent to (convert (abs @0))

Otherwise OK.

Richard.

> Thanks,
> Kugan
>
> >
> > --
> > Marc Glisse


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]