[llvm] [RemoveDIs] Fix removeRedundantDdbgInstrs utils for dbg.declares (PR #74102)

Orlando Cazalet-Hyams via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 1 08:34:35 PST 2023


https://github.com/OCHyams created https://github.com/llvm/llvm-project/pull/74102

The intrinsic variants of these functions don't do anything to dbg.declares so the non-instruction variants should too.

Tested in llvm/test/DebugInfo/duplicate_dbgvalue.ll, which has `--try-experimental-debuginfo-iterators` added in #73504.



>From 48dbd6b74bab9f923efa587a8e5b1cd7e87eb958 Mon Sep 17 00:00:00 2001
From: OCHyams <orlando.hyams at sony.com>
Date: Fri, 24 Nov 2023 16:47:06 +0000
Subject: [PATCH] [RemoveDIs] Fix removeRedundantDdbgInstrs utils for
 dbg.declares

The intrinsic variants of these functions don't do anything to
dbg.declares so the non-instruction variants should too.

Tested in llvm/test/DebugInfo/duplicate_dbgvalue.ll, which has
`--try-experimental-debuginfo-iterators` added in #73504.
---
 llvm/lib/Transforms/Utils/BasicBlockUtils.cpp | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
index ccee97025e3c3f9..1c6b4986c03425f 100644
--- a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
+++ b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
@@ -387,6 +387,8 @@ static bool DPValuesRemoveRedundantDbgInstrsUsingBackwardScan(BasicBlock *BB) {
   SmallDenseSet<DebugVariable> VariableSet;
   for (auto &I : reverse(*BB)) {
     for (DPValue &DPV : reverse(I.getDbgValueRange())) {
+      if (DPV.getType() == DPValue::LocationType::Declare)
+        continue;
       DebugVariable Key(DPV.getVariable(), DPV.getExpression(),
                         DPV.getDebugLoc()->getInlinedAt());
       auto R = VariableSet.insert(Key);
@@ -478,6 +480,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);



More information about the llvm-commits mailing list