Skip to content

Commit

Permalink
[PPC][AIX] Set needsFP to true when base pointer is used in prologue/…
Browse files Browse the repository at this point in the history
…epilogue

When the base pointer r30 is used to hold the stack pointer, r30 is spilled
in the prologue. On AIX registers are saved from highest to lowest, so r31
also needs to be saved. Setting needsFP to true on AIX when the base pointer
is used allows r31 to also be saved and restored.
  • Loading branch information
Zaara Syeda committed Jul 23, 2024
1 parent e3b30bc commit e5fd2aa
Show file tree
Hide file tree
Showing 3 changed files with 249 additions and 203 deletions.
3 changes: 3 additions & 0 deletions llvm/lib/Target/PowerPC/PPCFrameLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,9 @@ bool PPCFrameLowering::needsFP(const MachineFunction &MF) const {
if (MF.getFunction().hasFnAttribute(Attribute::Naked))
return false;

if (Subtarget.isAIXABI() && Subtarget.getRegisterInfo()->hasBasePointer(MF))
return true;

return MF.getTarget().Options.DisableFramePointerElim(MF) ||
MFI.hasVarSizedObjects() || MFI.hasStackMap() || MFI.hasPatchPoint() ||
MF.exposesReturnsTwice() ||
Expand Down
13 changes: 10 additions & 3 deletions llvm/test/CodeGen/PowerPC/aix-base-pointer.ll
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@

; Use an overaligned buffer to force base-pointer usage. Test verifies:
; - base pointer register (r30) is saved/defined/restored.
; - frame pointer register (r31) is saved/defined/restored.
; - stack frame is allocated with correct alignment.
; - Address of %AlignedBuffer is calculated based off offset from the stack
; - Address of %AlignedBuffer is calculated based off offset from the frame
; pointer.

define float @caller(float %f) {
Expand All @@ -19,23 +20,29 @@ define float @caller(float %f) {
declare void @callee(ptr)

; 32BIT-LABEL: .caller:
; 32BIT: stw 31, -12(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: mr 31, 1
; 32BIT: addi 3, 31, 64
; 32BIT: bl .callee
; 32BIT: mr 1, 30
; 32BIT: lwz 31, -12(1)
; 32BIT: lwz 30, -16(1)

; 64BIT-LABEL: .caller:
; 64BIT: std 31, -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: mr 31, 1
; 64BIT: addi 3, 31, 128
; 64BIT: bl .callee
; 64BIT: mr 1, 30
; 64BIT: ld 31, -16(1)
; 64BIT: ld 30, -24(1)
Loading

0 comments on commit e5fd2aa

Please sign in to comment.