Fix alignment of partially-passed stack arguments
Corrects stack argument alignment for arguments passed partially via registers and stack.
This commit fixes an alignment issue in GCC where arguments passed partially through registers and partially on the stack were not correctly aligned. The assign_parm_find_stack_rtl function previously used the full argument boundary for alignment, even when only part of the argument was on the stack. This led to incorrect memory accesses, such as misaligned loads/stores on RISC-V. The fix clamps the alignment to the actual size of the portion on the stack, ensuring correct memory referencing and resolving issues with specific RISC-V instructions.
In Details
The assign_parm_find_stack_rtl function in function.cc reconstructs partially passed arguments by spilling register portions below aligned stack slots. It incorrectly propagated data.locate.boundary to the reconstructed MEM's alignment, even for partial arguments where only a fraction occupied the stack. This resulted in over-stated alignment (e.g., A64 on RV32 for a DImode argument split between register and stack). The fix clamps the alignment to the partial size, resolving a RISC-V zilsd issue (PR 127598) where an over-stated MEM_ALIGN caused misaligned ld/sd instructions b…
- stack argument
- A function argument that is passed by placing its value onto the program's call stack.
- register argument
- A function argument passed through CPU registers, which is typically faster than using the stack.
- RTL
- Register Transfer Language. GCC's internal intermediate representation used to represent code after register allocation.
- MEM
- In GCC's RTL, MEM represents a memory reference.
- alignment
- The requirement that data in memory be placed at addresses that are multiples of a certain value (e.g., word alignment, double-word alignment), often for performance or hardware reasons.
- RISC-V
- An open-standard instruction set architecture based on Reduced Instruction Set Computing principles.
- zilsd
- A RISC-V extension ('Z' for extension, 'ilsd' likely relating to instructions for load/store operations) that provides specific instructions for atomic load and store operations, potentially with byte-level alignment guarantees.