| Issue |
238193
|
| Summary |
[AArch64][Windows] Scalable (SVE) stack allocations are never probed with __chkstk
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
zjy-dev
|
On `aarch64-pc-windows-msvc`, fixed frames of at least 4 KiB are probed through `__chkstk`. Scalable stack areas (SVE locals
and scalable spill slots) are allocated with bare `addvl sp, sp, #-N` and no probe of any kind, no matter how large they are.
A 512 x VL-byte scalable local (at least 8 KiB, even at the minimum VL) moves SP across several guard pages
before anything touches the stack.
```llvm
target triple = "aarch64-pc-windows-msvc"
declare void @sink(ptr)
define void @scalable_local() "target-features"="+sve" {
%a = alloca [512 x <vscale x 16 x i8>], align 16 ; >= 8 KiB
call void @sink(ptr %a)
ret void
}
define void @fixed_local() "target-features"="+sve" {
%a = alloca [8192 x i8], align 16 ; control
call void @sink(ptr %a)
ret void
}
```
Compile flag: `llc -O2 trigger.ll`
```asm
scalable_local:
str x28, [sp, #-16]!
str x30, [sp, #8]
addvl sp, sp, #-32 // x16 in a row: SP drops by 512*VL bytes, no __chkstk, no probe
...
mov x0, sp
bl sink
fixed_local:
mov x15, #512
bl __chkstk // fixed 8 KiB frame is probed
sub sp, sp, x15, lsl #4
```
The same happens with C (`__SVInt8_t` locals, `clang --target=aarch64-pc-windows-msvc -march=armv8-a+sve`). Once the
function also has SVE callee saves and a large fixed frame, the compiler stops with
`fatal error: error in backend: SVE callee saves not yet supported with stack probing`.
**Root cause.** `AArch64TargetLowering::hasInlineStackProbe` returns false for Windows (AArch64ISelLowering.cpp:35343-35347).
So `AArch64PrologueEmitter::allocateStackSpace` (AArch64PrologueEpilogue.cpp:514-520) emits plain `emitFrameOffset`
for every scalable allocation (SVE callee-save area at :728, ZPR/PPR locals at :810-837). Only the fixed `NumBytes` part
goes through `windowsRequiresStackProbe`/`emitWindowsStackProbe` (:792). The scalable part is skipped and no error is
reported, except for the SVE-callee-save case at :1087.
**Suggested fix.** On Windows, probe scalable allocations as well: either compute the scalable size into x15 and call
`__chkstk` before the `addvl`, or report an error like the one at :1087 instead of emitting unprobed code.
Environment: LLVM 23.1.2 (85ac560262434c9ccfc0c183ec22d4138ed647fb); Compiler Explorer llc trunk (2026-10-31) emits the
same unprobed `addvl` sequence.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs