Incorporated feedback: Check that the implicitly defined operands aren't used
authorBill Wendling <isanbard@gmail.com>
Tue, 27 May 2008 20:40:52 +0000 (20:40 +0000)
committerBill Wendling <isanbard@gmail.com>
Tue, 27 May 2008 20:40:52 +0000 (20:40 +0000)
before deleting the instruction.

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

lib/CodeGen/TwoAddressInstructionPass.cpp

index 5bac6a6822aa67f38292cfd6c0c9ae5b0862727d..145f80ae74b2f923f2661508ea6badc2af30b8bb 100644 (file)
@@ -373,6 +373,8 @@ bool TwoAddressInstructionPass::runOnMachineFunction(MachineFunction &MF) {
   }
 
   if (EnableReMat) {
+    // Check to see if the instructions that we rematerialized are now dead. If
+    // they are, expunge them here.
     SmallPtrSet<MachineInstr*, 8>::iterator I = ReMattedInstrs.begin();
     SmallPtrSet<MachineInstr*, 8>::iterator E = ReMattedInstrs.end();
 
@@ -385,20 +387,17 @@ bool TwoAddressInstructionPass::runOnMachineFunction(MachineFunction &MF) {
         if (!MO.isRegister())
           continue;
         unsigned MOReg = MO.getReg();
-        if (!MOReg)
+
+        if (!MOReg || !MO.isDef() || (MO.isImplicit() && MO.isDead()))
           continue;
-        if (MO.isDef()) {
-          if (MO.isImplicit())
-            continue;
 
-          if (MRI->use_begin(MOReg) != MRI->use_end()) {
-            InstrDead = false;
-            break;
-          }
+        if (MRI->use_begin(MOReg) != MRI->use_end()) {
+          InstrDead = false;
+          break;
         }
       }
 
-      if (InstrDead && MI->getNumOperands() > 0)
+      if (InstrDead)
         MI->eraseFromParent();
     }
   }