From 0ca48de26c46281ae9fd15a042cc19cdf316bee6 Mon Sep 17 00:00:00 2001 From: Jeremy Morse Date: Fri, 4 Oct 2019 09:38:05 +0000 Subject: [DebugInfo] LiveDebugValues: defer DBG_VALUE creation during analysis When transfering variable locations from one place to another, LiveDebugValues immediately creates a DBG_VALUE representing that transfer. This causes trouble if the variable location should subsequently be invalidated by a loop back-edge, such as in the added test case: the transfer DBG_VALUE from a now-invalid location is used as proof that the variable location is correct. This is effectively a self-fulfilling prophesy. To avoid this, defer the insertion of transfer DBG_VALUEs until after analysis has completed. Some of those transfers are still sketchy, but we don't propagate them into other blocks now. Differential Revision: https://reviews.llvm.org/D67393 llvm-svn: 373720 --- llvm/lib/CodeGen/LiveDebugValues.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'llvm/lib/CodeGen') diff --git a/llvm/lib/CodeGen/LiveDebugValues.cpp b/llvm/lib/CodeGen/LiveDebugValues.cpp index 0bdc62a345c..8d523377fb4 100644 --- a/llvm/lib/CodeGen/LiveDebugValues.cpp +++ b/llvm/lib/CodeGen/LiveDebugValues.cpp @@ -986,9 +986,6 @@ bool LiveDebugValues::transferTerminator(MachineBasicBlock *CurMBB, const VarLocMap &VarLocIDs) { bool Changed = false; - if (OpenRanges.empty()) - return false; - LLVM_DEBUG(for (unsigned ID : OpenRanges.getVarLocs()) { // Copy OpenRanges to OutLocs, if not already present. @@ -1362,11 +1359,6 @@ bool LiveDebugValues::ExtendRanges(MachineFunction &MF) { DebugEntryVals, OverlapFragments, SeenFragments); OLChanged |= transferTerminator(MBB, OpenRanges, OutLocs, VarLocIDs); - // Add any DBG_VALUE instructions necessitated by spills. - for (auto &TR : Transfers) - MBB->insertAfterBundle(TR.TransferInst->getIterator(), TR.DebugInst); - Transfers.clear(); - LLVM_DEBUG(printVarLocInMBB(MF, OutLocs, VarLocIDs, "OutLocs after propagating", dbgs())); LLVM_DEBUG(printVarLocInMBB(MF, InLocs, VarLocIDs, @@ -1387,6 +1379,13 @@ bool LiveDebugValues::ExtendRanges(MachineFunction &MF) { assert(Pending.empty() && "Pending should be empty"); } + // Add any DBG_VALUE instructions created by location transfers. + for (auto &TR : Transfers) { + auto *MBB = TR.TransferInst->getParent(); + MBB->insertAfterBundle(TR.TransferInst->getIterator(), TR.DebugInst); + } + Transfers.clear(); + // Deferred inlocs will not have had any DBG_VALUE insts created; do // that now. flushPendingLocs(PendingInLocs, VarLocIDs); -- cgit v1.2.3