public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/users/meissner/heads/work042)] Do not enable __float128 or __ibm128 support on Fortran, PR 96983
@ 2021-03-23 20:01 Michael Meissner
  0 siblings, 0 replies; only message in thread
From: Michael Meissner @ 2021-03-23 20:01 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:5d15b4d17e899565e5c9ac11a677a3b6885d6a04

commit 5d15b4d17e899565e5c9ac11a677a3b6885d6a04
Author: Michael Meissner <meissner@linux.ibm.com>
Date:   Tue Mar 23 16:00:59 2021 -0400

    Do not enable __float128 or __ibm128 support on Fortran, PR 96983
    
    This patch does not create the internal types for __float128 and __ibm128
    on Fortran which cannot use them.  This in turn allows us to set the type
    precision for long double to be 128, which Fortran wants.
    
    gcc/
    2021-03-23  Michael Meissner  <meissner@linux.ibm.com>
    
            PR fortran/96983
            * config/rs6000/rs6000.c (rs6000_debug_reg_global): Add more
            debugging for __float128, __ibm128 support.
            (rs6000_option_override_internal): Do not enable __float128 and
            __ibm128 support for Fortran.  On Fortran, make the default long
            double precision to be 128.  Add error messages if the user tries
            to change the long double type between IBM/IEEE on Fortran.
            (rs6000_init_libfuncs): Do not enable __ibm128 support if it is
            disabled.
            * config/rs6000/rs6000.h (FLOAT128_IBM_P): Do not return true if
            __ibm128 was disabled for IFmode/ICmode.
            (TARGET_IBM128): Move this to rs6000.opt.
            * config/rs6000/rs6000.md (FP iterator): Do not enable IF mode if
            __ibm128 is disabled.
            (FLOAT128 iterator): Likewise.
            * config/rs6000/rs6000.opt (x_TARGET_IBM128): New variables to
            record whether __ibm128 is supported or not.
            (TARGET_IBM128): Likewise.

Diff:
---
 gcc/config/rs6000/rs6000.c   | 92 +++++++++++++++++++++++++++++++++-----------
 gcc/config/rs6000/rs6000.h   |  9 +----
 gcc/config/rs6000/rs6000.md  |  4 +-
 gcc/config/rs6000/rs6000.opt |  7 ++++
 4 files changed, 81 insertions(+), 31 deletions(-)

diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c
index db215810aa6..c3d280b0874 100644
--- a/gcc/config/rs6000/rs6000.c
+++ b/gcc/config/rs6000/rs6000.c
@@ -2551,6 +2551,11 @@ rs6000_debug_reg_global (void)
 	       TARGET_IEEEQUAD ? "IEEE" : "IBM");
       fprintf (stderr, DEBUG_FMT_S, "default long double type",
 	       TARGET_IEEEQUAD_DEFAULT ? "IEEE" : "IBM");
+      if (TARGET_FLOAT128_TYPE)
+	fprintf (stderr, DEBUG_FMT_S, "IEEE 128-bit support",
+		 TARGET_FLOAT128_KEYWORD ? "keyword" : "type");
+      if (TARGET_IBM128)
+	fprintf (stderr, DEBUG_FMT_S, "__ibm128 keyword", "true");
     }
   fprintf (stderr, DEBUG_FMT_D, "sched_restricted_insns_priority",
 	   (int)rs6000_sched_restricted_insns_priority);
@@ -4136,12 +4141,20 @@ rs6000_option_override_internal (bool global_init_p)
 	rs6000_isa_flags &= ~OPTION_MASK_BLOCK_OPS_VECTOR_PAIR;
     }
 
-  /* Use long double size to select the appropriate long double.  We use
-     TYPE_PRECISION to differentiate the 3 different long double types.  We map
-     128 into the precision used for TFmode.  */
+  /* Use long double size to select the appropriate long double.
+
+     On C/C++, We use TYPE_PRECISION to differentiate the 3 different long
+     double types.  We map 128 into the precision used for TFmode.
+
+     Fortran does not have support for the types __float128 and __ibm128, just
+     the default long double type.  For Fortran, we use the precision 128 for
+     the long double type.  */
+  bool is_fortran = lang_GNU_Fortran ();
   int default_long_double_size = (RS6000_DEFAULT_LONG_DOUBLE_SIZE == 64
 				  ? 64
-				  : FLOAT_PRECISION_TFmode);
+				  : (is_fortran
+				     ? 128
+				     : FLOAT_PRECISION_TFmode));
 
   /* Set long double size before the IEEE 128-bit tests.  */
   if (!global_options_set.x_rs6000_long_double_type_size)
@@ -4153,7 +4166,7 @@ rs6000_option_override_internal (bool global_init_p)
       else
 	rs6000_long_double_type_size = default_long_double_size;
     }
-  else if (rs6000_long_double_type_size == 128)
+  else if (rs6000_long_double_type_size == 128 && !is_fortran)
     rs6000_long_double_type_size = FLOAT_PRECISION_TFmode;
   else if (global_options_set.x_rs6000_ieeequad)
     {
@@ -4184,17 +4197,25 @@ rs6000_option_override_internal (bool global_init_p)
 	     2.32 or newer.  Only issue one warning.  */
 	  static bool warned_change_long_double;
 
-	  if (!warned_change_long_double
-	      && (!glibc_supports_ieee_128bit ()
-		  || (!lang_GNU_C () && !lang_GNU_CXX ())))
+	  if (!warned_change_long_double)
 	    {
 	      warned_change_long_double = true;
-	      if (TARGET_IEEEQUAD)
-		warning (OPT_Wpsabi, "Using IEEE extended precision "
-			 "%<long double%>");
-	      else
-		warning (OPT_Wpsabi, "Using IBM extended precision "
-			 "%<long double%>");
+	      if (is_fortran)
+		error ("Fortran does not support %qs to change the default "
+		       "long double type",
+		       (TARGET_IEEEQUAD
+			? "-mabi=ieeelongdouble"
+			: "-mabi=ibmlongdouble"));
+
+	      else if (!glibc_supports_ieee_128bit ())
+		{
+		  if (TARGET_IEEEQUAD)
+		    warning (OPT_Wpsabi, "Using IEEE extended precision "
+			     "%<long double%>");
+		  else
+		    warning (OPT_Wpsabi, "Using IBM extended precision "
+			     "%<long double%>");
+		}
 	    }
 	}
     }
@@ -4203,8 +4224,13 @@ rs6000_option_override_internal (bool global_init_p)
      sytems.  In GCC 7, we would enable the IEEE 128-bit floating point
      infrastructure (-mfloat128-type) but not enable the actual __float128 type
      unless the user used the explicit -mfloat128.  In GCC 8, we enable both
-     the keyword as well as the type.  */
-  TARGET_FLOAT128_TYPE = TARGET_FLOAT128_ENABLE_TYPE && TARGET_VSX;
+     the keyword as well as the type.
+
+     Fortran does not support separate 128-bit floating point types other than
+     long double, we only enable TARGET_FLOAT128_TYPE if the default long double
+     for Fortran is IEEE-128 bit.  */
+  TARGET_FLOAT128_TYPE = (TARGET_FLOAT128_ENABLE_TYPE && TARGET_VSX
+			  && (!is_fortran || TARGET_IEEEQUAD));
 
   /* IEEE 128-bit floating point requires VSX support.  */
   if (TARGET_FLOAT128_KEYWORD)
@@ -4218,6 +4244,13 @@ rs6000_option_override_internal (bool global_init_p)
 	  rs6000_isa_flags &= ~(OPTION_MASK_FLOAT128_KEYWORD
 				| OPTION_MASK_FLOAT128_HW);
 	}
+      else if (is_fortran)
+	{
+	  if ((rs6000_isa_flags_explicit & OPTION_MASK_FLOAT128_KEYWORD) != 0)
+	    error ("Fortran does not support %qs", "-mfloat128");
+
+	  rs6000_isa_flags &= ~OPTION_MASK_FLOAT128_KEYWORD;
+	}
       else if (!TARGET_FLOAT128_TYPE)
 	{
 	  TARGET_FLOAT128_TYPE = 1;
@@ -4225,8 +4258,22 @@ rs6000_option_override_internal (bool global_init_p)
 	}
     }
 
-  /* Enable the __float128 keyword under Linux by default.  */
-  if (TARGET_FLOAT128_TYPE && !TARGET_FLOAT128_KEYWORD
+  /* Whether the '__ibm128' keywork is enabled.  We enable __ibm128 either if the
+   IEEE 128-bit floating point support is enabled or if the long double support
+   uses the 128-bit IBM extended double format.
+
+   However, we don't enable __ibm128 if the language is Fortran.  Fortran
+   doesn't have the notion of separate types for __ibm128 and __float128, and it
+   wants the precision for the 16 byte floating point type to be 128.  With the
+   3 128-bit types enabled, we use the precision field to identify the separate
+   types.  */
+  TARGET_IBM128 = (!is_fortran
+		   && (TARGET_FLOAT128_TYPE
+		       || (!TARGET_IEEEQUAD && TARGET_LONG_DOUBLE_128)));
+
+
+  /* Enable the __float128 keyword under Linux by default for C/C++.  */
+  if (TARGET_FLOAT128_TYPE && !TARGET_FLOAT128_KEYWORD && !is_fortran
       && (rs6000_isa_flags_explicit & OPTION_MASK_FLOAT128_KEYWORD) == 0)
     rs6000_isa_flags |= OPTION_MASK_FLOAT128_KEYWORD;
 
@@ -11061,10 +11108,11 @@ rs6000_init_libfuncs (void)
 {
   /* __float128 support.  */
   if (TARGET_FLOAT128_TYPE)
-    {
-      init_float128_ibm (IFmode);
-      init_float128_ieee (KFmode);
-    }
+    init_float128_ieee (KFmode);
+
+  /* __ibm128 support.  */
+  if (TARGET_IBM128)
+    init_float128_ibm (IFmode);
 
   /* AIX/Darwin/64-bit Linux quad floating point routines.  */
   if (TARGET_LONG_DOUBLE_128)
diff --git a/gcc/config/rs6000/rs6000.h b/gcc/config/rs6000/rs6000.h
index 520e277f7f3..6c25fedc0ff 100644
--- a/gcc/config/rs6000/rs6000.h
+++ b/gcc/config/rs6000/rs6000.h
@@ -334,7 +334,8 @@ extern const char *host_detect_local_cpu (int argc, const char **argv);
 #define FLOAT128_IBM_P(MODE)						\
   ((!TARGET_IEEEQUAD && TARGET_LONG_DOUBLE_128				\
     && ((MODE) == TFmode || (MODE) == TCmode))				\
-   || (TARGET_HARD_FLOAT && ((MODE) == IFmode || (MODE) == ICmode)))
+   || (TARGET_HARD_FLOAT && TARGET_IBM128				\
+       && ((MODE) == IFmode || (MODE) == ICmode)))
 
 /* Helper macros to say whether a 128-bit floating point type can go in a
    single vector register, or whether it needs paired scalar values.  */
@@ -509,12 +510,6 @@ extern int rs6000_vector_align[];
 #define TARGET_MINMAX	(TARGET_HARD_FLOAT && TARGET_PPC_GFXOPT		\
 			 && (TARGET_P9_MINMAX || !flag_trapping_math))
 
-/* Whether the '__ibm128' keywork is enabled.  We enable __ibm128 either if the
-   IEEE 128-bit floating point support is enabled or if the long double support
-   uses the 128-bit IBM extended double format.  */
-#define TARGET_IBM128	(TARGET_FLOAT128_TYPE				\
-			 || (!TARGET_IEEEQUAD && TARGET_LONG_DOUBLE_128))
-
 /* In switching from using target_flags to using rs6000_isa_flags, the options
    machinery creates OPTION_MASK_<xxx> instead of MASK_<xxx>.  For now map
    OPTION_MASK_<xxx> back into MASK_<xxx>.  */
diff --git a/gcc/config/rs6000/rs6000.md b/gcc/config/rs6000/rs6000.md
index 97da8490495..53502ede3b0 100644
--- a/gcc/config/rs6000/rs6000.md
+++ b/gcc/config/rs6000/rs6000.md
@@ -480,7 +480,7 @@
   (SF "TARGET_HARD_FLOAT")
   (DF "TARGET_HARD_FLOAT")
   (TF "TARGET_HARD_FLOAT && TARGET_LONG_DOUBLE_128")
-  (IF "TARGET_HARD_FLOAT && TARGET_LONG_DOUBLE_128")
+  (IF "TARGET_HARD_FLOAT && TARGET_IBM128")
   (KF "TARGET_FLOAT128_TYPE")
   (DD "TARGET_DFP")
   (TD "TARGET_DFP")])
@@ -604,7 +604,7 @@
 
 ; Iterator for 128-bit floating point
 (define_mode_iterator FLOAT128 [(KF "TARGET_FLOAT128_TYPE")
-				(IF "TARGET_FLOAT128_TYPE")
+				(IF "TARGET_IBM128")
 				(TF "TARGET_LONG_DOUBLE_128")])
 
 ; Iterator for signbit on 64-bit machines with direct move
diff --git a/gcc/config/rs6000/rs6000.opt b/gcc/config/rs6000/rs6000.opt
index 0dbdf753673..1fb2c35c1b3 100644
--- a/gcc/config/rs6000/rs6000.opt
+++ b/gcc/config/rs6000/rs6000.opt
@@ -112,6 +112,13 @@ unsigned char x_TARGET_FLOAT128_TYPE
 Variable
 unsigned char TARGET_FLOAT128_TYPE
 
+;; Whether to enable the __ibm128 support
+TargetSave
+unsigned char x_TARGET_IBM128
+
+Variable
+unsigned char TARGET_IBM128
+
 ;; This option existed in the past, but now is always on.
 mpowerpc
 Target RejectNegative Undocumented Ignore


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-03-23 20:01 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-23 20:01 [gcc(refs/users/meissner/heads/work042)] Do not enable __float128 or __ibm128 support on Fortran, PR 96983 Michael Meissner

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).