On Wed, 14 Feb 2018, Jakub Jelinek wrote: > On Tue, Feb 13, 2018 at 07:04:09PM +0100, Richard Biener wrote: > > On February 13, 2018 6:51:29 PM GMT+01:00, Jakub Jelinek <ja...@redhat.com> > > wrote: > > >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? I'd rather > > not try to avoid all the complex code. > > So like this? Bootstrapped/regtested on x86_64-linux and i686-linux, ok for > trunk?
Yes. Thanks, Richard. > 2018-02-14 Jakub Jelinek <ja...@redhat.com> > > PR tree-optimization/84334 > * match.pd ((A +- CST1) +- CST2 -> A + CST3): If A is > also a CONSTANT_CLASS_P, punt. > > * gcc.dg/pr84334.c: New test. > > --- gcc/match.pd.jj 2018-02-13 21:22:19.565979401 +0100 > +++ gcc/match.pd 2018-02-14 13:55:06.584668049 +0100 > @@ -1733,9 +1733,12 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) > CONSTANT_CLASS_P@2) > /* If one of the types wraps, use that one. */ > (if (!ANY_INTEGRAL_TYPE_P (type) || TYPE_OVERFLOW_WRAPS (type)) > - (if (outer_op == PLUS_EXPR) > - (plus (view_convert @0) (inner_op @2 (view_convert @1))) > - (minus (view_convert @0) (neg_inner_op @2 (view_convert @1)))) > + /* If all 3 captures are CONSTANT_CLASS_P, punt, as we might recurse > + forever if something doesn't simplify into a constant. */ > + (if (!CONSTANT_CLASS_P (@0)) > + (if (outer_op == PLUS_EXPR) > + (plus (view_convert @0) (inner_op @2 (view_convert @1))) > + (minus (view_convert @0) (neg_inner_op @2 (view_convert @1))))) > (if (!ANY_INTEGRAL_TYPE_P (TREE_TYPE (@0)) > || TYPE_OVERFLOW_WRAPS (TREE_TYPE (@0))) > (if (outer_op == PLUS_EXPR) > --- gcc/testsuite/gcc.dg/pr84334.c.jj 2018-02-14 13:53:36.816683512 +0100 > +++ gcc/testsuite/gcc.dg/pr84334.c 2018-02-14 13:53:36.815683512 +0100 > @@ -0,0 +1,12 @@ > +/* PR tree-optimization/84334 */ > +/* { dg-do compile } */ > +/* { dg-options "-Ofast -frounding-math" } */ > + > +float > +foo (void) > +{ > + float a = 9.999999974752427078783512115478515625e-7f; > + float b = 1.999999994950485415756702423095703125e-6f; > + float c = 4.999999873689375817775726318359375e-6f; > + return a + b + c; > +} > > > Jakub > > -- Richard Biener <rguent...@suse.de> SUSE LINUX GmbH, GF: Felix Imendoerffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nuernberg)