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: Fri, 21 Aug 2015 10:38:51 +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> <CAFiYyc1xhkUsnmaGeLg-8iufxWpgXSjgP_izamcX0bvm9KRRNQ at mail dot gmail dot com> <SN2PR0701MB1024A460F6FA7BC0FB386A588E670 at SN2PR0701MB1024 dot namprd07 dot prod dot outlook dot com> <CAFiYyc0CZ1ECw0wysk1xHkNrOBUnYcC8P22=HJ-Qk+cx0aR95Q at mail dot gmail dot com> <SN2PR0701MB10247452B48809F7CC92DFD08E660 at SN2PR0701MB1024 dot namprd07 dot prod dot outlook dot com> <CAFiYyc2cvNAMJJ5CkqF-e8tTrF+cweFni6GR393DH_x4q6jToQ at mail dot gmail dot com> <SN2PR0701MB10245A87E9DE18E7EAECA0F98E660 at SN2PR0701MB1024 dot namprd07 dot prod dot outlook dot com> <CAFiYyc2LacyRUPFMO1PUurj82t1+Jcp5CeNmQdRDvn3A5zBZjA at mail dot gmail dot com>
On Thu, Aug 20, 2015 at 12:58 PM, Richard Biener
<richard.guenther@gmail.com> wrote:
> On Thu, Aug 20, 2015 at 11:18 AM, Hurugalawadi, Naveen
> <Naveen.Hurugalawadi@caviumnetworks.com> wrote:
>> Hi,
>>
>>>> Works for me if you specify -fno-math-errno. I think that's a
>>>> "regression" we can accept.
>>
>> Modified the pattern with "fno-math-errno" as a condition.
>>
>>>> Can you re-post with the typo fix and the missing :s?
>>
>> Please find attached the modified patch as per the review comments.
>> Please suggest if there should be any further modifications.
>
> You marked
>
> + /* Simplify x * pow(x,c) -> pow(x,c+1). */
> + (simplify
> + (mult @0 (POW:s @0 REAL_CST@1))
> + (if (!flag_errno_math
> + && !TREE_OVERFLOW (@1))
> + (POW @0 (plus @1 { build_one_cst (type); }))))
>
> with !flag_errno_math to avoid ICEs when replacing a non-call with a call.
> But ...
I have now committed a patch for PR67285 so your patch is ok now if
you remove that !flag_errno_math check above.
Thanks,
Richard.
> + /* Simplify sin(x) / cos(x) -> tan(x). */
> + (simplify
> + (rdiv (SIN:s @0) (COS:s @0))
> + (TAN @0))
>
> has exactly the same issue, so does the following (and maybe others)
>
> + /* Simplify cos(x) / sin(x) -> 1 / tan(x). */
> + (simplify
> + (rdiv (COS:s @0) (SIN:s @0))
> + (rdiv { build_one_cst (type); } (TAN @0)))
>
> so I presume those simply do not trigger late (on GIMPLE) for any existing
> testcases.
>
> So to not expose this (latent) issue please wait until I find the time to fix
> the underlying issue in a more generic way. I will have a look today.
>
> Thanks,
> Richard.
>
>> Thanks,
>> Naveen
>>
>> ChangeLog
>>
>> 2015-08-20 Naveen H.S <Naveen.Hurugalawadi@caviumnetworks.com>
>>
>> * fold-const.c (fold_binary_loc) : Move sqrt(x)*sqrt(x) as x
>> to match.pd.
>> Move Optimize pow(x,y)*pow(z,y) as pow(x*z,y)to match.pd.
>> 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 (SQRT@1 @0) @1) : New simplifier.
>> (mult (POW:s @0 @1) (POW:s @2 @1)) : New simplifier.
>> (mult:c (TAN:s @0) (COS:s @0)) : New simplifier.
>> (mult:c (TAN:s @0) (COS:s @0)) : New simplifier.
>> (rdiv (SIN:s @0) (COS:s @0)) : New simplifier.
>> (rdiv (COS:s @0) (SIN:s @0)) : New simplifier.
>> (rdiv (SIN:s @0) (TAN:s @0)) : New simplifier.
>> (rdiv (TAN:s @0) (SIN:s @0)) : New simplifier.
>> (rdiv (POW:s @0 REAL_CST@1) @0) : New simplifier.
>> (rdiv @0 (SQRT:s (rdiv:s @1 @2))) : New simplifier.
>> (rdiv @0 (POW:s @1 @2)) : New simplifier.