Skip to content

Commit b92d084

Browse files
committed
[AArch64][SVE] Fix frame offset calculation when d8 is saved.
If d8 is saved, the fp is not actually adjacent to the SVE spills/allocations. Fix the offset calculation to account for this. Differential Revision: https://reviews.llvm.org/D88117
1 parent d14cfe1 commit b92d084

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

llvm/lib/Target/AArch64/AArch64FrameLowering.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1952,12 +1952,15 @@ StackOffset AArch64FrameLowering::resolveFrameOffsetReference(
19521952
"non-argument/CSR objects cannot be accessed through the frame pointer");
19531953

19541954
if (isSVE) {
1955-
int64_t OffsetToSVEArea =
1955+
int64_t OffsetFromSPToSVEArea =
19561956
MFI.getStackSize() - AFI->getCalleeSavedStackSize();
1957-
StackOffset FPOffset = {ObjectOffset, MVT::nxv1i8};
1957+
int64_t OffsetFromFPToSVEArea =
1958+
-AFI->getCalleeSaveBaseToFrameRecordOffset();
1959+
StackOffset FPOffset = StackOffset(OffsetFromFPToSVEArea, MVT::i8) +
1960+
StackOffset(ObjectOffset, MVT::nxv1i8);
19581961
StackOffset SPOffset = SVEStackSize +
19591962
StackOffset(ObjectOffset, MVT::nxv1i8) +
1960-
StackOffset(OffsetToSVEArea, MVT::i8);
1963+
StackOffset(OffsetFromSPToSVEArea, MVT::i8);
19611964
// Always use the FP for SVE spills if available and beneficial.
19621965
if (hasFP(MF) &&
19631966
(SPOffset.getBytes() ||

llvm/test/CodeGen/AArch64/framelayout-sve.mir

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
define aarch64_sve_vector_pcs void @save_restore_sve() { entry: unreachable }
4141
define aarch64_sve_vector_pcs void @save_restore_sve_realign() { entry: unreachable }
4242
define aarch64_sve_vector_pcs void @frame_layout() { entry: unreachable }
43+
define void @fp_relative_index_with_float_save() { entry: unreachable }
4344

4445
...
4546
# +----------+
@@ -779,3 +780,37 @@ body: |
779780
RET_ReallyLR
780781
781782
---
783+
# Make sure we account for the offset between the fp and the sve area, if it exists.
784+
# FIXME: Should there be an offset?
785+
# CHECK-LABEL: name: fp_relative_index_with_float_save
786+
# CHECK: - { id: 0, name: '', type: default, offset: -16, size: 16, alignment: 16,
787+
# CHECK-NEXT: stack-id: sve-vec
788+
# CHECK: - { id: 1, name: '', type: default, offset: -64, size: 16, alignment: 32,
789+
# CHECK-NEXT: stack-id: default
790+
# CHECK: - { id: 2, name: '', type: spill-slot, offset: -8, size: 8, alignment: 8,
791+
# CHECK-NEXT: stack-id: default, callee-saved-register: '$lr'
792+
# CHECK: - { id: 3, name: '', type: spill-slot, offset: -16, size: 8, alignment: 8,
793+
# CHECK-NEXT: stack-id: default, callee-saved-register: '$fp'
794+
# CHECK: - { id: 4, name: '', type: spill-slot, offset: -32, size: 8, alignment: 16,
795+
# CHECK-NEXT: stack-id: default, callee-saved-register: '$d8'
796+
797+
# CHECK: $x8 = SUBXri $fp, 16, 0
798+
# CHECK: STR_ZXI $z0, killed $x8, -1
799+
800+
name: fp_relative_index_with_float_save
801+
stack:
802+
- { id: 0, stack-id: sve-vec, size: 16, alignment: 16 }
803+
- { id: 1, stack-id: default, size: 16, alignment: 32 }
804+
frameInfo:
805+
maxAlignment: 16
806+
isFrameAddressTaken: true
807+
body: |
808+
bb.0.entry:
809+
liveins: $z0
810+
811+
$d8 = IMPLICIT_DEF
812+
813+
STR_ZXI $z0, %stack.0, 0
814+
815+
RET_ReallyLR
816+
---

0 commit comments

Comments
 (0)