[llvm] [DebugInfo][RemoveDIs] Instrument jump-threading to update DPValues (PR #73127)

Jeremy Morse via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 23 08:37:25 PST 2023


================
@@ -410,6 +410,10 @@ static bool replaceFoldableUses(Instruction *Cond, Value *ToVal,
   if (Cond->getParent() == KnownAtEndOfBB)
     Changed |= replaceNonLocalUsesWith(Cond, ToVal);
   for (Instruction &I : reverse(*KnownAtEndOfBB)) {
+    // Replace any debug-info record users of Cond with ToVal.
+    for (DPValue &DPV : I.getDbgValueRange())
+      DPV.replaceVariableLocationOp(Cond, ToVal, true);
----------------
jmorse wrote:

It's more of a check-my-errors flag -- using replaceVariableLocationOp on debug intrinsics that don't use the "Source" value is considered an error, and there's an assertion for that. Wheras this code here is speculatively trying to "replace this value if it's used, never mind if it isn't", and the AllowEmpty parameter signals that there shouldn't be an error if the Source value can't be found.

There are a bunch of different ways of doing this, I'll admit I haven't thought about how to restructure it, but it's an existing API call on DbgValueInst, so I didn't want to get too far away from that.

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


More information about the llvm-commits mailing list