[llvm] e1c03dd - [PowerPC] use r1 as the frame pointer when there is dynamic alloca

Chen Zheng via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 20 19:37:35 PDT 2024


Author: Chen Zheng
Date: 2024-06-20T22:26:52-04:00
New Revision: e1c03ddc9b03b820b421d8b3bca6a94e4d1a4675

URL: https://github.com/llvm/llvm-project/commit/e1c03ddc9b03b820b421d8b3bca6a94e4d1a4675
DIFF: https://github.com/llvm/llvm-project/commit/e1c03ddc9b03b820b421d8b3bca6a94e4d1a4675.diff

LOG: [PowerPC] use r1 as the frame pointer when there is dynamic alloca

On PPC, when there is dynamic alloca, only r1 points to the backchain.

Added: 
    

Modified: 
    llvm/lib/Target/PowerPC/PPCFrameLowering.cpp
    llvm/test/CodeGen/PowerPC/frameaddr-alloca.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/PowerPC/PPCFrameLowering.cpp b/llvm/lib/Target/PowerPC/PPCFrameLowering.cpp
index 201b2d162372b..277d708013c78 100644
--- a/llvm/lib/Target/PowerPC/PPCFrameLowering.cpp
+++ b/llvm/lib/Target/PowerPC/PPCFrameLowering.cpp
@@ -384,7 +384,10 @@ bool PPCFrameLowering::needsFP(const MachineFunction &MF) const {
 }
 
 void PPCFrameLowering::replaceFPWithRealFP(MachineFunction &MF) const {
-  bool is31 = needsFP(MF);
+  // When there is dynamic alloca in this function, we can not use the frame
+  // pointer X31/R31 for the frameaddress lowering. In this case, only X1/R1
+  // always points to the backchain.
+  bool is31 = needsFP(MF) && !MF.getFrameInfo().hasVarSizedObjects();
   unsigned FPReg  = is31 ? PPC::R31 : PPC::R1;
   unsigned FP8Reg = is31 ? PPC::X31 : PPC::X1;
 

diff  --git a/llvm/test/CodeGen/PowerPC/frameaddr-alloca.ll b/llvm/test/CodeGen/PowerPC/frameaddr-alloca.ll
index 6be391fb929d9..0e136305428e1 100644
--- a/llvm/test/CodeGen/PowerPC/frameaddr-alloca.ll
+++ b/llvm/test/CodeGen/PowerPC/frameaddr-alloca.ll
@@ -18,7 +18,7 @@ define ptr @frame_1(i32 signext %num) nounwind {
 ; AIX32-NEXT:    lbz 4, 0(3)
 ; AIX32-NEXT:    addi 4, 4, 1
 ; AIX32-NEXT:    stb 4, 0(3)
-; AIX32-NEXT:    lwz 3, 0(31)
+; AIX32-NEXT:    lwz 3, 0(1)
 ; AIX32-NEXT:    lwz 1, 0(1)
 ; AIX32-NEXT:    lwz 31, -4(1)
 ; AIX32-NEXT:    blr
@@ -37,7 +37,7 @@ define ptr @frame_1(i32 signext %num) nounwind {
 ; AIX64-NEXT:    lbz 4, 0(3)
 ; AIX64-NEXT:    addi 4, 4, 1
 ; AIX64-NEXT:    stb 4, 0(3)
-; AIX64-NEXT:    ld 3, 0(31)
+; AIX64-NEXT:    ld 3, 0(1)
 ; AIX64-NEXT:    ld 1, 0(1)
 ; AIX64-NEXT:    ld 31, -8(1)
 ; AIX64-NEXT:    blr
@@ -56,7 +56,7 @@ define ptr @frame_1(i32 signext %num) nounwind {
 ; LE-NEXT:    lbz 4, 0(3)
 ; LE-NEXT:    addi 4, 4, 1
 ; LE-NEXT:    stb 4, 0(3)
-; LE-NEXT:    ld 3, 0(31)
+; LE-NEXT:    ld 3, 0(1)
 ; LE-NEXT:    ld 1, 0(1)
 ; LE-NEXT:    ld 31, -8(1)
 ; LE-NEXT:    blr
@@ -85,7 +85,7 @@ define ptr @frame_0(i32 signext %num) nounwind {
 ; AIX32-NEXT:    lbz 4, 0(3)
 ; AIX32-NEXT:    addi 4, 4, 1
 ; AIX32-NEXT:    stb 4, 0(3)
-; AIX32-NEXT:    mr 3, 31
+; AIX32-NEXT:    mr 3, 1
 ; AIX32-NEXT:    lwz 1, 0(1)
 ; AIX32-NEXT:    lwz 31, -4(1)
 ; AIX32-NEXT:    blr
@@ -104,7 +104,7 @@ define ptr @frame_0(i32 signext %num) nounwind {
 ; AIX64-NEXT:    lbz 4, 0(3)
 ; AIX64-NEXT:    addi 4, 4, 1
 ; AIX64-NEXT:    stb 4, 0(3)
-; AIX64-NEXT:    mr 3, 31
+; AIX64-NEXT:    mr 3, 1
 ; AIX64-NEXT:    ld 1, 0(1)
 ; AIX64-NEXT:    ld 31, -8(1)
 ; AIX64-NEXT:    blr
@@ -123,7 +123,7 @@ define ptr @frame_0(i32 signext %num) nounwind {
 ; LE-NEXT:    lbz 4, 0(3)
 ; LE-NEXT:    addi 4, 4, 1
 ; LE-NEXT:    stb 4, 0(3)
-; LE-NEXT:    mr 3, 31
+; LE-NEXT:    mr 3, 1
 ; LE-NEXT:    ld 1, 0(1)
 ; LE-NEXT:    ld 31, -8(1)
 ; LE-NEXT:    blr


        


More information about the llvm-commits mailing list