[llvm] [AMDGPU] Make sort ordering in `AMDGPURewriteAGPRCopyMFMAImpl::eliminateSpillsOfReassignedVGPRs()` strict weak. (PR #162493)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 8 07:44:00 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-amdgpu
Author: weiwei chen (weiweichen)
<details>
<summary>Changes</summary>
To fix the crash mentioned in
https://github.com/llvm/llvm-project/issues/162490
- [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.
---
Full diff: https://github.com/llvm/llvm-project/pull/162493.diff
1 Files Affected:
- (modified) llvm/lib/Target/AMDGPU/AMDGPURewriteAGPRCopyMFMA.cpp (+3-1)
``````````diff
diff --git a/llvm/lib/Target/AMDGPU/AMDGPURewriteAGPRCopyMFMA.cpp b/llvm/lib/Target/AMDGPU/AMDGPURewriteAGPRCopyMFMA.cpp
index fedb694bfcc2a..caaa92999fd1a 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPURewriteAGPRCopyMFMA.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPURewriteAGPRCopyMFMA.cpp
@@ -490,7 +490,9 @@ void AMDGPURewriteAGPRCopyMFMAImpl::eliminateSpillsOfReassignedVGPRs() const {
return true;
// Tie breaker by number to avoid need for stable sort
- return A->reg().stackSlotIndex() < B->reg().stackSlotIndex();
+ // The ordering have to be strictly weak.
+ return (A->reg().stackSlotIndex() < B->reg().stackSlotIndex()) &&
+ ((A->weight() <= B->weight()) && (A->getSize() <= B->getSize()));
});
// FIXME: The APIs for dealing with the LiveInterval of a frame index are
``````````
</details>
https://github.com/llvm/llvm-project/pull/162493
More information about the llvm-commits
mailing list