[llvm] 2322511 - [AArch64] Correct comparator in regalloc hints to satisfy strict weak ordering (#192383)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 16 08:13:15 PDT 2026
Author: Leonardo Román Carrillo
Date: 2026-04-16T15:13:09Z
New Revision: 232251164fe1fe7336450bfd61810aa9b812c6bb
URL: https://github.com/llvm/llvm-project/commit/232251164fe1fe7336450bfd61810aa9b812c6bb
DIFF: https://github.com/llvm/llvm-project/commit/232251164fe1fe7336450bfd61810aa9b812c6bb.diff
LOG: [AArch64] Correct comparator in regalloc hints to satisfy strict weak ordering (#192383)
The current comparator will have a strict-weak ordering violation for
the following scenario:
a = GoodReg ((!CSRs.contains(A) || !MRI.def_empty(A) ||
Matrix->isPhysRegUsed(A)) == true) && !Op1Reg
b = BadReg ((!CSRs.contains(A) || !MRI.def_empty(A) ||
Matrix->isPhysRegUsed(A)) == false) && !Op1Reg
c = Op1Reg
Then we would have:
a vs c
A != B && B == Op1Reg && (!CSRs.contains(A) || !MRI.def_empty(A) ||
Matrix->isPhysRegUsed(A)) = true && true && true ->
a < c
a vs b
A != B && B == Op1Reg && (!CSRs.contains(A) || !MRI.def_empty(A) ||
Matrix->isPhysRegUsed(A)) =true && false && false ->
a ~ b
b vs c
A != B && B == Op1Reg && (!CSRs.contains(A) || !MRI.def_empty(A) ||
Matrix->isPhysRegUsed(A)) = true && true && false ->
b ~ c
That will result in a strict-weak ordering violation (a < c && a ~ c),
with the new implementation we define that a < b && a < c.
Added:
Modified:
llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp b/llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp
index f232fa79c7022..51ef14f4ee1fa 100644
--- a/llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp
+++ b/llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp
@@ -1157,9 +1157,13 @@ static bool HandleDestructivePredicateHint(
}
Hints.append(Order.begin(), Order.end());
+ auto CanUseReg = [&](Register R) {
+ return !CSRs.contains(R) || !MRI.def_empty(R) || Matrix->isPhysRegUsed(R);
+ };
llvm::stable_sort(Hints, [&](Register A, Register B) {
- return A != B && B == Op1Reg &&
- (!CSRs.contains(A) || !MRI.def_empty(A) || Matrix->isPhysRegUsed(A));
+ bool PrefA = (A != Op1Reg) && CanUseReg(A);
+ bool PrefB = (B != Op1Reg) && CanUseReg(B);
+ return PrefA && !PrefB;
});
return true;
}
More information about the llvm-commits
mailing list