diff options
author | Chris Lattner <sabre@nondot.org> | 2004-10-01 19:47:12 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2004-10-01 19:47:12 +0000 |
commit | 52b25db3ef9390271bbfa0b5c6efe0a72ce7cb8e (patch) | |
tree | 948675ba03aa12e061b2ca09cc2ebab03e6cd6e2 /lib/CodeGen/VirtRegMap.cpp | |
parent | 7fb64347d7d1310b5f3f06f7ae97031c73a21797 (diff) |
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 :)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@16630 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/VirtRegMap.cpp')
-rw-r--r-- | lib/CodeGen/VirtRegMap.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/CodeGen/VirtRegMap.cpp b/lib/CodeGen/VirtRegMap.cpp index a4d0733e88..8e6ff027e9 100644 --- a/lib/CodeGen/VirtRegMap.cpp +++ b/lib/CodeGen/VirtRegMap.cpp @@ -35,6 +35,7 @@ namespace { 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 @@ void LocalSpiller::RewriteMBB(MachineBasicBlock &MBB, const VirtRegMap &VRM) { // 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 @@ void LocalSpiller::RewriteMBB(MachineBasicBlock &MBB, const VirtRegMap &VRM) { 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 @@ void LocalSpiller::RewriteMBB(MachineBasicBlock &MBB, const VirtRegMap &VRM) { // 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 @@ void LocalSpiller::RewriteMBB(MachineBasicBlock &MBB, const VirtRegMap &VRM) { 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 @@ void LocalSpiller::RewriteMBB(MachineBasicBlock &MBB, const VirtRegMap &VRM) { 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. |