[PATCH] D135687: [AArch64] Fix aligning the stack after calling __chkstk

Martin Storsjö via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 12 05:21:22 PDT 2022


mstorsjo added a comment.

In D135687#3850987 <https://reviews.llvm.org/D135687#3850987>, @efriedma wrote:

> After staring at my code sequence a bit more, it simplifies to:
>
>   mov x15, #(NumBytes/16)
>   mov x9, sp
>   ubfx x9, x9, #4, #AlignBits
>   add x15, x15, x9
>   bl __chkstk
>   sub sp, sp, x15, lsl #4
>
> Your suggested sequence also works, I guess, but it feels a little weird to overallocate, then deallocate the extra memory.

Yeah, that's a bit clumsy (but the amount of extra instructions is quite small).

I find your suggestion very neat, but it assumes that `NumBytes` itself is aligned to the alignment, otherwise we break the realignment we calculated from the actual stack pointer. In practice it isn't - the total allocation of the stack frame (including CSRs) is aligned, but NumBytes isn't. And trying to calculate how much is spent on the other bits and adjusting it here feels very brittle too. To counter that, we'd have to overallocate the chkstk amount to make sure that it is aligned on its own, and that's not very pretty either.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D135687/new/

https://reviews.llvm.org/D135687



More information about the llvm-commits mailing list