Skip to content

Commit e5fd2aa

Browse files
author
Zaara Syeda
committed
[PPC][AIX] Set needsFP to true when base pointer is used in prologue/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.
1 parent e3b30bc commit e5fd2aa

File tree

3 files changed

+249
-203
lines changed

3 files changed

+249
-203
lines changed

llvm/lib/Target/PowerPC/PPCFrameLowering.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,9 @@ bool PPCFrameLowering::needsFP(const MachineFunction &MF) const {
376376
if (MF.getFunction().hasFnAttribute(Attribute::Naked))
377377
return false;
378378

379+
if (Subtarget.isAIXABI() && Subtarget.getRegisterInfo()->hasBasePointer(MF))
380+
return true;
381+
379382
return MF.getTarget().Options.DisableFramePointerElim(MF) ||
380383
MFI.hasVarSizedObjects() || MFI.hasStackMap() || MFI.hasPatchPoint() ||
381384
MF.exposesReturnsTwice() ||

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66

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

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

2122
; 32BIT-LABEL: .caller:
23+
; 32BIT: stw 31, -12(1)
2224
; 32BIT: stw 30, -16(1)
2325
; 32BIT: mr 30, 1
2426
; 32BIT: clrlwi 0, 1, 27
2527
; 32BIT: subfic 0, 0, -224
2628
; 32BIT: stwux 1, 1, 0
27-
; 32BIT: addi 3, 1, 64
29+
; 32BIT: mr 31, 1
30+
; 32BIT: addi 3, 31, 64
2831
; 32BIT: bl .callee
2932
; 32BIT: mr 1, 30
33+
; 32BIT: lwz 31, -12(1)
3034
; 32BIT: lwz 30, -16(1)
3135

3236
; 64BIT-LABEL: .caller:
37+
; 64BIT: std 31, -16(1)
3338
; 64BIT: std 30, -24(1)
3439
; 64BIT: mr 30, 1
3540
; 64BIT: clrldi 0, 1, 59
3641
; 64BIT: subfic 0, 0, -288
3742
; 64BIT: stdux 1, 1, 0
38-
; 64BIT: addi 3, 1, 128
43+
; 64BIT: mr 31, 1
44+
; 64BIT: addi 3, 31, 128
3945
; 64BIT: bl .callee
4046
; 64BIT: mr 1, 30
47+
; 64BIT: ld 31, -16(1)
4148
; 64BIT: ld 30, -24(1)

0 commit comments

Comments
 (0)