]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
xtensa: constantsynth: Exclude the stack pointer
authorTakayuki 'January June' Suwa <jjsuwa_sys3175@yahoo.co.jp>
Fri, 20 Feb 2026 12:17:15 +0000 (21:17 +0900)
committerMax Filippov <jcmvbkbc@gmail.com>
Sat, 21 Feb 2026 23:35:43 +0000 (15:35 -0800)
When updating the value of the stack pointer through a sequence of instruc-
tions, only the last instruction in the sequence must modify the stack
pointer, because the stack pointer may be referenced by an interrupt or
other event during the sequence:

     /* example */
     register void *stack_ptr asm ("a1");
     void test(void) {
       stack_ptr = (void *)0x04000000;
     }

     ;; before (-O -mabi=call0)
     test:
      movi.n sp, 1 ;; An interrupt may occur
      slli sp, sp, 26 ;; between these instructions
      ret.n

This patch avoids this problem by excluding constant value assignments to
the stack pointer from 'constantsynth'.

     ;; after (-O -mabi=call0)
      .literal_position
      .literal .LC0, 67108864
     test:
      l32r sp, .LC0
      ret.n

gcc/ChangeLog:

* config/xtensa/xtensa.cc (constantsynth_pass1):
Add the case where the assignment destination is a stack pointer
to the exclusion criteria for processing.

gcc/config/xtensa/xtensa.cc

index ff3801194fdea9789e4effed3c646ce9c13d9fed..c2a6a1610662cdf97b04dd2b934940b7f4e7af23 100644 (file)
@@ -6028,7 +6028,7 @@ constantsynth_pass1 (rtx_insn *insn, constantsynth_info &info)
      constant.  */
   if (GET_CODE (pat = PATTERN (insn)) != SET
       || ! REG_P (dest = SET_DEST (pat)) || ! GP_REG_P (REGNO (dest))
-      || GET_MODE (dest) != SImode
+      || GET_MODE (dest) != SImode || rtx_equal_p (dest, stack_pointer_rtx)
       || ! CONST_INT_P (src = avoid_constant_pool_reference (SET_SRC (pat))))
     return false;