On Fri, Aug 7, 2015 at 10:43 AM, Hurugalawadi, Naveen
<naveen.hurugalaw...@caviumnetworks.com> wrote:
> Hi,
>
> Please find attached the patch "simplify-1.patch" that moves some
> "flag_unsafe_math_optimizations" from fold-const.c to simplify and match.
>
> However, I am facing some issues with cbrt, exp2, pow10 and exp10 functions.
>
> Please review the patch and let me know whether its the right way to
> implement them.
>
> Pointers on solving the unimplemented patterns issues will be very helpful.
>
> Regression tested on X86_64.
> gcc.dg/torture/builtin-power-1.c FAIL's due to unimplemented exp10 and pow10
> optimizations.
> AArch64 : Along with these cbrt and exp2 also has issues.

Apart from what Marc said I'd like to see the patch splitted up
somewhat.  So can you
split out the part that works well?

I don't see what issues you are facing (apart from FIXME aarch64 ICEs) with the
exp/log functions.  It seems that with

-             /* Optimize expN(x)*expN(y) as expN(x+y).  */
-             if (fcode0 == fcode1 && BUILTIN_EXPONENT_P (fcode0))
-               {
-                 tree expfn = TREE_OPERAND (CALL_EXPR_FN (arg0), 0);
-                 tree arg = fold_build2_loc (loc, PLUS_EXPR, type,
-                                         CALL_EXPR_ARG (arg0, 0),
-                                         CALL_EXPR_ARG (arg1, 0));
-                 return build_call_expr_loc (loc, expfn, 1, arg);

to

+/* Simplify expN(x) * expN(y) -> expN(x+y). */
+(for exps (EXP EXP2)
+/* FIXME : exp2 ICE's with AArch64.  */
+(simplify
+ (mult:c (exps @0) (exps @1))
+  (exps (plus @0 @1))))

you are missing EXP10 and POW10.

I agree with Marc that on most function calls you want to add :s
restrictions.  Thus

+/* Simplify cos(x) / sin(x) -> 1 / tan(x). */
+(simplify
+ (rdiv (COS @0) (SIN @0))
+  (rdiv { build_one_cst (type); } (TAN @0)))

becomes

+/* Simplify cos(x) / sin(x) -> 1 / tan(x). */
+(simplify
+ (rdiv (COS:s @0) (SIN:s @0))
+  (rdiv { build_one_cst (type); } (TAN @0)))

so that if either or both cos() or sin() results are needed elsewhere
the transform
is not done.  With the value-numbering plumbing I am currently doing it would
still do the transform if tan (@0) is computed elsewhere.

Thanks,
Richard.

> Thanks,
> Naveen

Reply via email to