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

commit r16-8456-gf6e1788dec14dc8efb49c7cf8cff62b979105b1c
Author: Takayuki 'January June' Suwa <[email protected]>
Date:   Fri Apr 3 08:08:52 2026 +0900

    xtensa: Avoid redundant MEM_P() checks in memory constraint definitions
    
    If the memory constraint definition includes (match_code "MEM"), then
    the subsequent 'op' is undoubtedly MEM rtx, and all that remains is to
    determine if 'XEXP (op, 0)' is the address corresponding to that
    definition using (match_test "...").
    
    This patch eliminates the need to call MEM_P() again in the predicate
    function called from (match_test "...") in the memory constraint
    definitions.
    
    gcc/ChangeLog:
    
            * config/xtensa/xtensa.cc (smalloffset_mem_p):
            Rename it to smalloffset_address_p and remove the result check
            of MEM_P().
            (constantpool_address_p): Change from static scope to global.
            * config/xtensa/xtensa-protos.h (smalloffset_mem_p):
            Rename it to smalloffset_address_p.
            (constantpool_address_p): New function prototype.
            * config/xtensa/constraints.md (R):
            Change the call in (match_test "...") from smalloffset_mem_p()
            to smalloffset_address_p().
            (T, U): Change the call in (match_test "...") from
            constantpool_mem_p() to constantpool_address_p().

Diff:
---
 gcc/config/xtensa/constraints.md  |  6 +++---
 gcc/config/xtensa/xtensa-protos.h |  3 ++-
 gcc/config/xtensa/xtensa.cc       | 40 +++++++++++++++++++--------------------
 3 files changed, 24 insertions(+), 25 deletions(-)

diff --git a/gcc/config/xtensa/constraints.md b/gcc/config/xtensa/constraints.md
index 5cf2f198c5f5..81305074b648 100644
--- a/gcc/config/xtensa/constraints.md
+++ b/gcc/config/xtensa/constraints.md
@@ -129,14 +129,14 @@
 (define_special_memory_constraint "R"
  "Memory that can be accessed with a 4-bit unsigned offset from a register."
  (and (match_code "mem")
-      (match_test "smalloffset_mem_p (op)")))
+      (match_test "smalloffset_address_p (XEXP (op, 0))")))
 
 (define_special_memory_constraint "T"
  "Memory in a literal pool (addressable with an L32R instruction)."
  (and (match_code "mem")
-      (match_test "!TARGET_CONST16 && constantpool_mem_p (op)")))
+      (match_test "!TARGET_CONST16 && constantpool_address_p (XEXP (op, 0))")))
 
 (define_special_memory_constraint "U"
  "Memory that is not in a literal pool."
  (and (match_code "mem")
-      (match_test "! constantpool_mem_p (op)")))
+      (match_test "! constantpool_address_p (XEXP (op, 0))")))
diff --git a/gcc/config/xtensa/xtensa-protos.h 
b/gcc/config/xtensa/xtensa-protos.h
index f41f32f18acb..034549b61e06 100644
--- a/gcc/config/xtensa/xtensa-protos.h
+++ b/gcc/config/xtensa/xtensa-protos.h
@@ -35,7 +35,8 @@ extern bool xtensa_mem_offset (unsigned, machine_mode);
 #ifdef RTX_CODE
 extern int xt_true_regnum (rtx);
 extern int xtensa_valid_move (machine_mode, rtx *);
-extern int smalloffset_mem_p (rtx);
+extern bool smalloffset_address_p (const_rtx);
+extern bool constantpool_address_p (const_rtx);
 extern int constantpool_mem_p (rtx);
 extern void xtensa_extend_reg (rtx, rtx);
 extern void xtensa_expand_conditional_branch (rtx *, machine_mode);
diff --git a/gcc/config/xtensa/xtensa.cc b/gcc/config/xtensa/xtensa.cc
index 235b4e0446d4..dbbea0799da7 100644
--- a/gcc/config/xtensa/xtensa.cc
+++ b/gcc/config/xtensa/xtensa.cc
@@ -165,7 +165,6 @@ static reg_class_t xtensa_secondary_reload (bool, rtx, 
reg_class_t,
                                            machine_mode,
                                            struct secondary_reload_info *);
 
-static bool constantpool_address_p (const_rtx addr);
 static bool xtensa_legitimate_constant_p (machine_mode, rtx);
 static void xtensa_reorg (void);
 static bool xtensa_can_use_doloop_p (const widest_int &, const widest_int &,
@@ -563,32 +562,31 @@ xtensa_valid_move (machine_mode mode, rtx *operands)
 }
 
 
-int
-smalloffset_mem_p (rtx op)
+bool
+smalloffset_address_p (const_rtx addr)
 {
-  if (MEM_P (op))
+  if (REG_P (addr))
+    return BASE_REG_P (addr, 0);
+
+  if (GET_CODE (addr) == PLUS)
     {
-      rtx addr = XEXP (op, 0);
-      if (REG_P (addr))
-       return BASE_REG_P (addr, 0);
-      if (GET_CODE (addr) == PLUS)
-       {
-         rtx offset = XEXP (addr, 0);
-         HOST_WIDE_INT val;
-         if (! CONST_INT_P (offset))
-           offset = XEXP (addr, 1);
-         if (! CONST_INT_P (offset))
-           return FALSE;
-
-         val = INTVAL (offset);
-         return (val & 3) == 0 && IN_RANGE (val, 0, 60);
-       }
+      rtx offset = XEXP (addr, 0);
+      HOST_WIDE_INT val;
+
+      if (! CONST_INT_P (offset))
+       offset = XEXP (addr, 1);
+      if (! CONST_INT_P (offset))
+       return false;
+
+      val = INTVAL (offset);
+      return (val & 3) == 0 && IN_RANGE (val, 0, 60);
     }
-  return FALSE;
+
+  return false;
 }
 
 
-static bool
+bool
 constantpool_address_p (const_rtx addr)
 {
   const_rtx sym = addr;

Reply via email to