If the only use of something is a DEBUG_VALUE, don't
authorDale Johannesen <dalej@apple.com>
Wed, 27 Jan 2010 22:12:36 +0000 (22:12 +0000)
committerDale Johannesen <dalej@apple.com>
Wed, 27 Jan 2010 22:12:36 +0000 (22:12 +0000)
let that stop it from being deleted, and change the
DEBUG_VALUE value to undef.

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

lib/CodeGen/DeadMachineInstructionElim.cpp

index 0982eabff123a76900b786b20d5e82d2d088bc40..9d7ec06ac972e7e3d574648825a3e2aae7ebdabb 100644 (file)
@@ -107,6 +107,20 @@ bool DeadMachineInstructionElim::runOnMachineFunction(MachineFunction &MF) {
          MIE = MBB->rend(); MII != MIE; ) {
       MachineInstr *MI = &*MII;
 
+      if (MI->getOpcode()==TargetInstrInfo::DEBUG_VALUE) {
+        // Don't delete the DEBUG_VALUE itself, but if its Value operand is
+        // a vreg and this is the only use, substitute an undef operand;
+        // the former operand will then be deleted normally.
+        if (MI->getNumOperands()==3 && MI->getOperand(0).isReg()) {
+          unsigned Reg = MI->getOperand(0).getReg();
+          MachineRegisterInfo::use_iterator I = MRI->use_begin(Reg);
+          assert(I != MRI->use_end());
+          if (++I == MRI->use_end())
+            // only one use, which must be this DEBUG_VALUE.
+            MI->getOperand(0).setReg(0U);
+        }
+      }
+
       // If the instruction is dead, delete it!
       if (isDead(MI)) {
         DEBUG(dbgs() << "DeadMachineInstructionElim: DELETING: " << *MI);