[llvm-commits] CVS: llvm/lib/CodeGen/VirtRegMap.cpp

Chris Lattner lattner at cs.uiuc.edu
Fri Oct 1 12:47:26 PDT 2004



Changes in directory llvm/lib/CodeGen:

VirtRegMap.cpp updated: 1.27 -> 1.28
---
Log message:

Add a simple little improvement to the local spiller to keep track of stores
and delete them if they turn out to be dead.  This is a useful little hack
that even speeds up some programs.  For example, it speeds up Ptrdist/ks
from 17.53s to 15.59s, and 188.ammp from 149s to 146s.

This also speeds up llc :)



---
Diffs of the changes:  (+26 -0)

Index: llvm/lib/CodeGen/VirtRegMap.cpp
diff -u llvm/lib/CodeGen/VirtRegMap.cpp:1.27 llvm/lib/CodeGen/VirtRegMap.cpp:1.28
--- llvm/lib/CodeGen/VirtRegMap.cpp:1.27	Fri Oct  1 14:04:51 2004
+++ llvm/lib/CodeGen/VirtRegMap.cpp	Fri Oct  1 14:47:12 2004
@@ -35,6 +35,7 @@
   Statistic<> NumStores("spiller", "Number of stores added");
   Statistic<> NumLoads ("spiller", "Number of loads added");
   Statistic<> NumReused("spiller", "Number of values reused");
+  Statistic<> NumDSE   ("spiller", "Number of dead stores elided");
 
   enum SpillerName { simple, local };
 
@@ -283,6 +284,14 @@
   // and ".second" is the virtual register that is spilled.
   std::vector<std::pair<unsigned, unsigned> > DefAndUseVReg;
 
+  // MaybeDeadStores - When we need to write a value back into a stack slot,
+  // keep track of the inserted store.  If the stack slot value is never read
+  // (because the value was used from some available register, for example), and
+  // subsequently stored to, the original store is dead.  This map keeps track
+  // of inserted stores that are not used.  If we see a subsequent store to the
+  // same stack slot, the original store is deleted.
+  std::map<int, MachineInstr*> MaybeDeadStores;
+
   for (MachineBasicBlock::iterator MII = MBB.begin(), E = MBB.end();
        MII != E; ) {
     MachineInstr &MI = *MII;
@@ -361,6 +370,9 @@
                         ClobberPhysReg(Op.AssignedPhysReg, SpillSlotsAvailable,
                                        PhysRegsAvailable);
 
+                        // Any stores to this stack slot are not dead anymore.
+                        MaybeDeadStores.erase(Op.StackSlot);
+
                         MI.SetMachineOperandReg(Op.Operand, Op.AssignedPhysReg);
                         PhysRegsAvailable[Op.AssignedPhysReg] = Op.StackSlot;
                         SpillSlotsAvailable[Op.StackSlot] = Op.AssignedPhysReg;
@@ -383,6 +395,9 @@
               // This invalidates PhysReg.
               ClobberPhysReg(PhysReg, SpillSlotsAvailable, PhysRegsAvailable);
 
+              // Any stores to this stack slot are not dead anymore.
+              MaybeDeadStores.erase(StackSlot);
+
               MI.SetMachineOperandReg(i, PhysReg);
               PhysRegsAvailable[PhysReg] = StackSlot;
               SpillSlotsAvailable[StackSlot] = PhysReg;
@@ -423,6 +438,9 @@
         int SS = VRM.getStackSlot(I->second);
         DEBUG(std::cerr << " - StackSlot: " << SS << "\n");
 
+        // Any stores to this stack slot are not dead anymore.
+        MaybeDeadStores.erase(SS);
+
         std::map<int, unsigned>::iterator I = SpillSlotsAvailable.find(SS);
         if (I != SpillSlotsAvailable.end()) {
           PhysRegsAvailable.erase(I->second);
@@ -476,6 +494,14 @@
           DEBUG(std::cerr << "Store:\t" << *next(MII));
           MI.SetMachineOperandReg(i, PhysReg);
 
+          // If there is a dead store to this stack slot, nuke it now.
+          MachineInstr *&LastStore = MaybeDeadStores[StackSlot];
+          if (LastStore) {
+            ++NumDSE;
+            MBB.erase(LastStore);
+          }
+          LastStore = next(MII);
+
           // If the stack slot value was previously available in some other
           // register, change it now.  Otherwise, make the register available,
           // in PhysReg.






More information about the llvm-commits mailing list