[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:56:46 PDT 2022
mstorsjo added a comment.
In D135687#3850753 <https://reviews.llvm.org/D135687#3850753>, @efriedma wrote:
> I was thinking you could do something like this:
>
> mov x15, #(NumBytes/16) ; Stack allocation size
> mov x9, sp
> and x9, x9, #AlignMask ; compute aligned stack
> sub x9, sp, x9 ; compute number of bytes required to align stack
> add x15, x15, x9, lsr #4 ; add bytes to chkstk input
> bl __chkstk
> sub sp, sp, x15, lsl #4
>
> There's probably some slightly more efficient way to write this, but that's the idea.
Hmm, ok, I see. I guess that'd work, but it feels a bit roundabout IMO.
It looks like MSVC does something like this:
mov x15, #(NumBytes+Align)/16
bl __chkstk
sub sp, sp, x15, lsl #4
mov x8, sp
add x9, x8, #(Align-1)
and x0, x9, #AlignMask
(The `mov x8, sp` feels superfluous here?) It doesn't align the stack pointer itself, but I think we should be able to do the same (while wasting fewer registers) by doing the last `and` into `sp`.
I think I'd prefer something like this:
mov x15, #(NumBytes+Align)/16
bl __chkstk
sub sp, sp, x15, lsl #4
add x9, sp, #(Align -1)
and sp, x9, #AlignMask
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