Fix a problem that Nate noticed, where spill code was not getting coallesced
authorChris Lattner <sabre@nondot.org>
Fri, 9 Sep 2005 21:46:49 +0000 (21:46 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 9 Sep 2005 21:46:49 +0000 (21:46 +0000)
with copies, leading to code like this:

       lwz r4, 380(r1)
       or r10, r4, r4    ;; Last use of r4

By teaching the PPC backend how to fold spills into copies, we now get this
code:

       lwz r10, 380(r1)

wow. :)

This reduces a testcase nate sent me from 1505 instructions to 1484.

Note that this could handle FP values but doesn't currently, for reasons
mentioned in the patch

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23298 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/PowerPC/PPCRegisterInfo.cpp
lib/Target/PowerPC/PPCRegisterInfo.h

index 750d97978e2f765db39777cdd8c097edba08646c..1ccc85990150c90a9f2857d58cc3ecd43b9b268b 100644 (file)
@@ -134,6 +134,33 @@ void PPC32RegisterInfo::copyRegToReg(MachineBasicBlock &MBB,
   }
 }
 
+/// foldMemoryOperand - PowerPC (like most RISC's) can only fold spills into
+/// copy instructions, turning them into load/store instructions.
+MachineInstr *PPC32RegisterInfo::foldMemoryOperand(MachineInstr *MI,
+                                                   unsigned OpNum,
+                                                   int FrameIndex) const {
+  // Make sure this is a reg-reg copy.  Note that we can't handle MCRF, because
+  // it takes more than one instruction to store it.
+  unsigned Opc = MI->getOpcode();
+  
+  if ((Opc == PPC::OR &&
+       MI->getOperand(1).getReg() == MI->getOperand(2).getReg())) {
+    if (OpNum == 0) {  // move -> store
+      unsigned InReg = MI->getOperand(1).getReg();
+      return addFrameReference(BuildMI(PPC::STW,
+                                       3).addReg(InReg), FrameIndex);
+    } else {
+      unsigned OutReg = MI->getOperand(0).getReg();
+      return addFrameReference(BuildMI(PPC::LWZ, 2, OutReg), FrameIndex);
+    }
+    
+  } else if (Opc == PPC::FMR) {
+    // FIXME: We would be able to fold this, but we don't know whether to use a
+    // 32- or 64-bit load/store :(.
+  }
+  return 0;
+}
+
 //===----------------------------------------------------------------------===//
 // Stack Frame Processing methods
 //===----------------------------------------------------------------------===//
index 442eae269355c48eb711a9423ec18d3a5fb65dc4..d2745455040e7e49b2079b6e6d5df1e825546fb8 100644 (file)
@@ -40,6 +40,11 @@ public:
                     unsigned DestReg, unsigned SrcReg,
                     const TargetRegisterClass *RC) const;
 
+  /// foldMemoryOperand - PowerPC (like most RISC's) can only fold spills into
+  /// copy instructions, turning them into load/store instructions.
+  virtual MachineInstr* foldMemoryOperand(MachineInstr* MI, unsigned OpNum,
+                                          int FrameIndex) const;
+  
   void eliminateCallFramePseudoInstr(MachineFunction &MF,
                                      MachineBasicBlock &MBB,
                                      MachineBasicBlock::iterator I) const;