[llvm] 497d648 - [AMDGPU] Make sort ordering in `AMDGPURewriteAGPRCopyMFMAImpl::eliminateSpillsOfReassignedVGPRs()` strict weak. (#162493)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 8 10:05:12 PDT 2025
Author: weiwei chen
Date: 2025-10-08T13:05:08-04:00
New Revision: 497d648fcc096eff968cbfc32c37c96661d14158
URL: https://github.com/llvm/llvm-project/commit/497d648fcc096eff968cbfc32c37c96661d14158
DIFF: https://github.com/llvm/llvm-project/commit/497d648fcc096eff968cbfc32c37c96661d14158.diff
LOG: [AMDGPU] Make sort ordering in `AMDGPURewriteAGPRCopyMFMAImpl::eliminateSpillsOfReassignedVGPRs()` strict weak. (#162493)
- [x] `sort` needs the comparator with strictly weak ordering, however
current logic doesn't meet the
[**Antisymmetry**](https://tanjim131.github.io/2020-05-22-strict-weak-ordering/#:~:text=Almost%20all%20C++%20STL%20containers,the%20person%20with%20greater%20height.)
requirement with
```
sort 0x561ecd3d3db0,0x561eaba91d10 25
weight 0.000000e+00,0.000000e+00
size 650370,662754
slot 732,733
```
Make the comparator logic strict weak order.
Fixes #162490
Added:
Modified:
llvm/lib/Target/AMDGPU/AMDGPURewriteAGPRCopyMFMA.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/AMDGPU/AMDGPURewriteAGPRCopyMFMA.cpp b/llvm/lib/Target/AMDGPU/AMDGPURewriteAGPRCopyMFMA.cpp
index fedb694bfcc2a..89c16dadb4b41 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPURewriteAGPRCopyMFMA.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPURewriteAGPRCopyMFMA.cpp
@@ -482,12 +482,13 @@ void AMDGPURewriteAGPRCopyMFMAImpl::eliminateSpillsOfReassignedVGPRs() const {
}
sort(StackIntervals, [](const LiveInterval *A, const LiveInterval *B) {
+ // The ordering has 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();
More information about the llvm-commits
mailing list