Message ID | Pine.LNX.4.64.1311201816531.28804@digraph.polyomino.org.uk |
---|---|
State | New |
Headers | show |
On Wed, 20 Nov 2013, Joseph S. Myers wrote: > This patch removes real_sqrt. (I rather hope that in general little > if any floating-point constant folding is happening on RTL - it > doesn't seem like the sort of thing for which RTL expansion should be > expected to introduce new folding opportunities, and if it does I'd > tend to think that indicates a deficiency in the GIMPLE optimizers.) > > Bootstrapped with no regressions on x86_64-unknown-linux-gnu. OK to > commit? > > 2013-11-20 Joseph Myers <joseph@codesourcery.com> > > * real.c (real_sqrt): Remove function. > * real.h (real_sqrt): Remove prototype. > * simplify-rtx.c (simplify_const_unary_operation): Do not fold > SQRT using real_sqrt. I think you can close PR 55950 with that one.
On Wed, 20 Nov 2013, Marc Glisse wrote: > On Wed, 20 Nov 2013, Joseph S. Myers wrote: > > > This patch removes real_sqrt. (I rather hope that in general little > > if any floating-point constant folding is happening on RTL - it > > doesn't seem like the sort of thing for which RTL expansion should be > > expected to introduce new folding opportunities, and if it does I'd > > tend to think that indicates a deficiency in the GIMPLE optimizers.) > > > > Bootstrapped with no regressions on x86_64-unknown-linux-gnu. OK to > > commit? > > > > 2013-11-20 Joseph Myers <joseph@codesourcery.com> > > > > * real.c (real_sqrt): Remove function. > > * real.h (real_sqrt): Remove prototype. > > * simplify-rtx.c (simplify_const_unary_operation): Do not fold > > SQRT using real_sqrt. > > I think you can close PR 55950 with that one. Thanks for the reference - if you have a case where this code is active (other than where -fno- options are used to disable GIMPLE constant propagation etc. artificially, although I couldn't find a suitable testcase even with such options), could you file a PR in Bugzilla for the missing GIMPLE optimization that results in this only getting optimized (or not, after this patch) at the RTL level?
On Wed, 20 Nov 2013, Joseph S. Myers wrote: > On Wed, 20 Nov 2013, Marc Glisse wrote: > >> On Wed, 20 Nov 2013, Joseph S. Myers wrote: >> >>> This patch removes real_sqrt. (I rather hope that in general little >>> if any floating-point constant folding is happening on RTL - it >>> doesn't seem like the sort of thing for which RTL expansion should be >>> expected to introduce new folding opportunities, and if it does I'd >>> tend to think that indicates a deficiency in the GIMPLE optimizers.) >>> >>> Bootstrapped with no regressions on x86_64-unknown-linux-gnu. OK to >>> commit? >>> >>> 2013-11-20 Joseph Myers <joseph@codesourcery.com> >>> >>> * real.c (real_sqrt): Remove function. >>> * real.h (real_sqrt): Remove prototype. >>> * simplify-rtx.c (simplify_const_unary_operation): Do not fold >>> SQRT using real_sqrt. >> >> I think you can close PR 55950 with that one. > > Thanks for the reference - if you have a case where this code is active > (other than where -fno- options are used to disable GIMPLE constant > propagation etc. artificially, although I couldn't find a suitable > testcase even with such options), could you file a PR in Bugzilla for the > missing GIMPLE optimization that results in this only getting optimized > (or not, after this patch) at the RTL level? Actually, in my case (sqrt(2.) with -frounding-math), constant propagation was not wanted. gimple properly avoided it, and now RTL won't do it either, which is good, no optimization missed.
On Wed, Nov 20, 2013 at 7:17 PM, Joseph S. Myers <joseph@codesourcery.com> wrote: > On Wed, 20 Nov 2013, Richard Biener wrote: > >> I suggest to remove real_sqrt and the only use in simplify-rtx.c instead >> (or fix it to use MPFR as well - your choice). > > This patch removes real_sqrt. (I rather hope that in general little > if any floating-point constant folding is happening on RTL - it > doesn't seem like the sort of thing for which RTL expansion should be > expected to introduce new folding opportunities, and if it does I'd > tend to think that indicates a deficiency in the GIMPLE optimizers.) > > Bootstrapped with no regressions on x86_64-unknown-linux-gnu. OK to > commit? Ok. Thanks, Richard. > 2013-11-20 Joseph Myers <joseph@codesourcery.com> > > * real.c (real_sqrt): Remove function. > * real.h (real_sqrt): Remove prototype. > * simplify-rtx.c (simplify_const_unary_operation): Do not fold > SQRT using real_sqrt. > > Index: gcc/real.c > =================================================================== > --- gcc/real.c (revision 205119) > +++ gcc/real.c (working copy) > @@ -4765,84 +4765,6 @@ const struct real_format real_internal_format = > false > }; > > -/* Calculate the square root of X in mode MODE, and store the result > - in R. Return TRUE if the operation does not raise an exception. > - For details see "High Precision Division and Square Root", > - Alan H. Karp and Peter Markstein, HP Lab Report 93-93-42, June > - 1993. http://www.hpl.hp.com/techreports/93/HPL-93-42.pdf. */ > - > -bool > -real_sqrt (REAL_VALUE_TYPE *r, enum machine_mode mode, > - const REAL_VALUE_TYPE *x) > -{ > - static REAL_VALUE_TYPE halfthree; > - static bool init = false; > - REAL_VALUE_TYPE h, t, i; > - int iter, exp; > - > - /* sqrt(-0.0) is -0.0. */ > - if (real_isnegzero (x)) > - { > - *r = *x; > - return false; > - } > - > - /* Negative arguments return NaN. */ > - if (real_isneg (x)) > - { > - get_canonical_qnan (r, 0); > - return false; > - } > - > - /* Infinity and NaN return themselves. */ > - if (!real_isfinite (x)) > - { > - *r = *x; > - return false; > - } > - > - if (!init) > - { > - do_add (&halfthree, &dconst1, &dconsthalf, 0); > - init = true; > - } > - > - /* Initial guess for reciprocal sqrt, i. */ > - exp = real_exponent (x); > - real_ldexp (&i, &dconst1, -exp/2); > - > - /* Newton's iteration for reciprocal sqrt, i. */ > - for (iter = 0; iter < 16; iter++) > - { > - /* i(n+1) = i(n) * (1.5 - 0.5*i(n)*i(n)*x). */ > - do_multiply (&t, x, &i); > - do_multiply (&h, &t, &i); > - do_multiply (&t, &h, &dconsthalf); > - do_add (&h, &halfthree, &t, 1); > - do_multiply (&t, &i, &h); > - > - /* Check for early convergence. */ > - if (iter >= 6 && real_identical (&i, &t)) > - break; > - > - /* ??? Unroll loop to avoid copying. */ > - i = t; > - } > - > - /* Final iteration: r = i*x + 0.5*i*x*(1.0 - i*(i*x)). */ > - do_multiply (&t, x, &i); > - do_multiply (&h, &t, &i); > - do_add (&i, &dconst1, &h, 1); > - do_multiply (&h, &t, &i); > - do_multiply (&i, &dconsthalf, &h); > - do_add (&h, &t, &i, 0); > - > - /* ??? We need a Tuckerman test to get the last bit. */ > - > - real_convert (r, mode, &h); > - return true; > -} > - > /* Calculate X raised to the integer exponent N in mode MODE and store > the result in R. Return true if the result may be inexact due to > loss of precision. The algorithm is the classic "left-to-right binary > Index: gcc/real.h > =================================================================== > --- gcc/real.h (revision 205119) > +++ gcc/real.h (working copy) > @@ -461,10 +461,6 @@ bool real_can_shorten_arithmetic (enum machine_mod > /* In tree.c: wrap up a REAL_VALUE_TYPE in a tree node. */ > extern tree build_real (tree, REAL_VALUE_TYPE); > > -/* Calculate R as the square root of X in the given machine mode. */ > -extern bool real_sqrt (REAL_VALUE_TYPE *, enum machine_mode, > - const REAL_VALUE_TYPE *); > - > /* Calculate R as X raised to the integer exponent N in mode MODE. */ > extern bool real_powi (REAL_VALUE_TYPE *, enum machine_mode, > const REAL_VALUE_TYPE *, HOST_WIDE_INT); > Index: gcc/simplify-rtx.c > =================================================================== > --- gcc/simplify-rtx.c (revision 205119) > +++ gcc/simplify-rtx.c (working copy) > @@ -1931,17 +1931,13 @@ simplify_const_unary_operation (enum rtx_code code > && SCALAR_FLOAT_MODE_P (mode) > && SCALAR_FLOAT_MODE_P (GET_MODE (op))) > { > - REAL_VALUE_TYPE d, t; > + REAL_VALUE_TYPE d; > REAL_VALUE_FROM_CONST_DOUBLE (d, op); > > switch (code) > { > case SQRT: > - if (HONOR_SNANS (mode) && real_isnan (&d)) > - return 0; > - real_sqrt (&t, mode, &d); > - d = t; > - break; > + return 0; > case ABS: > d = real_value_abs (&d); > break; > > -- > Joseph S. Myers > joseph@codesourcery.com
Index: gcc/real.c =================================================================== --- gcc/real.c (revision 205119) +++ gcc/real.c (working copy) @@ -4765,84 +4765,6 @@ const struct real_format real_internal_format = false }; -/* Calculate the square root of X in mode MODE, and store the result - in R. Return TRUE if the operation does not raise an exception. - For details see "High Precision Division and Square Root", - Alan H. Karp and Peter Markstein, HP Lab Report 93-93-42, June - 1993. http://www.hpl.hp.com/techreports/93/HPL-93-42.pdf. */ - -bool -real_sqrt (REAL_VALUE_TYPE *r, enum machine_mode mode, - const REAL_VALUE_TYPE *x) -{ - static REAL_VALUE_TYPE halfthree; - static bool init = false; - REAL_VALUE_TYPE h, t, i; - int iter, exp; - - /* sqrt(-0.0) is -0.0. */ - if (real_isnegzero (x)) - { - *r = *x; - return false; - } - - /* Negative arguments return NaN. */ - if (real_isneg (x)) - { - get_canonical_qnan (r, 0); - return false; - } - - /* Infinity and NaN return themselves. */ - if (!real_isfinite (x)) - { - *r = *x; - return false; - } - - if (!init) - { - do_add (&halfthree, &dconst1, &dconsthalf, 0); - init = true; - } - - /* Initial guess for reciprocal sqrt, i. */ - exp = real_exponent (x); - real_ldexp (&i, &dconst1, -exp/2); - - /* Newton's iteration for reciprocal sqrt, i. */ - for (iter = 0; iter < 16; iter++) - { - /* i(n+1) = i(n) * (1.5 - 0.5*i(n)*i(n)*x). */ - do_multiply (&t, x, &i); - do_multiply (&h, &t, &i); - do_multiply (&t, &h, &dconsthalf); - do_add (&h, &halfthree, &t, 1); - do_multiply (&t, &i, &h); - - /* Check for early convergence. */ - if (iter >= 6 && real_identical (&i, &t)) - break; - - /* ??? Unroll loop to avoid copying. */ - i = t; - } - - /* Final iteration: r = i*x + 0.5*i*x*(1.0 - i*(i*x)). */ - do_multiply (&t, x, &i); - do_multiply (&h, &t, &i); - do_add (&i, &dconst1, &h, 1); - do_multiply (&h, &t, &i); - do_multiply (&i, &dconsthalf, &h); - do_add (&h, &t, &i, 0); - - /* ??? We need a Tuckerman test to get the last bit. */ - - real_convert (r, mode, &h); - return true; -} - /* Calculate X raised to the integer exponent N in mode MODE and store the result in R. Return true if the result may be inexact due to loss of precision. The algorithm is the classic "left-to-right binary Index: gcc/real.h =================================================================== --- gcc/real.h (revision 205119) +++ gcc/real.h (working copy) @@ -461,10 +461,6 @@ bool real_can_shorten_arithmetic (enum machine_mod /* In tree.c: wrap up a REAL_VALUE_TYPE in a tree node. */ extern tree build_real (tree, REAL_VALUE_TYPE); -/* Calculate R as the square root of X in the given machine mode. */ -extern bool real_sqrt (REAL_VALUE_TYPE *, enum machine_mode, - const REAL_VALUE_TYPE *); - /* Calculate R as X raised to the integer exponent N in mode MODE. */ extern bool real_powi (REAL_VALUE_TYPE *, enum machine_mode, const REAL_VALUE_TYPE *, HOST_WIDE_INT); Index: gcc/simplify-rtx.c =================================================================== --- gcc/simplify-rtx.c (revision 205119) +++ gcc/simplify-rtx.c (working copy) @@ -1931,17 +1931,13 @@ simplify_const_unary_operation (enum rtx_code code && SCALAR_FLOAT_MODE_P (mode) && SCALAR_FLOAT_MODE_P (GET_MODE (op))) { - REAL_VALUE_TYPE d, t; + REAL_VALUE_TYPE d; REAL_VALUE_FROM_CONST_DOUBLE (d, op); switch (code) { case SQRT: - if (HONOR_SNANS (mode) && real_isnan (&d)) - return 0; - real_sqrt (&t, mode, &d); - d = t; - break; + return 0; case ABS: d = real_value_abs (&d); break;