From: David Malcolm <dmalcolm@redhat.com>
To: Jakub Jelinek <jakub@redhat.com>, fortran@gcc.gnu.org
Cc: gcc-patches@gcc.gnu.org, David Malcolm <dmalcolm@redhat.com>
Subject: [PATCH] Minimum version of mpfr? (was Re: [PATCH] Fix up norm2 simplification (PR middle-end/88074))
Date: Thu, 21 Feb 2019 21:18:00 -0000 [thread overview]
Message-ID: <1550785827-10962-1-git-send-email-dmalcolm@redhat.com> (raw)
In-Reply-To: <20190212230942.GQ2135@tucnak>
On Wed, 2019-02-13 at 00:09 +0100, Jakub Jelinek wrote:
> Hi!
>
> As discussed recently on the mailing list, the norm2 simplification
> doesn't
> work if we limit mpfr emin/emax to some values derived from maximum
> floating
> exponents (and precision for denormals).
>
> The following patch adjusts the computation, so that it is scaled
> down if
> needed. In particular, if any value in the array is so large that
> **2 will
> overflow on it or will be very close to it, the scale down is set to
> 2**(max_exponent/2+4), and if the result during computation gets
> close to
> overflowing, it is scaled down a little bit too. The scaling is
> always done
> using powers of two, operands by that and the sum by **2 of that, and
> at the
> end it multiplies the sqrt back. I had to change
> simplify_transformation_to_array, so that post_op is done immediately
> after
> finishing ops corresponding to that, so that there can be just one
> global
> variable for the scale. From my understanding of e.g. the
> libgfortran norm2
> code where sqrt is done basically in this spot I hope it isn't
> possible that
> the same *dest is updated multiple times with dest
> increments/decrements in
> between.
>
> Bootstrapped/regtested on x86_64-linux and i686-linux (together with
> Richard's patch), ok for trunk?
>
> 2019-02-12 Jakub Jelinek <jakub@redhat.com>
>
> PR middle-end/88074
> * simplify.c (simplify_transformation_to_array): Run post_op
> immediately after processing corresponding row, rather than at
> the
> end.
> (norm2_scale): New variable.
> (add_squared): Rename to ...
> (norm2_add_squared): ... this. Scale down operand and/or
> result
> if needed.
> (do_sqrt): Rename to ...
> (norm2_do_sqrt): ... this. Handle the result == e case. Scale
> up
> result and clear norm2_scale.
> (gfc_simplify_norm2): Clear norm2_scale. Change add_squared to
> norm2_add_squared and &do_sqrt to norm2_do_sqrt. Scale up
> result
> and clear norm2_scale again.
>
[...]
> static gfc_expr *
> -add_squared (gfc_expr *result, gfc_expr *e)
> +norm2_add_squared (gfc_expr *result, gfc_expr *e)
> {
> mpfr_t tmp;
>
> @@ -6059,8 +6060,45 @@ add_squared (gfc_expr *result, gfc_expr
> && result->expr_type == EXPR_CONSTANT);
>
> gfc_set_model_kind (result->ts.kind);
> + int index = gfc_validate_kind (BT_REAL, result->ts.kind, false);
> + mpfr_exp_t exp;
> + if (mpfr_regular_p (result->value.real))
> + {
I've started seeing build failures in my testing setup here, apparently
introduced with this patch:
../../../src/gcc/fortran/simplify.c: In function âgfc_expr* norm2_add_squared(gfc_expr*, gfc_expr*)â:
../../../src/gcc/fortran/simplify.c:6064:3: error: âmpfr_exp_tâ was not declared in this scope; did you mean âmpfr_expm1â?
6064 | mpfr_exp_t exp;
| ^~~~~~~~~~
| mpfr_expm1
I'm using mpfr-2.4.2.tar.bz2, which is the minimum version stated at:
https://gcc.gnu.org/install/prerequisites.html
which says "MPFR Library version 2.4.2 (or later)"; that
version doesn't seem to have that type.
However, I see on:
https://www.mpfr.org/mpfr-3.0.1/mpfr.html#API-Compatibility
that "The official type for exponent values changed from mp_exp_t to
mpfr_exp_t in MPFR 3.0."
So should the patch be tweaked to use the old type name, like in the
following patch (caveat: not tested yet), or do we need to update
the minimum version of mpfr, and if so, to what version?
[...]
Dave
gcc/fortran/ChangeLog:
PR middle-end/88074
* simplify.c (norm2_add_squared): Use mp_exp_t rather than
mpfr_exp_t.
---
gcc/fortran/simplify.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/gcc/fortran/simplify.c b/gcc/fortran/simplify.c
index fa6396b..a1df735 100644
--- a/gcc/fortran/simplify.c
+++ b/gcc/fortran/simplify.c
@@ -6061,7 +6061,7 @@ norm2_add_squared (gfc_expr *result, gfc_expr *e)
gfc_set_model_kind (result->ts.kind);
int index = gfc_validate_kind (BT_REAL, result->ts.kind, false);
- mpfr_exp_t exp;
+ mp_exp_t exp;
if (mpfr_regular_p (result->value.real))
{
exp = mpfr_get_exp (result->value.real);
--
1.8.5.3
next prev parent reply other threads:[~2019-02-21 20:59 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-12 23:09 [PATCH] Fix up norm2 simplification (PR middle-end/88074) Jakub Jelinek
2019-02-13 18:18 ` Thomas Koenig
2019-02-13 18:31 ` Jakub Jelinek
2019-02-13 18:51 ` Steve Kargl
2019-02-13 18:58 ` Jakub Jelinek
2019-02-16 16:25 ` Thomas Koenig
2019-02-16 18:01 ` Steve Kargl
2019-02-17 17:30 ` Thomas Koenig
2019-02-21 21:18 ` David Malcolm [this message]
2019-02-21 21:22 ` [PATCH] Minimum version of mpfr? (was Re: [PATCH] Fix up norm2 simplification (PR middle-end/88074)) Jakub Jelinek
2019-02-22 13:46 ` [PATCH] Minimum version of mpfr? (was Re: [PATCH] Fix up norm2 simplification (PR middle-end/88074)), take 2 Jakub Jelinek
2019-02-22 14:40 ` Richard Biener
2019-02-23 1:06 ` David Malcolm
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1550785827-10962-1-git-send-email-dmalcolm@redhat.com \
--to=dmalcolm@redhat.com \
--cc=fortran@gcc.gnu.org \
--cc=gcc-patches@gcc.gnu.org \
--cc=jakub@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).