If the adjustment doesn't fit in 12 bits, try to break it into
two 12 bit values before falling back to movImm+add/sub.
This is based on a similar idea from isel.
Differential D126392
[RISCV] Use two ADDIs to do some stack pointer adjustments. craig.topper on May 25 2022, 9:54 AM. Authored by
Details If the adjustment doesn't fit in 12 bits, try to break it into This is based on a similar idea from isel.
Diff Detail
Event TimelineComment Actions Doesn't this run the risk of temporarily misaligning the stack (e.g. for Val == 2064)? The psABI says using such a non-standard ABI within a function is fine and that kernels should realign stacks before calling signal handlers. Both FreeBSD and Linux correctly do this for signal handlers so as to not make assumptions about whether userspace is following the standard ABI, but both assume that the kernel itself is following the standard ABI, and so do not realign the stack in their exception entry points, causing the stack to be misaligned if an interrupt is taken in between. Whether this is a bug or not in the kernels is debatable, but with a more careful splitting of Val it should be possible to avoid anyway, with the exception of 4080? Comment Actions For reference, this is the exact text in the psABI spec:
Comment Actions Good point. I copied the split from what we do in isel without thinking about it. I'll try a better split. Comment Actions Instead of dividing in half, use a large immediate, either -2048 or (2048-stackalign),
Comment Actions This may break assumptions that some unwinding code uses (e.g. an kernel backtrace without debug info). But then again I don't know if any of them handle non-immediate offsets anyway. Comment Actions What do you mean? Unwinding with neither the frame pointer nor CFI?
Comment Actions Yeah I've seen such implementations for MIPS, maybe there are some for RISC-V too. This was not meant as a request to change anything, no one should rely on specific code generation patterns unless it's mandated by a specification. Comment Actions LGTM. Minor optional comment from me, and remember to address nit from previous reviewer before landing.
Comment Actions Minor improvement noted after LGTM. Feel free to roll into approved patch if you agree with my comment.
|
Nit: MaxAdj -> MaxAdjStep