Debug info: If the RegisterCoalescer::reMaterializeTrivialDef() is
[opencl/llvm.git] / lib / CodeGen / RegisterCoalescer.cpp
index 2d2dc92a56b6debfd915951c15a26ac4131c4f82..0596b60a19aef916ee8a1c523c24dd8085dcda0b 100644 (file)
@@ -898,8 +898,20 @@ bool RegisterCoalescer::reMaterializeTrivialDef(CoalescerPair &CP,
 
   // The source interval can become smaller because we removed a use.
   LIS->shrinkToUses(&SrcInt, &DeadDefs);
-  if (!DeadDefs.empty())
+  if (!DeadDefs.empty()) {
+    // If the virtual SrcReg is completely eliminated, update all DBG_VALUEs
+    // to describe DstReg instead.
+    for (MachineRegisterInfo::use_iterator UI = MRI->use_begin(SrcReg),
+         UE = MRI->use_end(); UI != UE; ++UI) {
+      MachineOperand &UseMO = *UI;
+      MachineInstr *UseMI = UseMO.getParent();
+      if (UseMI->isDebugValue()) {
+        UseMO.setReg(DstReg);
+        DEBUG({dbgs() << "\t\tupdated: " <<  *UseMI;});
+      }
+    }
     eliminateDeadDefs();
+  }
 
   return true;
 }