]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
xtensa: Define LOCAL_REGNO() macro
authorTakayuki 'January June' Suwa <jjsuwa_sys3175@yahoo.co.jp>
Fri, 17 Jul 2026 20:37:13 +0000 (05:37 +0900)
committerMax Filippov <jcmvbkbc@gmail.com>
Tue, 21 Jul 2026 19:49:05 +0000 (12:49 -0700)
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.

gcc/config/xtensa/xtensa.h

index 3b33d69bf210a3fe717a74692b983d58bf87de16..00bb9e06e2e914968eeaadd066ce8771cba8d5b4 100644 (file)
@@ -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.  */