Skip to content

[shrinkwrap] PowerPC's FP register should be honored when processing the save point for prologue. #129855

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Mar 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions llvm/include/llvm/CodeGen/TargetRegisterInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -1246,6 +1246,11 @@ class TargetRegisterInfo : public MCRegisterInfo {
return false;
}

/// Some targets delay assigning the frame until late and use a placeholder
/// to represent it earlier. This method can be used to identify the frame
/// register placeholder.
virtual bool isVirtualFrameRegister(MCRegister Reg) const { return false; }

virtual std::optional<uint8_t> getVRegFlagValue(StringRef Name) const {
return {};
}
Expand Down
12 changes: 8 additions & 4 deletions llvm/lib/CodeGen/ShrinkWrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,10 +348,14 @@ bool ShrinkWrap::useOrDefCSROrFI(const MachineInstr &MI, RegScavenger *RS,
// calling convention definitions, so we need to watch for it, too. An LR
// mentioned implicitly by a return (or "branch to link register")
// instruction we can ignore, otherwise we may pessimize shrinkwrapping.
UseOrDefCSR =
(!MI.isCall() && PhysReg == SP) ||
RCI.getLastCalleeSavedAlias(PhysReg) ||
(!MI.isReturn() && TRI->isNonallocatableRegisterCalleeSave(PhysReg));
// PPC's Frame pointer (FP) is also not described as a callee-saved
// register. Until the FP is assigned a Physical Register PPC's FP needs
// to be checked separately.
UseOrDefCSR = (!MI.isCall() && PhysReg == SP) ||
RCI.getLastCalleeSavedAlias(PhysReg) ||
(!MI.isReturn() &&
TRI->isNonallocatableRegisterCalleeSave(PhysReg)) ||
TRI->isVirtualFrameRegister(PhysReg);
} else if (MO.isRegMask()) {
// Check if this regmask clobbers any of the CSRs.
for (unsigned Reg : getCurrentCSRs(RS)) {
Expand Down
4 changes: 4 additions & 0 deletions llvm/lib/Target/PowerPC/PPCRegisterInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ class PPCRegisterInfo : public PPCGenRegisterInfo {
bool isNonallocatableRegisterCalleeSave(MCRegister Reg) const override {
return Reg == PPC::LR || Reg == PPC::LR8;
}

bool isVirtualFrameRegister(MCRegister Reg) const override {
return Reg == PPC::FP || Reg == PPC::FP8;
}
};

} // end namespace llvm
Expand Down
31 changes: 22 additions & 9 deletions llvm/test/CodeGen/PowerPC/shrink-wrap-frame-pointer.ll
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,37 @@
define void @foo(ptr noundef readnone %parent_frame_pointer) {
; POWERPC64-LABEL: foo
; POWERPC64: # %bb.0:
; POWERPC64-NEXT: cmpld [[REG1:[0-9]+]], 1
; POWERPC64: # %bb.1:
; POWERPC64-NEXT: mflr [[REG2:[0-9]+]]
; POWERPC64: mflr [[REG1:[0-9]+]]
; POWERPC64-NEXT: stdu 1, -32(1)
; POWERPC64-NEXT: std [[REG1]], 48(1)
; POWERPC64: cmpld [[REG2:[0-9]+]], 1
; POWERPC64: # %bb.1:
; POWERPC64-NEXT: addi 1, 1, 32
; POWERPC64-NEXT: ld [[REG1]], 16(1)
; POWERPC64-NEXT: mtlr [[REG1]]
; POWERPC64-NEXT: blr

; POWERPC32-AIX-LABEL: .foo:
; POWERPC32-AIX: # %bb.0:
; POWERPC32-AIX-NEXT: cmplw [[REG1:[0-9]+]], 1
; POWERPC32-AIX: # %bb.1:
; POWERPC32-AIX-NEXT: mflr [[REG2:[0-9]+]]
; POWERPC32-AIX-NEXT: mflr [[REG1:[0-9]+]]
; POWERPC32-AIX-NEXT: stwu 1, -64(1)
; POWERPC32-AIX-NEXT: cmplw [[REG2:[0-9]+]], 1
; POWERPC32-AIX: # %bb.1:
; POWERPC32-AIX-NEXT: addi 1, 1, 64
; POWERPC32-AIX-NEXT: lwz [[REG1]], 8(1)
; POWERPC32-AIX-NEXT: mtlr [[REG1]]
; POWERPC32-AIX-NEXT: blr

; POWERPC64-AIX-LABEL: .foo:
; POWERPC64-AIX: # %bb.0:
; POWERPC64-AIX-NEXT: cmpld [[REG1:[0-9]+]], 1
; POWERPC64-AIX: # %bb.1:
; POWERPC64-AIX-NEXT: mflr [[REG2:[0-9]+]]
; POWERPC64-AIX-NEXT: mflr [[REG1:[0-9]+]]
; POWERPC64-AIX-NEXT: stdu 1, -112(1)
; POWERPC64-AIX-NEXT: cmpld [[REG2:[0-9]+]], 1
; POWERPC64-AIX: # %bb.1:
; POWERPC64-AIX-NEXT: addi 1, 1, 112
; POWERPC64-AIX-NEXT: ld [[REG1]], 16(1)
; POWERPC64-AIX-NEXT: mtlr [[REG1]]
; POWERPC64-AIX-NEXT: blr

entry:
%frameaddress = tail call ptr @llvm.frameaddress.p0(i32 0)
Expand Down