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: Thu, 20 Aug 2015 10:16:05 +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>
On Thu, Aug 20, 2015 at 6:48 AM, Hurugalawadi, Naveen
<Naveen.Hurugalawadi@caviumnetworks.com> wrote:
> Hi,
>
> Thanks again for your review and useful comments.
>
>>> I see. But I can't really help without a testcase that I can use to have a look
>>> (same for the above issue with the segfaults).
>
> The following testcase does not generate "x" as needed.
> ====================
> double t (double x)
> {
> x = sqrt (x) * sqrt (x);
> return x;
> }
Works for me if you specify -fno-math-errno. I think that's a
"regression" we can accept.
Later on GIMPLE CSE fails to CSE the two calls (because of the unknown
side-effects,
special-casing of (some) builtins would be necessary).
> ====================
>
> All of the following operation results in segfault with:-
> aarch64-thunder-elf-gcc simlify-2.c -O2 -funsafe-math-optimizations
> ===============================================
> #include <math.h>
>
> double t (double x, double y, double z)
> {
> x = cbrt (x) * cbrt (y);
> x = exp10 (x) * exp10 (y);
> x = pow10 (x) * pow10 (y);
> x = x / cbrt (x/y)
> x = x / exp10 (y);
> x = x / pow10 (y);
> return x;
> }
>
> float t (float x, float y, float z)
> {
> x = sqrtf (x) * sqrtf (y);
> x = expf (x) * expf (y);
> x = powf (x, y) * powf (x, z);
> x = x / expf (y);
> return x;
> }
>
> long double t1 (long double x, long double y, long double z)
> {
> x = sqrtl (x) * sqrtl (y);
> x = expl (x) * expl (y);
> x = powl (x, y) * powl (x, z);
> x = x / expl (y);
> return x;
> }
> ===============================================
> /* Simplify sqrt(x) * sqrt(y) -> sqrt(x*y). */
> (simplify
> (mult (SQRT:s @0) (SQRT:s @1))
> (SQRT (mult @0 @1)))
>
> /* Simplify pow(x,y) * pow(x,z) -> pow(x,y+z). */
> (simplify
> (mult (POW:s @0 @1) (POW:s @0 @2))
> (POW @0 (plus @1 @2)))
>
> /* Simplify expN(x) * expN(y) -> expN(x+y). */
> (simplify
> (mult (EXP:s @0) (EXP:s @1))
> (EXP (plus @0 @1)))
>
> /* Simplify x / expN(y) into x*expN(-y). */
> (simplify
> (rdiv @0 (EXP @1))
> (mult @0 (EXP (negate @1))))
> ===============================================
>
>>> A quick "fix" to avoid this ICE would disable the pattern for
>>> -ferrno-math.
>
> Disabled the pattern for -ferrno-math.
>
>>> If you open a bugreport with the pattern and a testcase
> I'm going to have a closer look.
>
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67285
>
> Thanks for the detailed explanation of ":s".
>
> Please let me know whether the working patch can be committed?
> If its okay and with your approval, I would like to move some more
> patterns using "match and simplify".
Can you re-post with the typo fix and the missing :s?
Thanks,
Richard.
> Thanks,
> Naveen