[llvm] 40edb37 - [StackSlotColoring] Fix issue where colors for a StackID are dropped (#138140)

via llvm-commits llvm-commits at lists.llvm.org
Fri May 2 02:23:43 PDT 2025


Author: Benjamin Maxwell
Date: 2025-05-02T10:23:39+01:00
New Revision: 40edb37bb370541b71657fc308ba26b1ec2deb16

URL: https://github.com/llvm/llvm-project/commit/40edb37bb370541b71657fc308ba26b1ec2deb16
DIFF: https://github.com/llvm/llvm-project/commit/40edb37bb370541b71657fc308ba26b1ec2deb16.diff

LOG: [StackSlotColoring] Fix issue where colors for a StackID are dropped (#138140)

In InitializeSlots, if an interval with a non-zero StackID (A) is
encountered we set All/UsedColors to a size of A + 1. If after this we
process another interval with a non-zero StackID (B), where B < A, then
we resize All/UsedColors to size < A + 1, and lose the BitVector
associated with A.

AFAIK this is a latent bug upstream, but when adding a new TargetStackID
locally I hit a `NextColors[StackID] != -1 && "No more spill slots?"`
assertion due to this issue.

Added: 
    

Modified: 
    llvm/lib/CodeGen/StackSlotColoring.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/StackSlotColoring.cpp b/llvm/lib/CodeGen/StackSlotColoring.cpp
index 6e1c9fd167174..2f81bea4e86ba 100644
--- a/llvm/lib/CodeGen/StackSlotColoring.cpp
+++ b/llvm/lib/CodeGen/StackSlotColoring.cpp
@@ -287,8 +287,10 @@ void StackSlotColoring::InitializeSlots() {
 
     auto StackID = MFI->getStackID(FI);
     if (StackID != 0) {
-      AllColors.resize(StackID + 1);
-      UsedColors.resize(StackID + 1);
+      if (StackID >= AllColors.size()) {
+        AllColors.resize(StackID + 1);
+        UsedColors.resize(StackID + 1);
+      }
       AllColors[StackID].resize(LastFI);
       UsedColors[StackID].resize(LastFI);
     }


        


More information about the llvm-commits mailing list