[PATCH] D157955: [TableGen] Make OpcodeMappings sort comparator strict weak ordering compliant
Danila Kutenin via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 15 02:19:08 PDT 2023
danlark created this revision.
danlark added reviewers: andrewng, andreadb, Paul-C-Anagnostopoulos.
Herald added a project: All.
danlark requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
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
I don't have commit rights. Danila Kutenin kutdanila at yandex.ru
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D157955
Files:
llvm/utils/TableGen/CodeGenSchedule.cpp
Index: llvm/utils/TableGen/CodeGenSchedule.cpp
===================================================================
--- llvm/utils/TableGen/CodeGenSchedule.cpp
+++ llvm/utils/TableGen/CodeGenSchedule.cpp
@@ -369,19 +369,20 @@
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;
});
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D157955.550217.patch
Type: text/x-patch
Size: 1923 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230815/c5ea150f/attachment.bin>
More information about the llvm-commits
mailing list