https://gcc.gnu.org/g:ea7962211ffa96fc13cf8eba60c396a3cf9dfd97

commit ea7962211ffa96fc13cf8eba60c396a3cf9dfd97
Author: Michael Meissner <meiss...@linux.ibm.com>
Date:   Mon Jun 16 19:30:47 2025 -0400

    PR target/120681 - allow -mcmodel=large with prefixed addressing
    
    When I implemented the pc-relative support for power10 in GCC, I disabled 
using
    pc-relative support for -mcmodel=large.  At the time, I didn't want to  dig 
into
    the issues.  It is now time to allow -mcmodel=large to generate pc-relative
    code.
    
    This patch allows -mcmodel=large to use prefixed addressing on power10, 
power11,
    and possibly other future PowerPC processors.
    
    This patch deletes the code that disallows -mprefixed and -mcmodel=large.  
By
    deleting the code, it allows the normal pc-relative addressing to be used.  
For
    static variables, pc-relative addressing will be used.  For external 
variables,
    we will generate the normal code that uses '@got@pcrel' addressing to load 
up
    the external address and use this address as a pointer to do the load or 
store.
    
    2025-06-16  Michael Meissner  <meiss...@linux.ibm.com>
    
    gcc/
    
            PR target/120681
            * config/rs6000/rs6000.cc (rs6000_option_override_internal): Delete 
code
            that forced using TOC addressing for -mcmodel=large instead of
            pc-relative addressing.
    
    gcc/testsuite/
    
            PR target/120681
            * gcc.target/powerpc/pr120681.c: New test.

Diff:
---
 gcc/config/rs6000/rs6000.cc                 | 10 ----------
 gcc/testsuite/gcc.target/powerpc/pr120681.c | 31 +++++++++++++++++++++++++++++
 2 files changed, 31 insertions(+), 10 deletions(-)

diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc
index 80fc500fcec8..a268e0d17b5f 100644
--- a/gcc/config/rs6000/rs6000.cc
+++ b/gcc/config/rs6000/rs6000.cc
@@ -4360,16 +4360,6 @@ rs6000_option_override_internal (bool global_init_p)
       && (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.  */
-  else if (TARGET_PCREL && TARGET_CMODEL != CMODEL_MEDIUM)
-    {
-      if ((rs6000_isa_flags_explicit & OPTION_MASK_PCREL) != 0)
-       error ("%qs requires %qs", "-mpcrel", "-mcmodel=medium");
-
-      rs6000_isa_flags &= ~OPTION_MASK_PCREL;
-    }
-
   /* Enable -mmma by default on power10 systems.  */
   if (TARGET_POWER10 && (rs6000_isa_flags_explicit & OPTION_MASK_MMA) == 0)
     rs6000_isa_flags |= OPTION_MASK_MMA;
diff --git a/gcc/testsuite/gcc.target/powerpc/pr120681.c 
b/gcc/testsuite/gcc.target/powerpc/pr120681.c
new file mode 100644
index 000000000000..ad0bd64ceeaf
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/pr120681.c
@@ -0,0 +1,31 @@
+/* { dg-require-effective-target power10_ok } */
+/* { dg-options "-mdejagnu-cpu=power10 -O2 -mcmodel=large" } */
+
+/* PR target/120681 -- verify that -mcpu=power10 -mcmodel=large uses prefixed
+   addressing instead of forcing using TOC addressing.  */
+
+#ifndef TYPE
+#define TYPE unsigned long
+#endif
+
+extern TYPE global_var;
+
+void
+set_global (TYPE value)
+{
+  /*
+   * Generate:
+   * pld 9,global_var@got@pcrel
+   * std 3,0(9)
+   *
+   * Not:
+   * addis 9,2,.LC0@toc@ha
+   * ld    9,.LC0@toc@l(9)
+   * std   3,0(9)
+   */
+
+  global_var = value;
+}
+
+/* { dg-final { scan-assembler     {@got@pcrel} } } */
+/* { dg-final { scan-assembler-not {@toc}       } } */

Reply via email to