[llvm] [AMDGPU] Make sort ordering in `AMDGPURewriteAGPRCopyMFMAImpl::eliminateSpillsOfReassignedVGPRs()` strictly weak. (PR #162493)
weiwei chen via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 8 07:43:21 PDT 2025
https://github.com/weiweichen created https://github.com/llvm/llvm-project/pull/162493
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.
>From 56f9ded2a32e8f8ef2c3492f7260ab2aa79eccaf Mon Sep 17 00:00:00 2001
From: Weiwei Chen <weiwei.chen at modular.com>
Date: Wed, 8 Oct 2025 10:35:36 -0400
Subject: [PATCH] Make sort ordering strictly weak.
---
llvm/lib/Target/AMDGPU/AMDGPURewriteAGPRCopyMFMA.cpp | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
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
More information about the llvm-commits
mailing list