Skip to content

Commit 73e69b9

Browse files
author
Tony Varghese
committed
PPC's FP register should be honored when processing the save point for prolog by shrinkwrap pass
1 parent 0228b77 commit 73e69b9

File tree

4 files changed

+119
-1
lines changed

4 files changed

+119
-1
lines changed

llvm/include/llvm/CodeGen/TargetRegisterInfo.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,6 +1243,13 @@ class TargetRegisterInfo : public MCRegisterInfo {
12431243
return false;
12441244
}
12451245

1246+
/// Some targets delay assigning the frame until late and use a placeholder
1247+
/// to represent it earlier. This method can be used to identify the frame
1248+
/// register placeholder.
1249+
virtual bool isVirtualFrameRegister(MCRegister Reg) const {
1250+
return false;
1251+
}
1252+
12461253
virtual std::optional<uint8_t> getVRegFlagValue(StringRef Name) const {
12471254
return {};
12481255
}

llvm/lib/CodeGen/ShrinkWrap.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,10 +348,14 @@ bool ShrinkWrap::useOrDefCSROrFI(const MachineInstr &MI, RegScavenger *RS,
348348
// calling convention definitions, so we need to watch for it, too. An LR
349349
// mentioned implicitly by a return (or "branch to link register")
350350
// instruction we can ignore, otherwise we may pessimize shrinkwrapping.
351+
// PPC's Frame pointer (FP) is also not described as a callee-saved register.
352+
// Until the FP is assigned a Physical Register PPC's FP needs to be checked
353+
// separately.
351354
UseOrDefCSR =
352355
(!MI.isCall() && PhysReg == SP) ||
353356
RCI.getLastCalleeSavedAlias(PhysReg) ||
354-
(!MI.isReturn() && TRI->isNonallocatableRegisterCalleeSave(PhysReg));
357+
(!MI.isReturn() && TRI->isNonallocatableRegisterCalleeSave(PhysReg)) ||
358+
(!MI.isReturn() && TRI->isVirtualFrameRegister(PhysReg));
355359
} else if (MO.isRegMask()) {
356360
// Check if this regmask clobbers any of the CSRs.
357361
for (unsigned Reg : getCurrentCSRs(RS)) {

llvm/lib/Target/PowerPC/PPCRegisterInfo.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,10 @@ class PPCRegisterInfo : public PPCGenRegisterInfo {
176176
bool isNonallocatableRegisterCalleeSave(MCRegister Reg) const override {
177177
return Reg == PPC::LR || Reg == PPC::LR8;
178178
}
179+
180+
bool isVirtualFrameRegister(MCRegister Reg) const override {
181+
return Reg == PPC::FP || Reg == PPC::FP8;
182+
}
179183
};
180184

181185
} // end namespace llvm
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
; Test file to check shrink-wrap pass
2+
3+
; RUN: llc -verify-machineinstrs < %s -mtriple=powerpc-ibm-aix-xcoff -mcpu=pwr9 | FileCheck %s --check-prefixes=POWERPC32-AIX
4+
; RUN: llc -verify-machineinstrs < %s -mtriple=powerpc64-ibm-aix-xcoff -mcpu=pwr9 | FileCheck %s --check-prefixes=POWERPC64-AIX
5+
6+
@.str = private unnamed_addr constant [50 x i8] c"parent_frame_pointer > __builtin_frame_address(0)\00", align 1
7+
@.str.1 = private unnamed_addr constant [8 x i8] c"bad.cpp\00", align 1
8+
9+
; Function Attrs: mustprogress noinline nounwind
10+
define void @_Z3fooPv(ptr noundef readnone %parent_frame_pointer) local_unnamed_addr #0 {
11+
12+
; POWERPC32-AIX-LABEL: ._Z3fooPv:
13+
; POWERPC32-AIX: # %bb.0:
14+
; POWERPC32-AIX-NEXT: mflr 0
15+
; POWERPC32-AIX-NEXT: stwu 1, -64(1)
16+
; POWERPC32-AIX-NEXT: cmplw 3, 1
17+
; POWERPC32-AIX-NEXT: stw 0, 72(1)
18+
; POWERPC32-AIX-NEXT: ble- 0, L..BB0_2
19+
; POWERPC32-AIX-NEXT: # %bb.1:
20+
; POWERPC32-AIX-NEXT: addi 1, 1, 64
21+
; POWERPC32-AIX-NEXT: lwz 0, 8(1)
22+
; POWERPC32-AIX-NEXT: mtlr 0
23+
; POWERPC32-AIX-NEXT: blr
24+
; POWERPC32-AIX-NEXT: L..BB0_2:
25+
; POWERPC32-AIX-NEXT: lwz 4, L..C0(2)
26+
; POWERPC32-AIX-NEXT: li 5, 6
27+
; POWERPC32-AIX-NEXT: addi 3, 4, 8
28+
; POWERPC32-AIX-NEXT: bl .__assert[PR]
29+
; POWERPC32-AIX-NEXT: nop
30+
31+
; POWERPC64-AIX-LABEL: ._Z3fooPv:
32+
; POWERPC64-AIX: # %bb.0:
33+
; POWERPC64-AIX-NEXT: mflr 0
34+
; POWERPC64-AIX-NEXT: stdu 1, -112(1)
35+
; POWERPC64-AIX-NEXT: cmpld 3, 1
36+
; POWERPC64-AIX-NEXT: std 0, 128(1)
37+
; POWERPC64-AIX-NEXT: ble- 0, L..BB0_2
38+
; POWERPC64-AIX-NEXT: # %bb.1:
39+
; POWERPC64-AIX-NEXT: addi 1, 1, 112
40+
; POWERPC64-AIX-NEXT: ld 0, 16(1)
41+
; POWERPC64-AIX-NEXT: mtlr 0
42+
; POWERPC64-AIX-NEXT: blr
43+
; POWERPC64-AIX-NEXT: L..BB0_2:
44+
; POWERPC64-AIX-NEXT: ld 4, L..C0(2)
45+
; POWERPC64-AIX-NEXT: li 5, 6
46+
; POWERPC64-AIX-NEXT: addi 3, 4, 8
47+
; POWERPC64-AIX-NEXT: bl .__assert[PR]
48+
; POWERPC64-AIX-NEXT: nop
49+
50+
entry:
51+
%0 = tail call ptr @llvm.frameaddress.p0(i32 0)
52+
%cmp = icmp ugt ptr %parent_frame_pointer, %0
53+
br i1 %cmp, label %cond.end, label %cond.false
54+
55+
cond.false: ; preds = %entry
56+
tail call void @__assert(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 6) #4
57+
unreachable
58+
59+
cond.end: ; preds = %entry
60+
ret void
61+
}
62+
63+
; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(none)
64+
declare ptr @llvm.frameaddress.p0(i32 immarg) #1
65+
66+
; Function Attrs: noreturn nounwind
67+
declare void @__assert(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #2
68+
69+
; Function Attrs: mustprogress norecurse nounwind
70+
define noundef i32 @main() local_unnamed_addr #3 {
71+
; POWERPC32-AIX-LABEL: .main:
72+
; POWERPC32-AIX: # %bb.0:
73+
; POWERPC32-AIX-NEXT: mflr 0
74+
; POWERPC32-AIX-NEXT: stwu 1, -64(1)
75+
; POWERPC32-AIX-NEXT: mr 3, 1
76+
; POWERPC32-AIX-NEXT: stw 0, 72(1)
77+
; POWERPC32-AIX-NEXT: bl ._Z3fooPv
78+
; POWERPC32-AIX-NEXT: nop
79+
; POWERPC32-AIX-NEXT: li 3, 0
80+
; POWERPC32-AIX-NEXT: addi 1, 1, 64
81+
; POWERPC32-AIX-NEXT: lwz 0, 8(1)
82+
; POWERPC32-AIX-NEXT: mtlr 0
83+
; POWERPC32-AIX-NEXT: blr
84+
85+
; POWERPC64-AIX-LABEL: .main:
86+
; POWERPC64-AIX: # %bb.0:
87+
; POWERPC64-AIX-NEXT: mflr 0
88+
; POWERPC64-AIX-NEXT: stdu 1, -112(1)
89+
; POWERPC64-AIX-NEXT: mr 3, 1
90+
; POWERPC64-AIX-NEXT: std 0, 128(1)
91+
; POWERPC64-AIX-NEXT: bl ._Z3fooPv
92+
; POWERPC64-AIX-NEXT: nop
93+
; POWERPC64-AIX-NEXT: li 3, 0
94+
; POWERPC64-AIX-NEXT: addi 1, 1, 112
95+
; POWERPC64-AIX-NEXT: ld 0, 16(1)
96+
; POWERPC64-AIX-NEXT: mtlr 0
97+
; POWERPC64-AIX-NEXT: blr
98+
99+
entry:
100+
%0 = tail call ptr @llvm.frameaddress.p0(i32 0)
101+
tail call void @_Z3fooPv(ptr noundef %0)
102+
ret i32 0
103+
}

0 commit comments

Comments
 (0)