[llvm] [AArch64] Fix SVE callee-save layout for nounwind functions on Windows (PR #156467)

Benjamin Maxwell via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 2 08:12:29 PDT 2025


================
@@ -355,6 +355,28 @@ static bool isLikelyToHaveSVEStack(const MachineFunction &MF) {
   return false;
 }
 
+static bool isTargetWindows(const MachineFunction &MF) {
+  return MF.getSubtarget<AArch64Subtarget>().isTargetWindows();
+}
+
+// Windows unwind can't represent the required stack adjustments if we have
+// both SVE callee-saves and dynamic stack allocations, and the frame
+// pointer is before the SVE spills.  The allocation of the frame pointer
+// must be the last instruction in the prologue so the unwinder can restore
+// the stack pointer correctly. (And there isn't any unwind opcode for
+// `addvl sp, x29, -17`.)
+//
+// Because of this, we do spills in the opposite order on Windows: first SVE,
+// then GPRs. The main side-effect of this is that it makes accessing
+// parameters passed on the stack more expensive.
+//
+// We could consider rearranging the spills for simpler cases.
+static bool hasSVECalleeSavesAboveFrameRecord(const MachineFunction &MF) {
+  auto *AFI = MF.getInfo<AArch64FunctionInfo>();
+  return isTargetWindows(MF) && AFI->getSVECalleeSavedStackSize() &&
+         needsWinCFI(MF);
----------------
MacDue wrote:

nit: I think this could just be:
```suggestion
  return AFI->getSVECalleeSavedStackSize() && needsWinCFI(MF);
```

https://github.com/llvm/llvm-project/pull/156467


More information about the llvm-commits mailing list