]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
xtensa: Define HONOR_REG_ALLOC_ORDER as 1
authorTakayuki 'January June' Suwa <jjsuwa_sys3175@yahoo.co.jp>
Fri, 8 May 2026 21:04:48 +0000 (06:04 +0900)
committerMax Filippov <jcmvbkbc@gmail.com>
Mon, 11 May 2026 15:17:05 +0000 (08:17 -0700)
Since the commit of the preceding patch for IRA, "ira: Scale save/restore
costs of callee save registers with block frequency" (3b9b8d6cfdf59337f4b7ce10ce92a98044b2657b),
the Xtensa ISA has shown a tendency to allocate slightly more function stack
frames, especially when using the CALL0 ABI.

     /* example */
     extern void foo(void);
     int test(int a) {
       int array[252];
       foo();
       asm volatile (""::"m"(array));
       return a;
     }

     ;; before (-O2 -mabi=call0)
     test:
      addi sp, sp, -16
      s32i.n a0, sp, 12
      addmi sp, sp, -0x400
      s32i a2, sp, 1008
      call0 foo
      l32i a2, sp, 1008
      addmi sp, sp, 0x400
      l32i.n a0, sp, 12
      addi sp, sp, 16
      ret.n

This patch disables the incorrect register save cost estimation in function
prologues/epilogues by defining the HONOR_REG_ALLOC_ORDER macro as 1.

     ;; after (-O2 -mabi=call0)
     test:
      addmi sp, sp, -0x400
      s32i a0, sp, 1020
      s32i a2, sp, 1016
      call0 foo
      l32i a2, sp, 1016
      l32i a0, sp, 1020
      addmi sp, sp, 0x400
      ret.n

gcc/ChangeLog:

* config/xtensa/xtensa.h (HONOR_REG_ALLOC_ORDER):
New macro definition.

gcc/testsuite/ChangeLog:

* gcc.target/xtensa/elim_callee_saved.c:
Revise the test item for the number of mov instructions in the
assembler output.

gcc/config/xtensa/xtensa.h
gcc/testsuite/gcc.target/xtensa/elim_callee_saved.c

index 2bf43f7af42ce3ffc46997265f8f7bf44fb62ddc..3b33d69bf210a3fe717a74692b983d58bf87de16 100644 (file)
@@ -254,6 +254,10 @@ along with GCC; see the file COPYING3.  If not see
 }
 #define ADJUST_REG_ALLOC_ORDER xtensa_adjust_reg_alloc_order ()
 
+/* Tell IRA to use the order we define rather than messing it up with its
+   own cost calculations.  */
+#define HONOR_REG_ALLOC_ORDER 1
+
 /* Internal macros to classify a register number.  */
 
 /* 16 address registers + fake registers */
index cd3d6b9f2496fbfe6f09302e280c3c012c32ef26..69e5be35dfd0f699aca1a1bfbf62dc05310f6cfb 100644 (file)
@@ -34,5 +34,5 @@ int __attribute__((optimize(0))) test3(int a) {
   return bar() + a;
 }
 
-/* { dg-final { scan-assembler-times "mov\t|mov.n\t" 21 } } */
+/* { dg-final { scan-assembler-times "mov\t|mov.n\t" 20 } } */
 /* { dg-final { scan-assembler-times "a15, 8" 2 } } */