Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion llvm/lib/Target/AMDGPU/AMDGPURewriteAGPRCopyMFMA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// The ordering have to be strictly weak.
// The ordering has to be strictly weak.

return (A->reg().stackSlotIndex() < B->reg().stackSlotIndex()) &&
((A->weight() <= B->weight()) && (A->getSize() <= B->getSize()));
Copy link
Preview

Copilot AI Oct 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comparator logic is incorrect and still violates strict weak ordering. The current implementation can return false for both comp(a,b) and comp(b,a) when elements have the same stackSlotIndex, which breaks antisymmetry. For strict weak ordering, when primary criteria are equal, you should use a single tie-breaker. Consider using: return A->reg().stackSlotIndex() < B->reg().stackSlotIndex(); as the sole comparator, or if multiple criteria are needed, use lexicographic ordering like: if (A->weight() != B->weight()) return A->weight() < B->weight(); if (A->getSize() != B->getSize()) return A->getSize() < B->getSize(); return A->reg().stackSlotIndex() < B->reg().stackSlotIndex();

Copilot uses AI. Check for mistakes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using: return A->reg().stackSlotIndex() < B->reg().stackSlotIndex();

As mentioned in the issue, this is not the right solution for making strict weak ordering.

But it's also true that my change has the issue with when comp(a,b) and comp(b,a) can both be false 🤦 . Updating the logic to use the lexicographic ordering suggestion.

});

// FIXME: The APIs for dealing with the LiveInterval of a frame index are
Expand Down
Loading