[llvm] [LiveDebugVariables] Stop holding SlotIndexes for erased instructions (PR #224467)
Jeremy Morse via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 28 02:20:28 PDT 2026
================
@@ -1549,6 +1567,122 @@ 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());
+ trimmedDefs.clear();
+ for (SlotIndex Idx : Defs)
+ trimmedDefs.insert(SI.canonicalizeIndex(Idx));
+ }
+
+ // Rebuild rather than move the keys of the existing map: it has to stay
+ // ordered and non-empty at every step, which canonicalization does not
+ // respect.
+ struct CanonicalInterval {
+ SlotIndex Start;
+ SlotIndex Stop;
+ DbgVariableValue Value;
+ };
+ SmallVector<CanonicalInterval, 8> Intervals;
+
+ for (LocMap::const_iterator I = locInts.begin(); I.valid(); ++I) {
+ SlotIndex Start = SI.canonicalizeIndex(I.start());
+ SlotIndex Stop = SI.canonicalizeIndex(I.stop());
+
+ // A stale stop can land below a start that sat on the same instruction's
+ // dead slot. Both resolve to the same insert location.
+ if (Stop < Start)
+ Start = Stop;
----------------
jmorse wrote:
Is this a scenario where we should early-continue and drop the interval as having zero length?
https://github.com/llvm/llvm-project/pull/224467
More information about the llvm-commits
mailing list