Skip to content

Commit 300ac0a

Browse files
authored
[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).
1 parent 5457fab commit 300ac0a

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

llvm/lib/Transforms/Utils/BasicBlockUtils.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,18 @@ static bool DPValuesRemoveRedundantDbgInstrsUsingBackwardScan(BasicBlock *BB) {
387387
SmallDenseSet<DebugVariable> VariableSet;
388388
for (auto &I : reverse(*BB)) {
389389
for (DPValue &DPV : reverse(I.getDbgValueRange())) {
390+
// Skip declare-type records, as the debug intrinsic method only works
391+
// on dbg.value intrinsics.
392+
if (DPV.getType() == DPValue::LocationType::Declare) {
393+
// The debug intrinsic method treats dbg.declares are "non-debug"
394+
// instructions (i.e., a break in a consecutive range of debug
395+
// intrinsics). Emulate that to create identical outputs. See
396+
// "Possible improvements" above.
397+
// FIXME: Delete the line below.
398+
VariableSet.clear();
399+
continue;
400+
}
401+
390402
DebugVariable Key(DPV.getVariable(), DPV.getExpression(),
391403
DPV.getDebugLoc()->getInlinedAt());
392404
auto R = VariableSet.insert(Key);
@@ -478,6 +490,8 @@ static bool DPValuesRemoveRedundantDbgInstrsUsingForwardScan(BasicBlock *BB) {
478490
VariableMap;
479491
for (auto &I : *BB) {
480492
for (DPValue &DPV : I.getDbgValueRange()) {
493+
if (DPV.getType() == DPValue::LocationType::Declare)
494+
continue;
481495
DebugVariable Key(DPV.getVariable(), std::nullopt,
482496
DPV.getDebugLoc()->getInlinedAt());
483497
auto VMI = VariableMap.find(Key);

0 commit comments

Comments
 (0)