[llvm] [AArch64] Correct comparator in regalloc hints to satisfy strict weak ordering (PR #192383)
Leonardo Román Carrillo via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 15 20:49:14 PDT 2026
https://github.com/leonardo-roman-carrillo created https://github.com/llvm/llvm-project/pull/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.
>From a4dc89c0ff59f21a9560914c42869f6a90c88889 Mon Sep 17 00:00:00 2001
From: Leonardo Roman <leonardoroman at google.com>
Date: Thu, 16 Apr 2026 03:32:15 +0000
Subject: [PATCH] [AArch64] Correct comparator in regalloc hints to satisfy
strict weak ordering.
---
llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp b/llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp
index f232fa79c7022..662ec6563e28a 100644
--- a/llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp
+++ b/llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp
@@ -1158,8 +1158,10 @@ static bool HandleDestructivePredicateHint(
Hints.append(Order.begin(), Order.end());
llvm::stable_sort(Hints, [&](Register A, Register B) {
- return A != B && B == Op1Reg &&
- (!CSRs.contains(A) || !MRI.def_empty(A) || Matrix->isPhysRegUsed(A));
+ return ((A == Op1Reg) || !(!CSRs.contains(A) || !MRI.def_empty(A) ||
+ Matrix->isPhysRegUsed(A))) <
+ ((B == Op1Reg) || !(!CSRs.contains(B) || !MRI.def_empty(B) ||
+ Matrix->isPhysRegUsed(B)));
});
return true;
}
More information about the llvm-commits
mailing list