[llvm] [DebugInfo][ConstraintElimination] Fix debug value loss in replacing comparisons with the speculated constants (PR #136839)

Shan Huang via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 23 19:26:21 PDT 2025


================
@@ -1454,8 +1455,20 @@ static bool checkAndReplaceCondition(
       return ShouldReplace;
     });
     NumCondsRemoved++;
-    if (Cmp->use_empty())
+    if (Cmp->use_empty()) {
+      SmallVector<DbgVariableIntrinsic *> DbgUsers;
+      SmallVector<DbgVariableRecord *> DVRUsers;
+      findDbgUsers(DbgUsers, Cmp, &DVRUsers);
+
+      for (auto *DVR : DVRUsers) {
+        auto *DTN = DT.getNode(DVR->getParent());
+        if (!DTN || DTN->getDFSNumIn() < NumIn || DTN->getDFSNumOut() > NumOut)
+          continue;
+        DVR->replaceVariableLocationOp(Cmp, ConstantC);
----------------
Apochens wrote:

I have added this as another regression test `salvage-dbg-values-replaced-by-constant-2.ll`. However, the optimized IR shows that the forth `dbg_value` cannot be updated as well, because the `ContextInst` is `%t.2`.

https://github.com/llvm/llvm-project/pull/136839


More information about the llvm-commits mailing list