Skip to content

Function calling convention: Unnecessary MOVSP instruction (LLVM-65) #19

Closed
@inetbowser

Description

@inetbowser

When using Zig (https://github.com/ziglang/zig) with the Xtensa LLVM backend, I noticed that all functions use the calling convention below. The code works flawlessly but I think the MOVSP instruction can be omitted because the register window of the function guarantees the stack pointer will stay the same.

Code (compiled with Zig and Xtensa LLVM backend):

40080984 <testfn>:
40080984:	007136        	entry	a1, 56
40080987:	017d      	mov.n	a7, a1
40080989:	...    // some code
400809ce:	001710        	movsp	a1, a7
400809d1:	f01d      	retw.n

When compiling some function with the standard GCC C compiler a function is structured something like this.

Code (compiled with xtensa-esp32-elf-gcc):

004001a4 <testfn>:
  4001a4:	006136        	entry	a1, 48
  4001a7:	017d      	mov.n	a7, a1
  4001a9:	...    // some code
  4001d2:	f01d      	retw.n

As you can see there is no MOVSP instruction.

Although this is not a critical bug (it doesn't crash the program nor introduce undefined behaviour), this can decrease performance of a program significantly because the MOVSP instruction can cause an Alloca exception (which could hit performance quite hard).

If I'm mistaken at some point, feel free to let me know. I'm quite a newbie with the Xtensa architecture. 😄

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions