https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108016
--- Comment #13 from Alexey Merzlyakov <alexey.merzlyakov at samsung dot com> --- > There is https://gcc.gnu.org/pipermail/gcc-patches/2024-August/660968.html > which (though I am not 100% sure) will help the situtation. Thank you for the reference, this definitely makes sense. If I understood correctly, this patch does 2 things: re-assignment of function input arguments passed from registers and making the return value to be passed via output register(s). The first thing of the patch caused unnecessary SP addressing for RISC-V on the example like: typedef struct { long long a[4]; } A; typedef struct { A a; long long b; } B; A fun6 (const B b) { return b.a; } ... as it seem to make rhs part of the input arg as MEM_REF type, that will be reflected on the frame by "expand" and optimized-out by "DSE" later; but still unnecessary SP-allocation will remain. However, the second part of optimization of the returning value to be passed via register(s) seems to be exactly what we need. The patch fixes all local cases with return values I have, including the cases where return structure is being fully packed on an output register that my previously proposed optimization did not. FSRA patch still not resolve "Item2" case reported above, but fixes "Item1" (I believe that for "Item2" frame_offset could be re-calculated during FSRA stage when optimizing output parameters, but this need to be additionally checked). The patch seem to be abandoned since Sep-2024, so not sure how could we go on, maybe contact author of the original patch about upstream plans.