From 300ac0aa85864ddd4ec1b5eb65ae52918434d003 Mon Sep 17 00:00:00 2001 From: Orlando Cazalet-Hyams Date: Tue, 12 Dec 2023 14:53:27 +0000 Subject: [RemoveDIs] Fix removeRedundantDdbgInstrs utils for dbg.declares (#74102) The intrinsic variants of these functions don't do anything to dbg.declares so the non-instruction variants should ignore them too. Tested in llvm/test/DebugInfo/duplicate_dbgvalue.ll, which has `--try-experimental-debuginfo-iterators` added in #73504. The tests will become "live" once #74090 lands (see for more info). --- llvm/lib/Transforms/Utils/BasicBlockUtils.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'llvm/lib/Transforms/Utils/BasicBlockUtils.cpp') diff --git a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp index b700edf..8b5a6d6 100644 --- a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp +++ b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp @@ -387,6 +387,18 @@ static bool DPValuesRemoveRedundantDbgInstrsUsingBackwardScan(BasicBlock *BB) { SmallDenseSet VariableSet; for (auto &I : reverse(*BB)) { for (DPValue &DPV : reverse(I.getDbgValueRange())) { + // Skip declare-type records, as the debug intrinsic method only works + // on dbg.value intrinsics. + if (DPV.getType() == DPValue::LocationType::Declare) { + // The debug intrinsic method treats dbg.declares are "non-debug" + // instructions (i.e., a break in a consecutive range of debug + // intrinsics). Emulate that to create identical outputs. See + // "Possible improvements" above. + // FIXME: Delete the line below. + VariableSet.clear(); + continue; + } + DebugVariable Key(DPV.getVariable(), DPV.getExpression(), DPV.getDebugLoc()->getInlinedAt()); auto R = VariableSet.insert(Key); @@ -478,6 +490,8 @@ static bool DPValuesRemoveRedundantDbgInstrsUsingForwardScan(BasicBlock *BB) { VariableMap; for (auto &I : *BB) { for (DPValue &DPV : I.getDbgValueRange()) { + if (DPV.getType() == DPValue::LocationType::Declare) + continue; DebugVariable Key(DPV.getVariable(), std::nullopt, DPV.getDebugLoc()->getInlinedAt()); auto VMI = VariableMap.find(Key); -- cgit v1.1