diff --git a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp index b700edf8ea6c0..8b5a6d6184120 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);