Skip to content

Conversation

@arsenm
Copy link
Contributor

@arsenm arsenm commented Sep 24, 2025

Instead of checking if the recoloring candidate is a virtual register,
avoid adding it to the candidates in the first place.

@llvmbot
Copy link
Member

llvmbot commented Sep 24, 2025

@llvm/pr-subscribers-llvm-regalloc

Author: Matt Arsenault (arsenm)

Changes

Instead of checking if the recoloring candidate is a virtual register,
avoid adding it to the candidates in the first place.


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

1 Files Affected:

  • (modified) llvm/lib/CodeGen/RegAllocGreedy.cpp (+2-5)
diff --git a/llvm/lib/CodeGen/RegAllocGreedy.cpp b/llvm/lib/CodeGen/RegAllocGreedy.cpp
index 6e0585b2e9e55..dc23ab3ce9d2b 100644
--- a/llvm/lib/CodeGen/RegAllocGreedy.cpp
+++ b/llvm/lib/CodeGen/RegAllocGreedy.cpp
@@ -2502,10 +2502,6 @@ void RAGreedy::tryHintRecoloring(const LiveInterval &VirtReg) {
   do {
     Reg = RecoloringCandidates.pop_back_val();
 
-    // We cannot recolor physical register.
-    if (Reg.isPhysical())
-      continue;
-
     // This may be a skipped register.
     if (!VRM->hasPhys(Reg)) {
       assert(!shouldAllocateRegister(Reg) &&
@@ -2553,7 +2549,8 @@ void RAGreedy::tryHintRecoloring(const LiveInterval &VirtReg) {
     // Push all copy-related live-ranges to keep reconciling the broken
     // hints.
     for (const HintInfo &HI : Info) {
-      if (Visited.insert(HI.Reg).second)
+      // We cannot recolor physical register.
+      if (HI.Reg.isVirtual() && Visited.insert(HI.Reg).second)
         RecoloringCandidates.push_back(HI.Reg);
     }
   } while (!RecoloringCandidates.empty());

@llvmbot
Copy link
Member

llvmbot commented Sep 24, 2025

@llvm/pr-subscribers-backend-systemz

Author: Matt Arsenault (arsenm)

Changes

Instead of checking if the recoloring candidate is a virtual register,
avoid adding it to the candidates in the first place.


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

1 Files Affected:

  • (modified) llvm/lib/CodeGen/RegAllocGreedy.cpp (+2-5)
diff --git a/llvm/lib/CodeGen/RegAllocGreedy.cpp b/llvm/lib/CodeGen/RegAllocGreedy.cpp
index 6e0585b2e9e55..dc23ab3ce9d2b 100644
--- a/llvm/lib/CodeGen/RegAllocGreedy.cpp
+++ b/llvm/lib/CodeGen/RegAllocGreedy.cpp
@@ -2502,10 +2502,6 @@ void RAGreedy::tryHintRecoloring(const LiveInterval &VirtReg) {
   do {
     Reg = RecoloringCandidates.pop_back_val();
 
-    // We cannot recolor physical register.
-    if (Reg.isPhysical())
-      continue;
-
     // This may be a skipped register.
     if (!VRM->hasPhys(Reg)) {
       assert(!shouldAllocateRegister(Reg) &&
@@ -2553,7 +2549,8 @@ void RAGreedy::tryHintRecoloring(const LiveInterval &VirtReg) {
     // Push all copy-related live-ranges to keep reconciling the broken
     // hints.
     for (const HintInfo &HI : Info) {
-      if (Visited.insert(HI.Reg).second)
+      // We cannot recolor physical register.
+      if (HI.Reg.isVirtual() && Visited.insert(HI.Reg).second)
         RecoloringCandidates.push_back(HI.Reg);
     }
   } while (!RecoloringCandidates.empty());

@llvmbot
Copy link
Member

llvmbot commented Sep 24, 2025

@llvm/pr-subscribers-backend-x86

Author: Matt Arsenault (arsenm)

Changes

Instead of checking if the recoloring candidate is a virtual register,
avoid adding it to the candidates in the first place.


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

1 Files Affected:

  • (modified) llvm/lib/CodeGen/RegAllocGreedy.cpp (+2-5)
diff --git a/llvm/lib/CodeGen/RegAllocGreedy.cpp b/llvm/lib/CodeGen/RegAllocGreedy.cpp
index 6e0585b2e9e55..dc23ab3ce9d2b 100644
--- a/llvm/lib/CodeGen/RegAllocGreedy.cpp
+++ b/llvm/lib/CodeGen/RegAllocGreedy.cpp
@@ -2502,10 +2502,6 @@ void RAGreedy::tryHintRecoloring(const LiveInterval &VirtReg) {
   do {
     Reg = RecoloringCandidates.pop_back_val();
 
-    // We cannot recolor physical register.
-    if (Reg.isPhysical())
-      continue;
-
     // This may be a skipped register.
     if (!VRM->hasPhys(Reg)) {
       assert(!shouldAllocateRegister(Reg) &&
@@ -2553,7 +2549,8 @@ void RAGreedy::tryHintRecoloring(const LiveInterval &VirtReg) {
     // Push all copy-related live-ranges to keep reconciling the broken
     // hints.
     for (const HintInfo &HI : Info) {
-      if (Visited.insert(HI.Reg).second)
+      // We cannot recolor physical register.
+      if (HI.Reg.isVirtual() && Visited.insert(HI.Reg).second)
         RecoloringCandidates.push_back(HI.Reg);
     }
   } while (!RecoloringCandidates.empty());

Copy link
Collaborator

@preames preames left a comment

Choose a reason for hiding this comment

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

LGTM

@arsenm arsenm force-pushed the users/arsenm/greedy/trySplitAroundHintReg-subreg branch from f98b2e0 to 205e4cd Compare September 26, 2025 15:48
@arsenm arsenm force-pushed the users/arsenm/greedy/move-physreg-check-tryHintRecoloring branch from 19296e2 to f588d48 Compare September 26, 2025 15:48
@arsenm arsenm force-pushed the users/arsenm/greedy/trySplitAroundHintReg-subreg branch from 205e4cd to 5f93f5c Compare September 27, 2025 01:35
@arsenm arsenm force-pushed the users/arsenm/greedy/move-physreg-check-tryHintRecoloring branch from f588d48 to 5e1d9bb Compare September 27, 2025 01:35
Copy link
Collaborator

@qcolombet qcolombet left a comment

Choose a reason for hiding this comment

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

Good catch!

arsenm added 2 commits October 2, 2025 20:41
For subregister copies, do a subregister live check instead of checking
the main range. Doesn't do much yet, the split analysis still does not
track live ranges.
Instead of checking if the recoloring candidate is a virtual register,
avoid adding it to the candidates in the first place.
@arsenm arsenm force-pushed the users/arsenm/greedy/move-physreg-check-tryHintRecoloring branch from 5e1d9bb to 9c6c1a9 Compare October 2, 2025 11:42
@arsenm arsenm force-pushed the users/arsenm/greedy/trySplitAroundHintReg-subreg branch from 5f93f5c to 661b22d Compare October 2, 2025 11:42
Base automatically changed from users/arsenm/greedy/trySplitAroundHintReg-subreg to main October 2, 2025 12:21
@arsenm arsenm merged commit c4e1bca into main Oct 2, 2025
14 of 15 checks passed
@arsenm arsenm deleted the users/arsenm/greedy/move-physreg-check-tryHintRecoloring branch October 2, 2025 13:24
mahesh-attarde pushed a commit to mahesh-attarde/llvm-project that referenced this pull request Oct 3, 2025
…60484)

Instead of checking if the recoloring candidate is a virtual register,
avoid adding it to the candidates in the first place.
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.

5 participants