[llvm] [CodeGen] Fix incorrect index in rematerialization tracking (PR #194387)
Lucas Ramirez via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 27 07:18:54 PDT 2026
https://github.com/lucas-rami created https://github.com/llvm/llvm-project/pull/194387
When deleting the last rematerialization of a register, we should delete the rematerializer's remat tracking map's entry that corresponds to the index of the *original* register, not the rematerialized register.
The existing typo has no impact on correctness at the moment because entries with rematerialized register indices are never created (so there is nothing to erase), and having an empty set in a value does not break any code invariant; it just wastes memory.
Assisted-by: Claude Code
>From 64f4b279e563e2d2cd91d1141b5b51e2b73f67e7 Mon Sep 17 00:00:00 2001
From: Lucas Ramirez <lucas.rami at proton.me>
Date: Mon, 27 Apr 2026 13:52:48 +0000
Subject: [PATCH] [CodeGen] Fix incorrect index in rematerialization tracking
When deleting the last rematerialization of a register, we should delete
the rematerializer's remat tracking map's entry that corresponds to the
index of the *original* register, not the rematerialized register.
The existing typo has no impact on correctness at the moment because
entries with rematerialized register indices are never created (so there
is nothing to erase), and having an empty set in a value does not break
any code invariant; it just wastes memory.
---
llvm/lib/CodeGen/Rematerializer.cpp | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/llvm/lib/CodeGen/Rematerializer.cpp b/llvm/lib/CodeGen/Rematerializer.cpp
index 19dd3c54d61de..c4edface1e27f 100644
--- a/llvm/lib/CodeGen/Rematerializer.cpp
+++ b/llvm/lib/CodeGen/Rematerializer.cpp
@@ -310,11 +310,12 @@ void Rematerializer::deleteRegIfUnused(RegisterIdx RootIdx) {
deleteReg(RegIdx);
if (isRematerializedRegister(RegIdx)) {
// Delete rematerialized register from its origin's rematerializations.
- RematsOf &OriginRemats = Rematerializations.at(getOriginOf(RegIdx));
+ const RegisterIdx OriginIdx = getOriginOf(RegIdx);
+ RematsOf &OriginRemats = Rematerializations.at(OriginIdx);
assert(OriginRemats.contains(RegIdx) && "broken remat<->origin link");
OriginRemats.erase(RegIdx);
if (OriginRemats.empty())
- Rematerializations.erase(RegIdx);
+ Rematerializations.erase(OriginIdx);
}
LLVM_DEBUG(dbgs() << "** Deleted " << printID(RegIdx) << "\n");
}
More information about the llvm-commits
mailing list