[llvm] [LiveDebugVariables] Stop holding SlotIndexes for erased instructions (PR #224467)

Petar Jovanovic via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 27 18:25:04 PDT 2026


================
@@ -1549,6 +1567,120 @@ splitRegister(Register OldReg, ArrayRef<Register> NewRegs, LiveIntervals &LIS) {
     PImpl->splitRegister(OldReg, NewRegs);
 }
 
+//===----------------------------------------------------------------------===//
+//                        Stale Index Canonicalization
+//===----------------------------------------------------------------------===//
+
+void UserValue::canonicalizeIndexes(const SlotIndexes &SI) {
+  unsigned NumStale = 0;
+  for (LocMap::const_iterator I = locInts.begin(); I.valid(); ++I)
+    NumStale += SI.isStaleIndex(I.start()) + SI.isStaleIndex(I.stop());
+  for (SlotIndex Idx : trimmedDefs)
+    NumStale += SI.isStaleIndex(Idx);
+  NumStaleIndexes += NumStale;
+
+  if (NumStale) {
+    // trimmedDefs is looked up by interval start. Remapping it here is safe:
+    // trimmed starts are block slots, so the Stop < Start case below cannot
+    // reach them, and a merge drops a start that then matches nothing.
+    if (!trimmedDefs.empty()) {
+      SmallVector<SlotIndex, 2> Defs(trimmedDefs.begin(), trimmedDefs.end());
----------------
petar-jovanovic wrote:

> Potentially expensive if this allocates -- can they not be updated in place?

It should not allocate: SmallSet<T, 2> is backed by a SmallVector<T, 2>, so the temporary has the same inline capacity. In-place updates are not really an option either, since this is a set keyed by the value being rewritten and mutating elements would violate its invariants. It is also rarely reached: trimmedDefs is only populated for inlined variables trimmed to a lexical scope.

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


More information about the llvm-commits mailing list