Skip to content

[InlineSpiller] Drop unused elements in Virt2SiblingsMap. NFC #147866

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

csstormq
Copy link
Contributor

No description provided.

@llvmbot
Copy link
Member

llvmbot commented Jul 10, 2025

@llvm/pr-subscribers-llvm-regalloc

Author: None (csstormq)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/147866.diff

1 Files Affected:

  • (modified) llvm/lib/CodeGen/InlineSpiller.cpp (+1-1)
diff --git a/llvm/lib/CodeGen/InlineSpiller.cpp b/llvm/lib/CodeGen/InlineSpiller.cpp
index ee08dc42dce57..18ec0bc1c050c 100644
--- a/llvm/lib/CodeGen/InlineSpiller.cpp
+++ b/llvm/lib/CodeGen/InlineSpiller.cpp
@@ -1657,7 +1657,7 @@ void HoistSpillHelper::hoistAllSpills() {
   for (unsigned i = 0, e = MRI.getNumVirtRegs(); i != e; ++i) {
     Register Reg = Register::index2VirtReg(i);
     Register Original = VRM.getPreSplitReg(Reg);
-    if (!MRI.def_empty(Reg))
+    if (!MRI.def_empty(Reg) && Original.id())
       Virt2SiblingsMap[Original].insert(Reg);
   }
 

Copy link
Contributor

@arsenm arsenm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this. 0 isn't an invalid register index, it's the first valid virtual register index.

@csstormq
Copy link
Contributor Author

I don't understand this. 0 isn't an invalid register index, it's the first valid virtual register index.

@arsenm , thanks for your review. In my opinion, the key of Virt2SiblingsMap (the original register) should always hold the equal value as its corresponding value (the sibling register). However, the getPreSplitReg function returns 0, register number rather than register index, when encountering a register that was not created by splitting. Consequently, Virt2SiblingsMap[0] ends up storing registers with differing values, which directly contradicts the map's design principle.

@csstormq csstormq requested a review from arsenm July 10, 2025 07:29
@arsenm
Copy link
Contributor

arsenm commented Jul 10, 2025

However, the getPreSplitReg function returns 0, register number rather than register index, when encountering a register that was not created by splitting.

As in Register()? You shouldn't be checking against .id() == 0 for that case, rely on bool conversion?

@csstormq
Copy link
Contributor Author

As in Register()? You shouldn't be checking against .id() == 0 for that case, rely on bool conversion?

Thanks for the advice. I’ve updated the code accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants