forked from OSchip/llvm-project
[AArch64][SVE] Restore SP from FP when SVE CSRs and variable sized objects are present
Without SVE, after a dynamic stack allocation has modified the SP, it is presumed that a frame pointer restoration will revert the SP back to it's correct value prior to any caller stack being restored. However the SVE frame is restored using the stack pointer directly, as it is located after the frame pointer. This means that in the presence of a dynamic stack allocation, any SVE callee state gets corrupted as SP has the incorrect value when the SVE state is restored. To address this issue, when variable sized objects and SVE CSRs are present, treat the stack as having been realigned, hence restoring the stack pointer from the frame pointerr prior to restoring the SVE state. Differential Revision: https://reviews.llvm.org/D124615
This commit is contained in:
parent
032cc74d69
commit
8f623f4ab0
|
@ -1953,7 +1953,10 @@ void AArch64FrameLowering::emitEpilogue(MachineFunction &MF,
|
|||
|
||||
// Deallocate the SVE area.
|
||||
if (SVEStackSize) {
|
||||
if (AFI->isStackRealigned()) {
|
||||
// If we have stack realignment or variable sized objects on the stack,
|
||||
// restore the stack pointer from the frame pointer prior to SVE CSR
|
||||
// restoration.
|
||||
if (AFI->isStackRealigned() || MFI.hasVarSizedObjects()) {
|
||||
if (int64_t CalleeSavedSize = AFI->getSVECalleeSavedStackSize()) {
|
||||
// Set SP to start of SVE callee-save area from which they can
|
||||
// be reloaded. The code below will deallocate the stack space
|
||||
|
|
|
@ -629,7 +629,6 @@ body: |
|
|||
# CHECK-NEXT: $sp = frame-setup SUBXri $sp, 16, 0
|
||||
# CHECK-NEXT: $x19 = ADDXri $sp, 0, 0
|
||||
# CHECK-NEXT: STRXui $xzr, $x19, 0
|
||||
# CHECK-NEXT: $sp = frame-destroy ADDVL_XXI $sp, 1
|
||||
# CHECK-NEXT: $sp = frame-destroy ADDXri $fp, 0, 0
|
||||
# CHECK-NEXT: frame-destroy CFI_INSTRUCTION def_cfa $wsp, 32
|
||||
# CHECK-NEXT: $x19 = frame-destroy LDRXui $sp, 2
|
||||
|
|
|
@ -66,6 +66,7 @@ define void @foo(<vscale x 4 x i64> %dst, i1 %cond) {
|
|||
; CHECK-NEXT: st1d { z1.d }, p0, [x0, #1, mul vl]
|
||||
; CHECK-NEXT: st1d { z0.d }, p0, [x0]
|
||||
; CHECK-NEXT: bl bar
|
||||
; CHECK-NEXT: addvl sp, x29, #-18
|
||||
; CHECK-NEXT: ldr p15, [sp, #4, mul vl] // 2-byte Folded Reload
|
||||
; CHECK-NEXT: ldr p14, [sp, #5, mul vl] // 2-byte Folded Reload
|
||||
; CHECK-NEXT: ldr p13, [sp, #6, mul vl] // 2-byte Folded Reload
|
||||
|
@ -94,7 +95,6 @@ define void @foo(<vscale x 4 x i64> %dst, i1 %cond) {
|
|||
; CHECK-NEXT: ldr z10, [sp, #15, mul vl] // 16-byte Folded Reload
|
||||
; CHECK-NEXT: ldr z9, [sp, #16, mul vl] // 16-byte Folded Reload
|
||||
; CHECK-NEXT: ldr z8, [sp, #17, mul vl] // 16-byte Folded Reload
|
||||
; CHECK-NEXT: addvl sp, sp, #18
|
||||
; CHECK-NEXT: mov sp, x29
|
||||
; CHECK-NEXT: ldp x28, x19, [sp, #16] // 16-byte Folded Reload
|
||||
; CHECK-NEXT: ldp x29, x30, [sp], #32 // 16-byte Folded Reload
|
||||
|
|
Loading…
Reference in New Issue