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

Martin Storsjö via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 11 14:13:49 PDT 2022


mstorsjo added a comment.

In D135687#3850352 <https://reviews.llvm.org/D135687#3850352>, @mstorsjo wrote:

> In D135687#3850040 <https://reviews.llvm.org/D135687#3850040>, @efriedma wrote:
>
>> In general, I think we need to pass the number of bytes required for realignment to __chkstk, instead of directly realigning the stack.  As discussed on the bug.
>
> Oh, right, I didn't realize that we could fix that part of the requirement that easily.

Actually, on second thought, either this requires a bit more changes than that (deviating more from the pattern for how `__chkstk` is used) or it doesn't actually fulfill the intent you have here (or I'm still overlooking something).

Currently, the call to `__chkstk` looks like this:

  mov x15, #(NumBytes/16)
  bl __chkstk
  sub sp, sp, x15, lsl #4

If we'd include the alignment in the probing, it'd look like this:

  mov x15, #((NumBytes+Align)/16)
  bl __chkstk
  sub x15, sp, x15, lsl #4
  and sp, x15, #(AlignMask)

Here, the call to `__chkstk` does cover the extra align amount, but we also decrement the stack pointer by that amount, so when doing the alignment masking, we can still decrement the stack pointer further past what's been probed. To avoid this, I guess we'd need to add an `sub x15, x15, #(Align/16)` after the call, before decrementing the stack. Is that how you meant it?


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