[llvm] c79bc59 - [PowerPC][Bug] Fix Bug in Stack Frame Update Code

Stefan Pintilie via llvm-commits llvm-commits at lists.llvm.org
Tue May 11 03:54:13 PDT 2021


Author: Stefan Pintilie
Date: 2021-05-11T05:54:07-05:00
New Revision: c79bc5942d0efd4740c7a6d36ad951c59ef3bc0e

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

LOG: [PowerPC][Bug] Fix Bug in Stack Frame Update Code

The stack frame update code does not take into consideration spilling
to registers for callee saved registers. The option -ppc-enable-pe-vector-spills
turns on spilling to registers for callee saved registers and may expose a bug
in the code that moves a stack frame pointer update instruction.

Reviewed By: nemanjai, #powerpc

Differential Revision: https://reviews.llvm.org/D101366

Added: 
    llvm/test/CodeGen/PowerPC/stack_pointer_vec_spills.mir

Modified: 
    llvm/lib/Target/PowerPC/PPCFrameLowering.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/PowerPC/PPCFrameLowering.cpp b/llvm/lib/Target/PowerPC/PPCFrameLowering.cpp
index 5d53053216c81..0bebfc386b509 100644
--- a/llvm/lib/Target/PowerPC/PPCFrameLowering.cpp
+++ b/llvm/lib/Target/PowerPC/PPCFrameLowering.cpp
@@ -733,6 +733,22 @@ void PPCFrameLowering::emitPrologue(MachineFunction &MF,
   if (stackUpdateCanBeMoved(MF)) {
     const std::vector<CalleeSavedInfo> &Info = MFI.getCalleeSavedInfo();
     for (CalleeSavedInfo CSI : Info) {
+      // If the callee saved register is spilled to a register instead of the
+      // stack then the spill no longer uses the stack pointer.
+      // This can lead to two consequences:
+      // 1) We no longer need to update the stack because the function does not
+      //    spill any callee saved registers to stack.
+      // 2) We have a situation where we still have to update the stack pointer
+      //    even though some registers are spilled to other registers. In
+      //    this case the current code moves the stack update to an incorrect
+      //    position.
+      // In either case we should abort moving the stack update operation.
+      if (CSI.isSpilledToReg()) {
+        StackUpdateLoc = MBBI;
+        MovingStackUpdateDown = false;
+        break;
+      }
+
       int FrIdx = CSI.getFrameIdx();
       // If the frame index is not negative the callee saved info belongs to a
       // stack object that is not a fixed stack object. We ignore non-fixed
@@ -1621,6 +1637,12 @@ void PPCFrameLowering::emitEpilogue(MachineFunction &MF,
   if (stackUpdateCanBeMoved(MF)) {
     const std::vector<CalleeSavedInfo> & Info = MFI.getCalleeSavedInfo();
     for (CalleeSavedInfo CSI : Info) {
+      // If the callee saved register is spilled to another register abort the
+      // stack update movement.
+      if (CSI.isSpilledToReg()) {
+        StackUpdateLoc = MBBI;
+        break;
+      }
       int FrIdx = CSI.getFrameIdx();
       // If the frame index is not negative the callee saved info belongs to a
       // stack object that is not a fixed stack object. We ignore non-fixed

diff  --git a/llvm/test/CodeGen/PowerPC/stack_pointer_vec_spills.mir b/llvm/test/CodeGen/PowerPC/stack_pointer_vec_spills.mir
new file mode 100644
index 0000000000000..b0615959d91c6
--- /dev/null
+++ b/llvm/test/CodeGen/PowerPC/stack_pointer_vec_spills.mir
@@ -0,0 +1,41 @@
+# RUN: llc -mtriple=powerpc64le-unknown-linux-gnu -mcpu=pwr9 \
+# RUN:     -start-before=prologepilog -ppc-enable-pe-vector-spills \
+# RUN:     -ppc-asm-full-reg-names -verify-machineinstrs %s -o - | FileCheck %s
+
+---
+name:            MixedSpill
+alignment:       16
+tracksRegLiveness: true
+liveins:
+body:             |
+  bb.0.entry:
+    $r14 = IMPLICIT_DEF
+    $f14 = IMPLICIT_DEF
+    $lr8 = IMPLICIT_DEF
+    BLR8 implicit undef $lr8, implicit undef $rm
+
+# CHECK-LABEL: MixedSpill
+# CHECK:       stdu r1, -176(r1)
+# CHECK:       stfd f14, 32(r1)
+# CHECK:       mtvsrd vs32, r14
+# CHECK:       lfd f14, 32(r1)
+# CHECK:       addi r1, r1, 176
+# CHECK:       blr
+...
+---
+name:            NoStackUpdate
+alignment:       16
+tracksRegLiveness: true
+liveins:
+body:             |
+  bb.0.entry:
+    $r14 = IMPLICIT_DEF
+    $f14 = IMPLICIT_DEF
+    BLR8 implicit undef $lr8, implicit undef $rm
+
+# CHECK-LABEL: NoStackUpdate
+# CHECK-NOT:   stdu
+# CHECK:       mtvsrd vs32, r14
+# CHECK:       mfvsrd r14, vs32
+# CHECK:       blr
+...


        


More information about the llvm-commits mailing list