public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/vendors/ARM/heads/morello)] aarch64: Avoid generating PC-relative stores
@ 2022-05-06 14:45 Matthew Malcomson
  0 siblings, 0 replies; only message in thread
From: Matthew Malcomson @ 2022-05-06 14:45 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:021d8d117cbe7e5f1dbc4d3ac5ff28ddef25b740

commit 021d8d117cbe7e5f1dbc4d3ac5ff28ddef25b740
Author: Richard Sandiford <richard.sandiford@arm.com>
Date:   Thu Apr 28 18:25:30 2022 +0100

    aarch64: Avoid generating PC-relative stores
    
    c675754a1788ddd741fb310d8d7ee612b95264f5 regressed -mcmodel=tiny
    by allowing PC-relative stores such as “str x0, foo”, whereas
    only PC-relative loads are supported.  Previously
    aarch64_classify_address had:
    
          if (ldp_stp_mode == VOIDmode
              && GET_MODE_SIZE (mode).is_constant (&const_size)
              && const_size >= 4)
            {
              rtx sym, addend;
    
              split_const (x, &sym, &addend);
              return (GET_CODE (sym) == LABEL_REF
                       || (GET_CODE (sym) == SYMBOL_REF
                           && aarch64_pcrelative_literal_loads
                           && aarch64_function_literal_pool_address_p (x)));
            }
    
    and so allowed references to labels (which should never be needed here)
    and references to function literal pools.  The patch instead made the
    code test whether x is SYMBOL_TINY_ABSOLUTE, which is needed for
    -mcmodel=tiny references to .capinit entries in .data.rel.ro.
    
    However, as the fallout shows, we still need the test for a constant
    pool entry.  It just doesn't need to be in the function literal pool.
    
    As the comment in the patch says, this is really a hack.  The
    pre-Morello handling of -mcmodel=tiny means that we generate:
    
            adr     x0, foo
            ldr     x0, [x0]
    
    even though:
    
            ldr     x0, foo
    
    would be OK too.  But fixing things so that we generate that
    without:
    
            str     x0, foo
    
    would be too much of a distraction.  It's also something that
    should happen on trunk first.

Diff:
---
 gcc/config/aarch64/aarch64.c                     | 13 ++++++++++++-
 gcc/testsuite/gcc.target/aarch64/cmodel-tiny-1.c |  5 +++++
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c
index 852564b8f0c..2ddfb819899 100644
--- a/gcc/config/aarch64/aarch64.c
+++ b/gcc/config/aarch64/aarch64.c
@@ -10064,7 +10064,18 @@ aarch64_classify_address (struct aarch64_address_info *info,
 	  && GET_MODE_SIZE (mode).is_constant (&const_size)
 	  && const_size >= 4
 	  && aarch64_classify_symbolic_expression (x) == SYMBOL_TINY_ABSOLUTE)
-	return true;
+	{
+	  /* ??? This is a bit of a hack.  All SYMBOL_TINY_ABSOLUTE loads
+	     should be in range, not just function constant pool entries.
+	     However, to handle that properly, we would need to distinguish
+	     between load and store contexts.  This would probably mean
+	     defining TARGET_MEM_CONSTRAINT to something other than "m",
+	     keeping the current meaning of "m", and having a more relaxed
+	     constraint than "m" for loads.  */
+	  rtx base = strip_offset (x, &offset);
+	  if (SYMBOL_REF_P (base) && CONSTANT_POOL_ADDRESS_P (base))
+	    return true;
+	}
       return false;
 
     case LO_SUM:
diff --git a/gcc/testsuite/gcc.target/aarch64/cmodel-tiny-1.c b/gcc/testsuite/gcc.target/aarch64/cmodel-tiny-1.c
new file mode 100644
index 00000000000..18c2c56c184
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/cmodel-tiny-1.c
@@ -0,0 +1,5 @@
+/* { dg-do assemble } */
+/* { dg-options "-O2 -mcmodel=tiny" } */
+
+int x[5];
+void f() { x[3] = 1; }


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

only message in thread, other threads:[~2022-05-06 14:45 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-06 14:45 [gcc(refs/vendors/ARM/heads/morello)] aarch64: Avoid generating PC-relative stores Matthew Malcomson

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