[llvm-commits] [llvm] r41083 - /llvm/trunk/lib/CodeGen/VirtRegMap.cpp

Evan Cheng evan.cheng at apple.com
Tue Aug 14 13:23:15 PDT 2007


Author: evancheng
Date: Tue Aug 14 15:23:13 2007
New Revision: 41083

URL: http://llvm.org/viewvc/llvm-project?rev=41083&view=rev
Log:
If a MI's def is remat as well as spilled, and the store is later deemed dead, mark the def operand as isDead.

Modified:
    llvm/trunk/lib/CodeGen/VirtRegMap.cpp

Modified: llvm/trunk/lib/CodeGen/VirtRegMap.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/VirtRegMap.cpp?rev=41083&r1=41082&r2=41083&view=diff

==============================================================================
--- llvm/trunk/lib/CodeGen/VirtRegMap.cpp (original)
+++ llvm/trunk/lib/CodeGen/VirtRegMap.cpp Tue Aug 14 15:23:13 2007
@@ -433,12 +433,39 @@
 /// InvalidateKills - MI is going to be deleted. If any of its operands are
 /// marked kill, then invalidate the information.
 static void InvalidateKills(MachineInstr &MI, BitVector &RegKills,
-                           std::vector<MachineOperand*> &KillOps) {
+                            std::vector<MachineOperand*> &KillOps,
+                            MachineInstr *NewDef = NULL) {
   for (unsigned i = 0, e = MI.getNumOperands(); i != e; ++i) {
     MachineOperand &MO = MI.getOperand(i);
     if (!MO.isReg() || !MO.isUse() || !MO.isKill())
       continue;
     unsigned Reg = MO.getReg();
+    if (NewDef) {
+      // Due to remat, it's possible this reg isn't being reused. That is,
+      // the def of this reg (by prev MI) is now dead.
+      bool FoundUse = false, Done = false;
+      MachineBasicBlock::iterator I = MI, E = NewDef;
+      ++I; ++E;
+      for (; !Done && I != E; ++I) {
+        MachineInstr *NMI = I;
+        for (unsigned j = 0, ee = NMI->getNumOperands(); j != ee; ++j) {
+          MachineOperand &MO = NMI->getOperand(j);
+          if (!MO.isReg() || MO.getReg() != Reg)
+            continue;
+          if (MO.isUse())
+            FoundUse = true;
+          Done = true; // Stop after scanning all the operands of this MI.
+        }
+      }
+      if (!FoundUse) {
+        // Def is dead!
+        MachineBasicBlock::iterator MII = MI;
+        MachineInstr *DefMI = prior(MII);
+        MachineOperand *DefOp = DefMI->findRegisterDefOperand(Reg);
+        assert(DefOp && "Missing def?");
+        DefOp->setIsDead();
+      }
+    }
     if (KillOps[Reg] == &MO) {
       RegKills.reset(Reg);
       KillOps[Reg] = NULL;
@@ -1081,7 +1108,7 @@
         if (LastStore) {
           DOUT << "Removed dead store:\t" << *LastStore;
           ++NumDSE;
-          InvalidateKills(*LastStore, RegKills, KillOps);
+          InvalidateKills(*LastStore, RegKills, KillOps, &MI);
           MBB.erase(LastStore);
           VRM.RemoveFromFoldedVirtMap(LastStore);
         }





More information about the llvm-commits mailing list