This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] FIx endless match.pd recursion on cst1 + cst2 + cst3 (PR tree-optimization/84334)
- From: Jakub Jelinek <jakub at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Cc: Richard Biener <rguenther at suse dot de>
- Date: Tue, 13 Feb 2018 21:59:03 +0100
- Subject: Re: [PATCH] FIx endless match.pd recursion on cst1 + cst2 + cst3 (PR tree-optimization/84334)
- Authentication-results: sourceware.org; auth=none
- References: <20180213175129.GS5867@tucnak> <0EFCE6B1-E838-4739-838D-11231846CA98@suse.de> <alpine.DEB.2.21.1802131524001.4837@stedding.saclay.inria.fr>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
On Tue, Feb 13, 2018 at 03:28:25PM -0400, Marc Glisse wrote:
> On Tue, 13 Feb 2018, Richard Biener wrote:
>
> > On February 13, 2018 6:51:29 PM GMT+01:00, Jakub Jelinek <jakub@redhat.com> wrote:
> > > Hi!
> > >
> > > On the following testcase, we recurse infinitely, because
> > > we have float re-association enabled, but also rounding-math, so
> > > we try to optimize (cst1 + cst2) + cst3 as (cst2 + cst3) + cst1
> > > but (cst2 + cst3) doesn't simplify and we try again and optimize
> > > it as (cst3 + cst1) + cst2 and then (cst1 + cst2) + cst3 and so on
> > > forever. If @0 is not a CONSTANT_CLASS_P, there is not a problem,
> > > if it is, the code just checks if we can actually simplify the
> > > operation between cst2 and cst3 into a constant.
> >
> > Is there a reason to try simplifying at all for constant @0?
>
> Yes. cst2+cst3 might simplify (the operation happens to be exact and not
> require rounding), which leaves us with only one addition instead of 2.
Yeah, exactly, e.g.
/* { dg-do compile } */
/* { dg-options "-Ofast -frounding-math" } */
float
foo (void)
{
float a = 9.999999974752427078783512115478515625e-7f;
float b = 1024.0f;
float c = 2048.0f;
return a + b + c;
}
would no longer be optimized into a single addition rather than 2.
Jakub