If only user of a vreg is an copy instruction to export copy of vreg out of current...
authorDevang Patel <dpatel@apple.com>
Tue, 21 Sep 2010 20:56:33 +0000 (20:56 +0000)
committerDevang Patel <dpatel@apple.com>
Tue, 21 Sep 2010 20:56:33 +0000 (20:56 +0000)
Testcase is in r114476.
This fixes radar 8412415.

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

lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp

index a754ac2040ba73fb4e9a7716b003abd05b6b7f08..7ec1492b71122ceb7a345796df28c30fc119fe0f 100644 (file)
@@ -290,6 +290,29 @@ bool SelectionDAGISel::runOnMachineFunction(MachineFunction &mf) {
               TII.get(TargetOpcode::DBG_VALUE))
         .addReg(LDI->second, RegState::Debug)
         .addImm(Offset).addMetadata(Variable);
+
+      // If this vreg is directly copied into an exported register then
+      // that COPY instructions also need DBG_VALUE, if it is the only
+      // user of LDI->second.
+      MachineInstr *CopyUseMI = NULL;
+      for (MachineRegisterInfo::use_iterator 
+             UI = RegInfo->use_begin(LDI->second); 
+           MachineInstr *UseMI = UI.skipInstruction();) {
+        if (UseMI->isDebugValue()) continue;
+        if (UseMI->isCopy() && !CopyUseMI && UseMI->getParent() == EntryMBB) {
+          CopyUseMI = UseMI; continue;
+        }
+        // Otherwise this is another use or second copy use.
+        CopyUseMI = NULL; break;
+      }
+      if (CopyUseMI) {
+        MachineInstr *NewMI =
+          BuildMI(*MF, CopyUseMI->getDebugLoc(), 
+                  TII.get(TargetOpcode::DBG_VALUE))
+          .addReg(CopyUseMI->getOperand(0).getReg(), RegState::Debug)
+          .addImm(Offset).addMetadata(Variable);
+        EntryMBB->insertAfter(CopyUseMI, NewMI);
+      }
     }
   }