diff mbox series

Minimum version of mpfr? (was Re: [PATCH] Fix up norm2 simplification (PR middle-end/88074)), take 2

Message ID 20190222131907.GC7611@tucnak
State New
Headers show
Series Minimum version of mpfr? (was Re: [PATCH] Fix up norm2 simplification (PR middle-end/88074)), take 2 | expand

Commit Message

Jakub Jelinek Feb. 22, 2019, 1:19 p.m. UTC
On Thu, Feb 21, 2019 at 04:50:27PM -0500, David Malcolm wrote:
> gcc/fortran/ChangeLog:
> 	PR middle-end/88074
> 	* simplify.c (norm2_add_squared): Use mp_exp_t rather than
> 	mpfr_exp_t.

I have discussed this with Richard on IRC earlier today, there is another
issue that mpfr_regular_p is only 3.0 and later.  And he prefers that
mp_exp_t over say
#if MPFR_VERSION < MPFR_VERSION_NUM(3,0,0)
typedef mp_exp_t mpfr_exp_t;
#endif

So, here is the full patch I'll bootstrap/regtest soon:

2019-02-22  David Malcolm  <dmalcolm@redhat.com>
	    Jakub Jelinek  <jakub@redhat.com>

	PR middle-end/88074
	* simplify.c (norm2_do_sqrt, gfc_simplify_norm2): Use
	mpfr_number_p && !mpfr_zero_p instead of mpfr_regular_p.
	(norm2_add_squared): Likewise.  Use mp_exp_t rather than mpfr_exp_t.


	Jakub

Comments

Richard Biener Feb. 22, 2019, 1:25 p.m. UTC | #1
On Fri, 22 Feb 2019, Jakub Jelinek wrote:

> On Thu, Feb 21, 2019 at 04:50:27PM -0500, David Malcolm wrote:
> > gcc/fortran/ChangeLog:
> > 	PR middle-end/88074
> > 	* simplify.c (norm2_add_squared): Use mp_exp_t rather than
> > 	mpfr_exp_t.
> 
> I have discussed this with Richard on IRC earlier today, there is another
> issue that mpfr_regular_p is only 3.0 and later.  And he prefers that
> mp_exp_t over say
> #if MPFR_VERSION < MPFR_VERSION_NUM(3,0,0)
> typedef mp_exp_t mpfr_exp_t;
> #endif
> 
> So, here is the full patch I'll bootstrap/regtest soon:

OK if it passes.

Apart from autotesters where some of ours run very old outdated systems...
for SLES 12 which I think is the oldest relevant distro I'd like to
see newer GCCs to work on we have mpfr 3.1.2 and gmp 5.1.3 just in
case we might finally consider bumping the minimum required versions
at some point.  Though I didn't yet see any technical reason to do so,
we have more "issues" supporting old host GCC versions (SLE12 uses
GCC 4.8 so that would be a considerable bump already).

Richard.

> 2019-02-22  David Malcolm  <dmalcolm@redhat.com>
> 	    Jakub Jelinek  <jakub@redhat.com>
> 
> 	PR middle-end/88074
> 	* simplify.c (norm2_do_sqrt, gfc_simplify_norm2): Use
> 	mpfr_number_p && !mpfr_zero_p instead of mpfr_regular_p.
> 	(norm2_add_squared): Likewise.  Use mp_exp_t rather than mpfr_exp_t.
> 
> --- gcc/fortran/simplify.c.jj	2019-02-21 22:20:07.272388243 +0100
> +++ gcc/fortran/simplify.c	2019-02-22 11:07:36.093374586 +0100
> @@ -6061,8 +6061,8 @@ norm2_add_squared (gfc_expr *result, gfc
>  
>    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))
> +  mp_exp_t exp;
> +  if (mpfr_number_p (result->value.real) && !mpfr_zero_p (result->value.real))
>      {
>        exp = mpfr_get_exp (result->value.real);
>        /* If result is getting close to overflowing, scale down.  */
> @@ -6076,7 +6076,7 @@ norm2_add_squared (gfc_expr *result, gfc
>      }
>  
>    mpfr_init (tmp);
> -  if (mpfr_regular_p (e->value.real))
> +  if (mpfr_number_p (e->value.real) && !mpfr_zero_p (e->value.real))
>      {
>        exp = mpfr_get_exp (e->value.real);
>        /* If e**2 would overflow or close to overflowing, scale down.  */
> @@ -6117,7 +6117,9 @@ norm2_do_sqrt (gfc_expr *result, gfc_exp
>    if (result != e)
>      mpfr_set (result->value.real, e->value.real, GFC_RND_MODE);
>    mpfr_sqrt (result->value.real, result->value.real, GFC_RND_MODE);
> -  if (norm2_scale && mpfr_regular_p (result->value.real))
> +  if (norm2_scale
> +      && mpfr_number_p (result->value.real)
> +      && !mpfr_zero_p (result->value.real))
>      {
>        mpfr_t tmp;
>        mpfr_init (tmp);
> @@ -6156,7 +6158,9 @@ gfc_simplify_norm2 (gfc_expr *e, gfc_exp
>        result = simplify_transformation_to_scalar (result, e, NULL,
>  						  norm2_add_squared);
>        mpfr_sqrt (result->value.real, result->value.real, GFC_RND_MODE);
> -      if (norm2_scale && mpfr_regular_p (result->value.real))
> +      if (norm2_scale
> +	  && mpfr_number_p (result->value.real)
> +	  && !mpfr_zero_p (result->value.real))
>  	{
>  	  mpfr_t tmp;
>  	  mpfr_init (tmp);
> 
> 	Jakub
> 
>
David Malcolm Feb. 23, 2019, 12:32 a.m. UTC | #2
On Fri, 2019-02-22 at 14:19 +0100, Jakub Jelinek wrote:
> On Thu, Feb 21, 2019 at 04:50:27PM -0500, David Malcolm wrote:
> > gcc/fortran/ChangeLog:
> > 	PR middle-end/88074
> > 	* simplify.c (norm2_add_squared): Use mp_exp_t rather than
> > 	mpfr_exp_t.
> 
> I have discussed this with Richard on IRC earlier today, there is
> another
> issue that mpfr_regular_p is only 3.0 and later.  And he prefers that
> mp_exp_t over say
> #if MPFR_VERSION < MPFR_VERSION_NUM(3,0,0)
> typedef mp_exp_t mpfr_exp_t;
> #endif
> 
> So, here is the full patch I'll bootstrap/regtest soon:

FWIW, your patch fixed the bootstrap for me (and the regression tests
look sane:
  gfortran.sum : total: 49370 PASS: 49164 XFAIL: 126 UNSUPPORTED: 80
though sadly I've blown away my known-good baseline for comparison)

Dave

> 2019-02-22  David Malcolm  <dmalcolm@redhat.com>
> 	    Jakub Jelinek  <jakub@redhat.com>
> 
> 	PR middle-end/88074
> 	* simplify.c (norm2_do_sqrt, gfc_simplify_norm2): Use
> 	mpfr_number_p && !mpfr_zero_p instead of mpfr_regular_p.
> 	(norm2_add_squared): Likewise.  Use mp_exp_t rather than
> mpfr_exp_t.
> 
> --- gcc/fortran/simplify.c.jj	2019-02-21 22:20:07.272388243
> +0100
> +++ gcc/fortran/simplify.c	2019-02-22 11:07:36.093374586 +0100
> @@ -6061,8 +6061,8 @@ norm2_add_squared (gfc_expr *result, gfc
>  
>    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))
> +  mp_exp_t exp;
> +  if (mpfr_number_p (result->value.real) && !mpfr_zero_p (result-
> >value.real))
>      {
>        exp = mpfr_get_exp (result->value.real);
>        /* If result is getting close to overflowing, scale down.  */
> @@ -6076,7 +6076,7 @@ norm2_add_squared (gfc_expr *result, gfc
>      }
>  
>    mpfr_init (tmp);
> -  if (mpfr_regular_p (e->value.real))
> +  if (mpfr_number_p (e->value.real) && !mpfr_zero_p (e->value.real))
>      {
>        exp = mpfr_get_exp (e->value.real);
>        /* If e**2 would overflow or close to overflowing, scale
> down.  */
> @@ -6117,7 +6117,9 @@ norm2_do_sqrt (gfc_expr *result, gfc_exp
>    if (result != e)
>      mpfr_set (result->value.real, e->value.real, GFC_RND_MODE);
>    mpfr_sqrt (result->value.real, result->value.real, GFC_RND_MODE);
> -  if (norm2_scale && mpfr_regular_p (result->value.real))
> +  if (norm2_scale
> +      && mpfr_number_p (result->value.real)
> +      && !mpfr_zero_p (result->value.real))
>      {
>        mpfr_t tmp;
>        mpfr_init (tmp);
> @@ -6156,7 +6158,9 @@ gfc_simplify_norm2 (gfc_expr *e, gfc_exp
>        result = simplify_transformation_to_scalar (result, e, NULL,
>  						  norm2_add_squared)
> ;
>        mpfr_sqrt (result->value.real, result->value.real,
> GFC_RND_MODE);
> -      if (norm2_scale && mpfr_regular_p (result->value.real))
> +      if (norm2_scale
> +	  && mpfr_number_p (result->value.real)
> +	  && !mpfr_zero_p (result->value.real))
>  	{
>  	  mpfr_t tmp;
>  	  mpfr_init (tmp);
> 
> 	Jakub
diff mbox series

Patch

--- gcc/fortran/simplify.c.jj	2019-02-21 22:20:07.272388243 +0100
+++ gcc/fortran/simplify.c	2019-02-22 11:07:36.093374586 +0100
@@ -6061,8 +6061,8 @@  norm2_add_squared (gfc_expr *result, gfc
 
   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))
+  mp_exp_t exp;
+  if (mpfr_number_p (result->value.real) && !mpfr_zero_p (result->value.real))
     {
       exp = mpfr_get_exp (result->value.real);
       /* If result is getting close to overflowing, scale down.  */
@@ -6076,7 +6076,7 @@  norm2_add_squared (gfc_expr *result, gfc
     }
 
   mpfr_init (tmp);
-  if (mpfr_regular_p (e->value.real))
+  if (mpfr_number_p (e->value.real) && !mpfr_zero_p (e->value.real))
     {
       exp = mpfr_get_exp (e->value.real);
       /* If e**2 would overflow or close to overflowing, scale down.  */
@@ -6117,7 +6117,9 @@  norm2_do_sqrt (gfc_expr *result, gfc_exp
   if (result != e)
     mpfr_set (result->value.real, e->value.real, GFC_RND_MODE);
   mpfr_sqrt (result->value.real, result->value.real, GFC_RND_MODE);
-  if (norm2_scale && mpfr_regular_p (result->value.real))
+  if (norm2_scale
+      && mpfr_number_p (result->value.real)
+      && !mpfr_zero_p (result->value.real))
     {
       mpfr_t tmp;
       mpfr_init (tmp);
@@ -6156,7 +6158,9 @@  gfc_simplify_norm2 (gfc_expr *e, gfc_exp
       result = simplify_transformation_to_scalar (result, e, NULL,
 						  norm2_add_squared);
       mpfr_sqrt (result->value.real, result->value.real, GFC_RND_MODE);
-      if (norm2_scale && mpfr_regular_p (result->value.real))
+      if (norm2_scale
+	  && mpfr_number_p (result->value.real)
+	  && !mpfr_zero_p (result->value.real))
 	{
 	  mpfr_t tmp;
 	  mpfr_init (tmp);