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

Eli Friedman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 12 12:43:16 PDT 2022


efriedma added a comment.

Oh, to account for unaligned NumBytes, my solution would have to be something more like:

  sub x15, sp, #NumBytes
  and x15, x15, #AlignMask
  sub x15, sp, x15
  lsr x15, x15, lsr #4
  bl __chkstk
  sub sp, sp, x15, lsl #4

(If NumBytes is large, add 1 or 2 instructions to materialize it.)  Maybe emitting extra instructions to avoid overallocating isn't worth it, though...



================
Comment at: llvm/lib/Target/AArch64/AArch64FrameLowering.cpp:1654
+  if (windowsRequiresStackProbe(MF, NumBytes + RealignmentBytes)) {
+    uint64_t NumWords = (NumBytes + RealignmentBytes) >> 4;
     if (NeedsWinCFI) {
----------------
This is allocating more than necessary?  We only really need to add `RealignmentBytes ? RealignmentBytes - 16 : 0` bytes.


================
Comment at: llvm/lib/Target/AArch64/AArch64FrameLowering.cpp:1760
+      // NrBitsToZero zero bits as least significant bits.
+      uint32_t andMaskEncoded = (1 << 12)                         // = N
+                                | ((64 - NrBitsToZero) << 6)      // immr
----------------
We have a helper for this: AArch64_AM::encodeLogicalImmediate.


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