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

Orlando Cazalet-Hyams via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 29 08:03:06 PDT 2025


================
@@ -1454,8 +1455,29 @@ static bool checkAndReplaceCondition(
       return ShouldReplace;
     });
     NumCondsRemoved++;
+
+    // Update the debug value records that satisfy the same condition used
+    // in replaceUsesWithIf.
+    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;
+
+      auto *MarkedI = DVR->getInstruction();
+      if (MarkedI->getParent() == ContextInst->getParent() &&
+          MarkedI->comesBefore(ContextInst))
+        continue;
----------------
OCHyams wrote:

Hmm, part of me wants to reduce code duplication by introducing a lambda that is used by this code and the checks in `replaceUsesWithIf` above. That gives an added benefit of naming what it's doing. On the other hand, that might be more boilerplate than is needed here, so I'm happy for it to stay as it is too.

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


More information about the llvm-commits mailing list