Turn on -mpcrel by default for -mcpu=future

I reworked the patches based on your comments:

1) I removed the check for 64-bit;
2) I now set the prefixed and PC-relative bits on by default;
3) I removed the #if around the test, and provided a definition earlier;
5) I removed the #undef in linux64.h for PCREL_SUPPORTED_BY_OS.

I have also simplified the check for prefixed and PC-relative, so that the
prefix check only checks for prefixed, and the PC-relative check is separate.

I have checked against the trunk, doing bootstrap builds and make check, and
there were no regressions.  Can I check this patch into the master branch?

2020-04-21  Michael Meissner  <meiss...@linux.ibm.com>

        * config/rs6000/linux64.h (PCREL_SUPPORTED_BY_OS): Define to
        enable PC-relative addressing for -mcpu=future.
        * config/rs6000/rs6000-cpus.def (ISA_FUTURE_MASKS_SERVER): Move
        after OTHER_FUTURE_MASKS.  Use OTHER_FUTURE_MASKS.
        * config/rs6000/rs6000.c (PCREL_SUPPORTED_BY_OS): If not defined,
        suppress PC-relative addressing.
        (rs6000_option_override_internal): Split up error messages
        checking for -mprefixed and -mpcrel.  Enable -mpcrel if the target
        system supports it.

--- /tmp/ud7l8s_linux64.h       2020-04-21 16:09:26.761209165 -0400
+++ gcc/config/rs6000/linux64.h 2020-04-21 16:04:59.432652447 -0400
@@ -640,3 +640,10 @@ extern int dot_symbols;
    enabling the __float128 keyword.  */
 #undef TARGET_FLOAT128_ENABLE_TYPE
 #define TARGET_FLOAT128_ENABLE_TYPE 1
+
+/* Enable using prefixed PC-relative addressing on the 'future' machine if the
+   ABI supports it.  The ELF v2 ABI only supports PC-relative relocations for
+   the medium code model.  */
+#define PCREL_SUPPORTED_BY_OS  (TARGET_FUTURE && TARGET_PREFIXED       \
+                                && ELFv2_ABI_CHECK                     \
+                                && (TARGET_CMODEL == CMODEL_MEDIUM))
--- /tmp/g2yeWR_rs6000-cpus.def 2020-04-21 16:09:26.772209188 -0400
+++ gcc/config/rs6000/rs6000-cpus.def   2020-04-21 16:04:59.433652450 -0400
@@ -75,16 +75,15 @@
                                 | OPTION_MASK_P8_VECTOR                \
                                 | OPTION_MASK_P9_VECTOR)
 
-/* Support for a future processor's features.  Do not enable -mpcrel until it
-   is fully functional.  */
-#define ISA_FUTURE_MASKS_SERVER        (ISA_3_0_MASKS_SERVER                   
\
-                                | OPTION_MASK_FUTURE                   \
-                                | OPTION_MASK_PREFIXED)
-
 /* Flags that need to be turned off if -mno-future.  */
 #define OTHER_FUTURE_MASKS     (OPTION_MASK_PCREL                      \
                                 | OPTION_MASK_PREFIXED)
 
+/* Support for a future processor's features.  */
+#define ISA_FUTURE_MASKS_SERVER        (ISA_3_0_MASKS_SERVER                   
\
+                                | OPTION_MASK_FUTURE                   \
+                                | OTHER_FUTURE_MASKS)
+
 /* Flags that need to be turned off if -mno-power9-vector.  */
 #define OTHER_P9_VECTOR_MASKS  (OPTION_MASK_FLOAT128_HW                \
                                 | OPTION_MASK_P9_MINMAX)
--- /tmp/KhNyMg_rs6000.c        2020-04-21 16:09:26.785209215 -0400
+++ gcc/config/rs6000/rs6000.c  2020-04-21 16:09:20.579196291 -0400
@@ -98,6 +98,11 @@
 #endif
 #endif
 
+/* Don't enable PC-relative addressing if the target does not support it.  */
+#ifndef PCREL_SUPPORTED_BY_OS
+#define PCREL_SUPPORTED_BY_OS  0
+#endif
+
 /* Support targetm.vectorize.builtin_mask_for_load.  */
 tree altivec_builtin_mask_for_load;
 
@@ -4024,15 +4029,17 @@ rs6000_option_override_internal (bool gl
       rs6000_isa_flags &= ~OPTION_MASK_FLOAT128_HW;
     }
 
-  /* -mprefixed (and hence -mpcrel) requires -mcpu=future.  */
-  if (TARGET_PREFIXED && !TARGET_FUTURE)
+  /* Enable -mprefixed by default on 'future' systems.  */
+  if (TARGET_FUTURE && (rs6000_isa_flags_explicit & OPTION_MASK_PREFIXED) == 0)
+    rs6000_isa_flags |= OPTION_MASK_PREFIXED;
+
+  /* -mprefixed requires -mcpu=future.  */
+  else if (TARGET_PREFIXED && !TARGET_FUTURE)
     {
-      if ((rs6000_isa_flags_explicit & OPTION_MASK_PCREL) != 0)
-       error ("%qs requires %qs", "-mpcrel", "-mcpu=future");
-      else if ((rs6000_isa_flags_explicit & OPTION_MASK_PREFIXED) != 0)
+      if ((rs6000_isa_flags_explicit & OPTION_MASK_PREFIXED) != 0)
        error ("%qs requires %qs", "-mprefixed", "-mcpu=future");
 
-      rs6000_isa_flags &= ~(OPTION_MASK_PCREL | OPTION_MASK_PREFIXED);
+      rs6000_isa_flags &= ~OPTION_MASK_PREFIXED;
     }
 
   /* -mpcrel requires prefixed load/store addressing.  */
@@ -4175,9 +4182,16 @@ rs6000_option_override_internal (bool gl
   SUB3TARGET_OVERRIDE_OPTIONS;
 #endif
 
+  /* If the ABI has support for PC-relative relocations, enable it by default.
+     This test depends on the sub-target tests above setting the code model to
+     medium for ELF v2 systems.  */
+  if (PCREL_SUPPORTED_BY_OS
+      && (rs6000_isa_flags_explicit & OPTION_MASK_PCREL) == 0)
+    rs6000_isa_flags |= OPTION_MASK_PCREL;
+
   /* -mpcrel requires -mcmodel=medium, but we can't check TARGET_CMODEL until
       after the subtarget override options are done.  */
-  if (TARGET_PCREL && TARGET_CMODEL != CMODEL_MEDIUM)
+  else if (TARGET_PCREL && TARGET_CMODEL != CMODEL_MEDIUM)
     {
       if ((rs6000_isa_flags_explicit & OPTION_MASK_PCREL) != 0)
        error ("%qs requires %qs", "-mpcrel", "-mcmodel=medium");

-- 
Michael Meissner, IBM
IBM, M/S 2506R, 550 King Street, Littleton, MA 01460-6245, USA
email: meiss...@linux.ibm.com, phone: +1 (978) 899-4797

Reply via email to