Skip to content

Commit 497d648

Browse files
authored
[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
1 parent 6308cd8 commit 497d648

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

llvm/lib/Target/AMDGPU/AMDGPURewriteAGPRCopyMFMA.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -482,12 +482,13 @@ void AMDGPURewriteAGPRCopyMFMAImpl::eliminateSpillsOfReassignedVGPRs() const {
482482
}
483483

484484
sort(StackIntervals, [](const LiveInterval *A, const LiveInterval *B) {
485+
// The ordering has to be strictly weak.
485486
/// Sort heaviest intervals first to prioritize their unspilling
486-
if (A->weight() > B->weight())
487-
return true;
487+
if (A->weight() != B->weight())
488+
return A->weight() > B->weight();
488489

489-
if (A->getSize() > B->getSize())
490-
return true;
490+
if (A->getSize() != B->getSize())
491+
return A->getSize() > B->getSize();
491492

492493
// Tie breaker by number to avoid need for stable sort
493494
return A->reg().stackSlotIndex() < B->reg().stackSlotIndex();

0 commit comments

Comments
 (0)