[llvm] [AMDGPU] Make sort ordering in `AMDGPURewriteAGPRCopyMFMAImpl::eliminateSpillsOfReassignedVGPRs()` strict weak. (PR #162493)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 8 08:15:21 PDT 2025


================
@@ -482,15 +482,16 @@ void AMDGPURewriteAGPRCopyMFMAImpl::eliminateSpillsOfReassignedVGPRs() const {
   }
 
   sort(StackIntervals, [](const LiveInterval *A, const LiveInterval *B) {
+    // The ordering have to be strictly weak.
     /// Sort heaviest intervals first to prioritize their unspilling
-    if (A->weight() > B->weight())
-      return true;
+    if (A->weight() != B->weight())
+      return A->weight() > B->weight();
 
-    if (A->getSize() > B->getSize())
-      return true;
+    if (A->getSize() != B->getSize())
+      return A->getSize() > B->getSize();
 
     // Tie breaker by number to avoid need for stable sort
-    return A->reg().stackSlotIndex() < B->reg().stackSlotIndex();
+    return (A->reg().stackSlotIndex() < B->reg().stackSlotIndex());
----------------
arsenm wrote:

```suggestion
    return A->reg().stackSlotIndex() < B->reg().stackSlotIndex();
```

https://github.com/llvm/llvm-project/pull/162493


More information about the llvm-commits mailing list