https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94173
Bug ID: 94173 Summary: [RISCV] Superfluous stackpointer manipulation Product: gcc Version: 9.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: gcc at gms dot tf Target Milestone: --- Created attachment 48033 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48033&action=edit demonstrate how bar function yields superfluous stackpointer instructions GCC emits stackpointer decrement/increment instructions in some functions where they are superfluous. Example: struct Pair { char *s; char *t; }; typedef struct Pair Pair; Pair bar(char *s, char *t) { return (Pair){s, t}; } Expected assembly: 0000000000000002 <bar>: 2: 8082 ret Actual assembly: 0000000000000002 <bar>: 2: 1141 addi sp,sp,-16 4: 0141 addi sp,sp,16 6: 8082 ret Notes: In an example where the function just returns one value the assembly code actually just contain the expected assenbly code: char *foo(char *s, char *t) { return s; } Note that per the RISC-V calling-conventions up to 2 integer like values are returned via the a0/a1 registers, i.e. the same registers where also the first 2 function arguments are placed. FWIW, Clang 9.0.1 generates for both examples the expected code without superfluous stackpointer adjustments. Example code is attched. I tested with: riscv64-linux-gnu-gcc -O3 -c -o pair.o pair.c