This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Move some flag_unsafe_math_optimizations using simplify and match
- From: Richard Biener <richard dot guenther at gmail dot com>
- To: "Hurugalawadi, Naveen" <Naveen dot Hurugalawadi at caviumnetworks dot com>
- Cc: "gcc-patches at gcc dot gnu dot org" <gcc-patches at gcc dot gnu dot org>, "marc dot glisse at inria dot fr" <marc dot glisse at inria dot fr>
- Date: Tue, 18 Aug 2015 12:24:34 +0200
- Subject: Re: Move some flag_unsafe_math_optimizations using simplify and match
- Authentication-results: sourceware.org; auth=none
- References: <SN2PR0701MB1024EC4AD2C9B654AE3F0E9A8E790 at SN2PR0701MB1024 dot namprd07 dot prod dot outlook dot com>
On Mon, Aug 17, 2015 at 7:24 AM, Hurugalawadi, Naveen
<Naveen.Hurugalawadi@caviumnetworks.com> wrote:
> Hi,
>
> Please find attached the modified patch as per the comments.
>
> Tested the patch on AArch64 and X86 without any regressions.
>
> The other hunks of the earlier patch have been removed as per the earlier
> comments due to failure in regressions.
> Investigated those issues and found that its because of Double and Float
> patterns.
> Could not deduce why the double and float patterns FAIL though.
>
>>> fold_builtin_cos/cosh can be reduced to constant folding, thus
>>> remove their fold_strip_sign_nops () path.
> Had removed them but the double and float patterns does not generate the
> optimizations and hence had to retain them
>
> Please let me know why the double and float patterns are failing.
> I could work on those and try to move all other patterns using
> "simplify and match".
Can you point me to which patterns exhibit this behavior? I guess
you mean 'long double' and 'float' variants, not 'double' variants?
> The testcase for these pattern optimizations are present.
> Please let me know whether we would need a separate check so that I
> can add them.
In your new patch I see
+ /* Simplify sqrt(x) * sqrt(x) -> x. */
+ (simplify
+ (mult:c (SQRT (SQRT@1 @0)) @1)
+ (if (!HONOR_SNANS (type))
+ @0))
which looks like a typo - it matches (sqrt (sqrt (x)) * sqrt (x). You want
(mult (SQRT@1 @0) @1)
also note there is no need for the :c here.
For cases like
+ /* Simplify tan(x) * cos(x) -> sin(x). */
+ (simplify
+ (mult:c (TAN:s @0) (COS:s @0))
+ (SIN @0))
you can run into the issue that the program does not use sinf() and thus
the compiler refuses to generate it (but the fold-const.c has the same issue,
so it shouldn't regress). Not sure if that is your issue with long
double / float
variants.
+ /* Simplify pow(x,c) / x -> pow(x,c-1). */
+ (simplify
+ (rdiv (POW @0 @1) @0)
:s missing on the POW
+ (if (TREE_CODE (@1) == REAL_CST
+ && !TREE_OVERFLOW (@1))
+ (POW @0 (minus @1 { build_one_cst (type); }))))
please use
(simplify
(rdiv (POW @0 REAL_CST@1) @0)
(if (!TREE_OVERFLOW (@1))
...
here and in other cases where you restrict one operand to a constant.
That results in more efficient code.
+ /* Simplify a/root(b/c) into a*root(c/b). */
+ (simplify
+ (rdiv @0 (SQRT (rdiv @1 @2)))
:s missing on the SQRT and the rdiv
+ (mult @0 (SQRT (rdiv @2 @1))))
+ /* Simplify x / pow (y,z) -> x * pow(y,-z). */
+ (simplify
+ (rdiv @0 (POW @1 @2))
:s missing on the POW.
+ (mult @0 (POW @1 (negate @2))))
Otherwise the new patch looks ok to me.
Thanks,
Richard.
> Thanks,
> Naveen
>
> ChangeLog
>
> 2015-08-17 Naveen H.S <Naveen.Hurugalawadi@caviumnetworks.com>
>
> PR middle-end/16107
> * fold-const.c (fold_binary_loc) : Move Optimize tan(x)*cos(x) as
> sin(x) to match.pd.
> Move Optimize x*pow(x,c) as pow(x,c+1) to match.pd.
> Move Optimize pow(x,c)*x as pow(x,c+1) to match.pd.
> Move Optimize sin(x)/cos(x) as tan(x) to match.pd.
> Move Optimize cos(x)/sin(x) as 1.0/tan(x) to match.pd.
> Move Optimize sin(x)/tan(x) as cos(x) to match.pd.
> Move Optimize tan(x)/sin(x) as 1.0/cos(x) to match.pd.
> Move Optimize pow(x,c)/x as pow(x,c-1) to match.pd.
> Move Optimize x/pow(y,z) into x*pow(y,-z) to match.pd.
> * match.pd (SIN ) : New Operator.
> (TAN) : New Operator.
> (mult:c (SQRT (SQRT@1 @0)) @1) : New simplifier.
> (mult (POW:s @0 @1) (POW:s @2 @1))
> (mult:c (TAN:s @0) (COS:s @0))
> (mult:c @0 (POW @0 @1))
> (rdiv (SIN:s @0) (COS:s @0))
> (rdiv (COS:s @0) (SIN:s @0))
> (rdiv (SIN:s @0) (TAN:s @0))
> (rdiv (TAN:s @0) (SIN:s @0))
> (rdiv (POW @0 @1) @0)
> (rdiv @0 (SQRT (rdiv @1 @2)))
> (rdiv @0 (POW @1 @2))