[gcc r17-2598] xtensa: Define LOCAL_REGNO() macro

Max Filippov via Gcc-cvs <[email protected]>
Newsgroups gmane.comp.gcc.cvs
Message-ID <[email protected]>
https://gcc.gnu.org/g:c8c3988ef66c112defe86dcd23e6679d39814587

commit r17-2598-gc8c3988ef66c112defe86dcd23e6679d39814587
Author: Takayuki 'January June' Suwa <[email protected]>
Date:   Sat Jul 18 05:37:13 2026 +0900

    xtensa: Define LOCAL_REGNO() macro
    
    When the Windowed Register Option (TARGET_WINDOWED_ABI) is enabled, and this
    macro is not defined, "phantom" DF livenesses occurs in the function epilogue,
    which can hinder certain optimizations.  Indeed, in the following example,
    the low-overhead loop optimization is rejected because the epilogue BB, which
    succeeds the target loop BB, is incorrectly identified as using the loop
    iterator.
    
         /* example */
         void test(char *q, const char *p, unsigned int n) {
           do
             *q = *p, ++q, ++p;
           while (n-- != 1);
         }
    
         ;; before (-mabi=windowed ; TARGET_LOOPS)
         test:
            entry   sp, 32
            movi.n  a8, 0
         .L2:
            add.n   a9, a3, a8
            l8ui    a10, a9, 0
            add.n   a9, a2, a8
            s8i     a10, a9, 0
            addi.n  a8, a8, 1
            addi.n  a4, a4, -1
            bnez.n  a4, .L2         ;; incorrectly identified as using A4
                                    ;; in the epilogue.
            retw.n
    
    This patch fixes the above issue by properly defining the relevant macro.
    
         ;; after (-mabi=windowed ; TARGET_LOOPS)
         test:
            entry   sp, 32
            movi.n  a8, 0
            loop    a4, .L2_LEND
         .L2:
            add.n   a9, a3, a8
            l8ui    a10, a9, 0
            add.n   a9, a2, a8
            s8i     a10, a9, 0
            addi.n  a8, a8, 1
            .L2_LEND:
            retw.n
    
    gcc/ChangeLog:
    
            * config/xtensa/xtensa.h (LOCAL_REGNO):
            New macro definition.

Diff:
---
 gcc/config/xtensa/xtensa.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/gcc/config/xtensa/xtensa.h b/gcc/config/xtensa/xtensa.h
index 3b33d69bf210..00bb9e06e2e9 100644
--- a/gcc/config/xtensa/xtensa.h
+++ b/gcc/config/xtensa/xtensa.h
@@ -344,6 +344,9 @@ along with GCC; see the file COPYING3.  If not see
      ((unsigned) ((IN) - GP_REG_FIRST) < WINDOW_SIZE)) ?		\
     (IN) + WINDOW_SIZE : (IN)) : (IN))
 
+#define LOCAL_REGNO(REGNO)						\
+  (TARGET_WINDOWED_ABI && GP_REG_P (REGNO)				\
+   && ((unsigned) ((REGNO) - GP_REG_FIRST) < WINDOW_SIZE))
 
 /* Define the classes of registers for register constraints in the
    machine description.  */
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.