On Fri, Feb 20, 2026 at 4:17 AM Takayuki 'January June' Suwa
<[email protected]> wrote:
>
> 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 | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)

Regtested for target=xtensa-linux-uclibc, no new regressions.
Committed to master.

-- 
Thanks.
-- Max

Reply via email to