Skip to content

Commit fecc27d

Browse files
committed
[PowerPC][AIX] Update save/restore offset for frame and base pointers.
General purpose registers 30 and 31 are handled differently when they are reserved as the base-pointer and frame-pointer respectively. This fixes the offset of their fixed-stack objects when there are fpr calle-saved registers. Differential Revision: https://reviews.llvm.org/D85850
1 parent 96ae43b commit fecc27d

File tree

3 files changed

+44
-35
lines changed

3 files changed

+44
-35
lines changed

llvm/lib/Target/PowerPC/PPCFrameLowering.cpp

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -863,26 +863,18 @@ void PPCFrameLowering::emitPrologue(MachineFunction &MF,
863863

864864
int FPOffset = 0;
865865
if (HasFP) {
866-
if (isSVR4ABI) {
867-
MachineFrameInfo &MFI = MF.getFrameInfo();
868-
int FPIndex = FI->getFramePointerSaveIndex();
869-
assert(FPIndex && "No Frame Pointer Save Slot!");
870-
FPOffset = MFI.getObjectOffset(FPIndex);
871-
} else {
872-
FPOffset = getFramePointerSaveOffset();
873-
}
866+
MachineFrameInfo &MFI = MF.getFrameInfo();
867+
int FPIndex = FI->getFramePointerSaveIndex();
868+
assert(FPIndex && "No Frame Pointer Save Slot!");
869+
FPOffset = MFI.getObjectOffset(FPIndex);
874870
}
875871

876872
int BPOffset = 0;
877873
if (HasBP) {
878-
if (isSVR4ABI) {
879-
MachineFrameInfo &MFI = MF.getFrameInfo();
880-
int BPIndex = FI->getBasePointerSaveIndex();
881-
assert(BPIndex && "No Base Pointer Save Slot!");
882-
BPOffset = MFI.getObjectOffset(BPIndex);
883-
} else {
884-
BPOffset = getBasePointerSaveOffset();
885-
}
874+
MachineFrameInfo &MFI = MF.getFrameInfo();
875+
int BPIndex = FI->getBasePointerSaveIndex();
876+
assert(BPIndex && "No Base Pointer Save Slot!");
877+
BPOffset = MFI.getObjectOffset(BPIndex);
886878
}
887879

888880
int PBPOffset = 0;
@@ -1551,8 +1543,6 @@ void PPCFrameLowering::emitEpilogue(MachineFunction &MF,
15511543

15521544
// Get processor type.
15531545
bool isPPC64 = Subtarget.isPPC64();
1554-
// Get the ABI.
1555-
bool isSVR4ABI = Subtarget.isSVR4ABI();
15561546

15571547
// Check if the link register (LR) has been saved.
15581548
PPCFunctionInfo *FI = MF.getInfo<PPCFunctionInfo>();
@@ -1600,24 +1590,16 @@ void PPCFrameLowering::emitEpilogue(MachineFunction &MF,
16001590
SingleScratchReg = ScratchReg == TempReg;
16011591

16021592
if (HasFP) {
1603-
if (isSVR4ABI) {
1604-
int FPIndex = FI->getFramePointerSaveIndex();
1605-
assert(FPIndex && "No Frame Pointer Save Slot!");
1606-
FPOffset = MFI.getObjectOffset(FPIndex);
1607-
} else {
1608-
FPOffset = getFramePointerSaveOffset();
1609-
}
1593+
int FPIndex = FI->getFramePointerSaveIndex();
1594+
assert(FPIndex && "No Frame Pointer Save Slot!");
1595+
FPOffset = MFI.getObjectOffset(FPIndex);
16101596
}
16111597

16121598
int BPOffset = 0;
16131599
if (HasBP) {
1614-
if (isSVR4ABI) {
16151600
int BPIndex = FI->getBasePointerSaveIndex();
16161601
assert(BPIndex && "No Base Pointer Save Slot!");
16171602
BPOffset = MFI.getObjectOffset(BPIndex);
1618-
} else {
1619-
BPOffset = getBasePointerSaveOffset();
1620-
}
16211603
}
16221604

16231605
int PBPOffset = 0;

llvm/test/CodeGen/PowerPC/aix-base-pointer.ll

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,33 @@
1010
; - Address of %AlignedBuffer is calculated based off offset from the stack
1111
; pointer.
1212

13-
define void @caller() {
13+
define float @caller(float %f) {
1414
%AlignedBuffer = alloca [32 x i32], align 32
1515
%Pointer = getelementptr inbounds [32 x i32], [32 x i32]* %AlignedBuffer, i64 0, i64 0
1616
call void @callee(i32* %Pointer)
17-
ret void
17+
ret float %f
1818
}
1919

2020
declare void @callee(i32*)
2121

2222
; 32BIT-LABEL: .caller:
23-
; 32BIT: stw 30, -8(1)
23+
; 32BIT: stw 30, -16(1)
2424
; 32BIT: mr 30, 1
2525
; 32BIT: clrlwi 0, 1, 27
2626
; 32BIT: subfic 0, 0, -224
2727
; 32BIT: stwux 1, 1, 0
2828
; 32BIT: addi 3, 1, 64
2929
; 32BIT: bl .callee
3030
; 32BIT: lwz 1, 0(1)
31-
; 32BIT: lwz 30, -8(1)
31+
; 32BIT: lwz 30, -16(1)
3232

3333
; 64BIT-LABEL: .caller:
34-
; 64BIT: std 30, -16(1)
34+
; 64BIT: std 30, -24(1)
3535
; 64BIT: mr 30, 1
3636
; 64BIT: clrldi 0, 1, 59
3737
; 64BIT: subfic 0, 0, -288
3838
; 64BIT: stdux 1, 1, 0
3939
; 64BIT: addi 3, 1, 128
4040
; 64BIT: bl .callee
4141
; 64BIT: ld 1, 0(1)
42-
; 64BIT: ld 30, -16(1)
42+
; 64BIT: ld 30, -24(1)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
; RUN: llc -verify-machineinstrs < %s -mcpu=pwr4 -mattr=-altivec \
2+
; RUN: -mtriple=powerpc-ibm-aix-xcoff | \
3+
; RUN: FileCheck %s -check-prefix=AIX32
4+
5+
; RUN: llc -verify-machineinstrs < %s -mcpu=pwr4 -mattr=-altivec \
6+
; RUN: -mtriple=powerpc64-ibm-aix-xcoff | \
7+
; RUN: FileCheck %s -check-prefixes=AIX64
8+
9+
declare void @clobber(i32*)
10+
11+
define dso_local float @frameptr_only(i32 %n, float %f) {
12+
entry:
13+
%0 = alloca i32, i32 %n
14+
call void @clobber(i32* %0)
15+
ret float %f
16+
}
17+
18+
; AIX32: stw 31, -12(1)
19+
; AIX32: stwu 1, -80(1)
20+
; AIX32: lwz 1, 0(1)
21+
; AIX32: lwz 31, -12(1)
22+
23+
; AIX64: std 31, -16(1)
24+
; AIX64: stdu 1, -144(1)
25+
; AIX64: ld 1, 0(1)
26+
; AIX64: ld 31, -16(1)
27+

0 commit comments

Comments
 (0)