From 97861981cccce546b37f56e3e99e68d37c7586c7 Mon Sep 17 00:00:00 2001 From: David Stenberg Date: Fri, 20 Sep 2024 13:04:45 +0200 Subject: [LiveDebugVariables] Fix a DBG_VALUE reordering issue (#111124) LDV could reorder reinserted fragment and non-fragment debug values for the same variable (compared to the input order), potentially resulting in stale values being presented. For example, before: DBG_VALUE 1001, $noreg, !13, !DIExpression(DW_OP_LLVM_fragment, 0, 16) DBG_VALUE 1002, $noreg, !13, !DIExpression(DW_OP_LLVM_fragment, 16, 16) DBG_VALUE %0, $noreg, !13, !DIExpression() After (without this patch): DBG_VALUE %stack.0, 0, !13, !DIExpression() DBG_VALUE 1002, $noreg, !13, !DIExpression(DW_OP_LLVM_fragment, 16, 16) DBG_VALUE 1001, $noreg, !13, !DIExpression(DW_OP_LLVM_fragment, 0, 16) It would also reorder DBG_VALUEs for different variables. Although that does not matter for the debug information output, it resulted in some noise in before/after pass diffs. This should hopefully align so that instruction referencing and DBG_VALUE emit debug instructions in the same order (see the sdag-salvage-add.ll change). --- llvm/lib/CodeGen/LiveDebugVariables.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'llvm/lib/CodeGen/LiveDebugVariables.cpp') diff --git a/llvm/lib/CodeGen/LiveDebugVariables.cpp b/llvm/lib/CodeGen/LiveDebugVariables.cpp index 822a1be..2ff346d 100644 --- a/llvm/lib/CodeGen/LiveDebugVariables.cpp +++ b/llvm/lib/CodeGen/LiveDebugVariables.cpp @@ -1625,8 +1625,9 @@ findInsertLocation(MachineBasicBlock *MBB, SlotIndex Idx, LiveIntervals &LIS, } // Don't insert anything after the first terminator, though. - return MI->isTerminator() ? MBB->getFirstTerminator() : - std::next(MachineBasicBlock::iterator(MI)); + auto It = MI->isTerminator() ? MBB->getFirstTerminator() + : std::next(MachineBasicBlock::iterator(MI)); + return skipDebugInstructionsForward(It, MBB->end()); } /// Find an iterator for inserting the next DBG_VALUE instruction -- cgit v1.1