llvm.org GIT mirror llvm / cd6d38d
Merging r330976: ------------------------------------------------------------------------ r330976 | gberry | 2018-04-26 14:50:45 -0400 (Thu, 26 Apr 2018) | 15 lines [AArch64] Fix scavenged spill slot base when stack realignment required. Summary: Use the FP for scavenged spill slot accesses to prevent corruption of the callee-save region when the SP is re-aligned. Based on problem and patch reported by @paulwalker-arm This is an alternative to solution proposed in D45770 Reviewers: t.p.northover, paulwalker-arm, thegameg, javed.absar Subscribers: qcolombet, mcrosier, paulwalker-arm, kristof.beyls, rengolin, javed.absar, llvm-commits Differential Revision: https://reviews.llvm.org/D46063 ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_60@333223 91177308-0d34-0410-b5e6-96231b3b80d8 Geoff Berry 1 year, 4 months ago
2 changed file(s) with 45 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
916916 int FPOffset = MFI.getObjectOffset(FI) + FixedObject + 16;
917917 int Offset = MFI.getObjectOffset(FI) + MFI.getStackSize();
918918 bool isFixed = MFI.isFixedObjectIndex(FI);
919 bool isCSR = !isFixed && MFI.getObjectOffset(FI) >=
920 -((int)AFI->getCalleeSavedStackSize());
919921
920922 // Use frame pointer to reference fixed objects. Use it for locals if
921923 // there are VLAs or a dynamically realigned SP (and thus the SP isn't
929931 // Argument access should always use the FP.
930932 if (isFixed) {
931933 UseFP = hasFP(MF);
934 } else if (isCSR && RegInfo->needsStackRealignment(MF)) {
935 // References to the CSR area must use FP if we're re-aligning the stack
936 // since the dynamically-sized alignment padding is between the SP/BP and
937 // the CSR area.
938 assert(hasFP(MF) && "Re-aligned stack must have frame pointer");
939 UseFP = true;
932940 } else if (hasFP(MF) && !RegInfo->hasBasePointer(MF) &&
933941 !RegInfo->needsStackRealignment(MF)) {
934942 // Use SP or FP, whichever gives us the best chance of the offset
946954 }
947955 }
948956
949 assert((isFixed || !RegInfo->needsStackRealignment(MF) || !UseFP) &&
957 assert(((isFixed || isCSR) || !RegInfo->needsStackRealignment(MF) || !UseFP) &&
950958 "In the presence of dynamic stack pointer realignment, "
951 "non-argument objects cannot be accessed through the frame pointer");
959 "non-argument/CSR objects cannot be accessed through the frame pointer");
952960
953961 if (UseFP) {
954962 FrameReg = RegInfo->getFrameRegister(MF);
0 # RUN: llc -mtriple=aarch64-none-linux-gnu -run-pass=prologepilog %s -o - | FileCheck %s
1
2 # Ensure references to scavenged stack slots in the CSR area use the
3 # FP as a base when the stack pointer must be aligned to something
4 # larger than required by the target. This is necessary because the
5 # alignment padding area is between the CSR area and the SP, so the SP
6 # cannot be used to reference the CSR area.
7 name: test
8 tracksRegLiveness: true
9 frameInfo:
10 maxAlignment: 64
11 # CHECK: stack:
12 # CHECK: id: 0, name: '', type: default, offset: -64, size: 4, alignment: 64
13 # CHECK-NEXT: stack-id: 0
14 # CHECK-NEXT: local-offset: -64
15 # CHECK: id: 1, name: '', type: default, offset: -20, size: 4, alignment: 4
16 # CHECK-NEXT: stack-id: 0
17 # CHECK-NEXT: local-offset: -68
18 stack:
19 - { id: 0, size: 4, alignment: 64, local-offset: -64 }
20 - { id: 1, size: 4, alignment: 4, local-offset: -68 }
21
22 # CHECK: body:
23 # CHECK: %sp = ANDXri killed %{{x[0-9]+}}, 7865
24 # CHECK: STRSui %s0, %sp, 0
25 # CHECK: STURSi %s0, %fp, -4
26 body: |
27 bb.0.entry:
28 liveins: %s0
29
30 STRSui %s0, %stack.0, 0
31 STRSui %s0, %stack.1, 0
32 ; Force preserve a CSR to create a hole in the CSR stack region.
33 %x28 = IMPLICIT_DEF
34 RET_ReallyLR