[llvm] bf2f9d2 - [TableGen] Make OpcodeMappings sort comparator strict weak ordering compliant
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 29 13:55:56 PDT 2023
Author: Danila Kutenin
Date: 2023-08-29T13:54:51-07:00
New Revision: bf2f9d2b64b82d4deeb96b2ad44e53e84a4536ea
URL: https://github.com/llvm/llvm-project/commit/bf2f9d2b64b82d4deeb96b2ad44e53e84a4536ea
DIFF: https://github.com/llvm/llvm-project/commit/bf2f9d2b64b82d4deeb96b2ad44e53e84a4536ea.diff
LOG: [TableGen] Make OpcodeMappings sort comparator strict weak ordering compliant
This did not satisfy equivalence of transitivity. There was an attempt
to fix it in https://reviews.llvm.org/D58687 but it was not fully
correct. Masks might not be equivalent but be equal according to LessThan lambda
Reviewed By: aeubanks, MaskRay
Differential Revision: https://reviews.llvm.org/D157955
Added:
Modified:
llvm/utils/TableGen/CodeGenSchedule.cpp
Removed:
################################################################################
diff --git a/llvm/utils/TableGen/CodeGenSchedule.cpp b/llvm/utils/TableGen/CodeGenSchedule.cpp
index 04219a6e54d950..c753d9f9edd431 100644
--- a/llvm/utils/TableGen/CodeGenSchedule.cpp
+++ b/llvm/utils/TableGen/CodeGenSchedule.cpp
@@ -369,19 +369,20 @@ processSTIPredicate(STIPredicateFunction &Fn,
const std::pair<APInt, APInt> &LhsMasks = OpcodeMasks[LhsIdx];
const std::pair<APInt, APInt> &RhsMasks = OpcodeMasks[RhsIdx];
- auto LessThan = [](const APInt &Lhs, const APInt &Rhs) {
- unsigned LhsCountPopulation = Lhs.popcount();
- unsigned RhsCountPopulation = Rhs.popcount();
- return ((LhsCountPopulation < RhsCountPopulation) ||
- ((LhsCountPopulation == RhsCountPopulation) &&
- (Lhs.countl_zero() > Rhs.countl_zero())));
+ auto PopulationCountAndLeftBit =
+ [](const APInt &Other) -> std::pair<int, int> {
+ return std::pair<int, int>(Other.popcount(),
+ -Other.countl_zero());
};
-
- if (LhsMasks.first != RhsMasks.first)
- return LessThan(LhsMasks.first, RhsMasks.first);
-
- if (LhsMasks.second != RhsMasks.second)
- return LessThan(LhsMasks.second, RhsMasks.second);
+ auto lhsmask_first = PopulationCountAndLeftBit(LhsMasks.first);
+ auto rhsmask_first = PopulationCountAndLeftBit(RhsMasks.first);
+ if (lhsmask_first != rhsmask_first)
+ return lhsmask_first < rhsmask_first;
+
+ auto lhsmask_second = PopulationCountAndLeftBit(LhsMasks.second);
+ auto rhsmask_second = PopulationCountAndLeftBit(RhsMasks.second);
+ if (lhsmask_second != rhsmask_second)
+ return lhsmask_second < rhsmask_second;
return LhsIdx < RhsIdx;
});
More information about the llvm-commits
mailing list