Skip to content

Commit

Permalink
[PowerPC][AIX] Update save/restore offset for frame and base pointers.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mandlebug committed Sep 1, 2020
1 parent 96ae43b commit fecc27d
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 35 deletions.
40 changes: 11 additions & 29 deletions llvm/lib/Target/PowerPC/PPCFrameLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -863,26 +863,18 @@ void PPCFrameLowering::emitPrologue(MachineFunction &MF,

int FPOffset = 0;
if (HasFP) {
if (isSVR4ABI) {
MachineFrameInfo &MFI = MF.getFrameInfo();
int FPIndex = FI->getFramePointerSaveIndex();
assert(FPIndex && "No Frame Pointer Save Slot!");
FPOffset = MFI.getObjectOffset(FPIndex);
} else {
FPOffset = getFramePointerSaveOffset();
}
MachineFrameInfo &MFI = MF.getFrameInfo();
int FPIndex = FI->getFramePointerSaveIndex();
assert(FPIndex && "No Frame Pointer Save Slot!");
FPOffset = MFI.getObjectOffset(FPIndex);
}

int BPOffset = 0;
if (HasBP) {
if (isSVR4ABI) {
MachineFrameInfo &MFI = MF.getFrameInfo();
int BPIndex = FI->getBasePointerSaveIndex();
assert(BPIndex && "No Base Pointer Save Slot!");
BPOffset = MFI.getObjectOffset(BPIndex);
} else {
BPOffset = getBasePointerSaveOffset();
}
MachineFrameInfo &MFI = MF.getFrameInfo();
int BPIndex = FI->getBasePointerSaveIndex();
assert(BPIndex && "No Base Pointer Save Slot!");
BPOffset = MFI.getObjectOffset(BPIndex);
}

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

// Get processor type.
bool isPPC64 = Subtarget.isPPC64();
// Get the ABI.
bool isSVR4ABI = Subtarget.isSVR4ABI();

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

if (HasFP) {
if (isSVR4ABI) {
int FPIndex = FI->getFramePointerSaveIndex();
assert(FPIndex && "No Frame Pointer Save Slot!");
FPOffset = MFI.getObjectOffset(FPIndex);
} else {
FPOffset = getFramePointerSaveOffset();
}
int FPIndex = FI->getFramePointerSaveIndex();
assert(FPIndex && "No Frame Pointer Save Slot!");
FPOffset = MFI.getObjectOffset(FPIndex);
}

int BPOffset = 0;
if (HasBP) {
if (isSVR4ABI) {
int BPIndex = FI->getBasePointerSaveIndex();
assert(BPIndex && "No Base Pointer Save Slot!");
BPOffset = MFI.getObjectOffset(BPIndex);
} else {
BPOffset = getBasePointerSaveOffset();
}
}

int PBPOffset = 0;
Expand Down
12 changes: 6 additions & 6 deletions llvm/test/CodeGen/PowerPC/aix-base-pointer.ll
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,33 @@
; - Address of %AlignedBuffer is calculated based off offset from the stack
; pointer.

define void @caller() {
define float @caller(float %f) {
%AlignedBuffer = alloca [32 x i32], align 32
%Pointer = getelementptr inbounds [32 x i32], [32 x i32]* %AlignedBuffer, i64 0, i64 0
call void @callee(i32* %Pointer)
ret void
ret float %f
}

declare void @callee(i32*)

; 32BIT-LABEL: .caller:
; 32BIT: stw 30, -8(1)
; 32BIT: stw 30, -16(1)
; 32BIT: mr 30, 1
; 32BIT: clrlwi 0, 1, 27
; 32BIT: subfic 0, 0, -224
; 32BIT: stwux 1, 1, 0
; 32BIT: addi 3, 1, 64
; 32BIT: bl .callee
; 32BIT: lwz 1, 0(1)
; 32BIT: lwz 30, -8(1)
; 32BIT: lwz 30, -16(1)

; 64BIT-LABEL: .caller:
; 64BIT: std 30, -16(1)
; 64BIT: std 30, -24(1)
; 64BIT: mr 30, 1
; 64BIT: clrldi 0, 1, 59
; 64BIT: subfic 0, 0, -288
; 64BIT: stdux 1, 1, 0
; 64BIT: addi 3, 1, 128
; 64BIT: bl .callee
; 64BIT: ld 1, 0(1)
; 64BIT: ld 30, -16(1)
; 64BIT: ld 30, -24(1)
27 changes: 27 additions & 0 deletions llvm/test/CodeGen/PowerPC/aix-framepointer-save-restore.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
; RUN: llc -verify-machineinstrs < %s -mcpu=pwr4 -mattr=-altivec \
; RUN: -mtriple=powerpc-ibm-aix-xcoff | \
; RUN: FileCheck %s -check-prefix=AIX32

; RUN: llc -verify-machineinstrs < %s -mcpu=pwr4 -mattr=-altivec \
; RUN: -mtriple=powerpc64-ibm-aix-xcoff | \
; RUN: FileCheck %s -check-prefixes=AIX64

declare void @clobber(i32*)

define dso_local float @frameptr_only(i32 %n, float %f) {
entry:
%0 = alloca i32, i32 %n
call void @clobber(i32* %0)
ret float %f
}

; AIX32: stw 31, -12(1)
; AIX32: stwu 1, -80(1)
; AIX32: lwz 1, 0(1)
; AIX32: lwz 31, -12(1)

; AIX64: std 31, -16(1)
; AIX64: stdu 1, -144(1)
; AIX64: ld 1, 0(1)
; AIX64: ld 31, -16(1)

0 comments on commit fecc27d

Please sign in to comment.