Skip to content

Commit bf2f9d2

Browse files
danlark1MaskRay
authored andcommitted
[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
1 parent c9da9c0 commit bf2f9d2

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

llvm/utils/TableGen/CodeGenSchedule.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -369,19 +369,20 @@ processSTIPredicate(STIPredicateFunction &Fn,
369369
const std::pair<APInt, APInt> &LhsMasks = OpcodeMasks[LhsIdx];
370370
const std::pair<APInt, APInt> &RhsMasks = OpcodeMasks[RhsIdx];
371371

372-
auto LessThan = [](const APInt &Lhs, const APInt &Rhs) {
373-
unsigned LhsCountPopulation = Lhs.popcount();
374-
unsigned RhsCountPopulation = Rhs.popcount();
375-
return ((LhsCountPopulation < RhsCountPopulation) ||
376-
((LhsCountPopulation == RhsCountPopulation) &&
377-
(Lhs.countl_zero() > Rhs.countl_zero())));
372+
auto PopulationCountAndLeftBit =
373+
[](const APInt &Other) -> std::pair<int, int> {
374+
return std::pair<int, int>(Other.popcount(),
375+
-Other.countl_zero());
378376
};
379-
380-
if (LhsMasks.first != RhsMasks.first)
381-
return LessThan(LhsMasks.first, RhsMasks.first);
382-
383-
if (LhsMasks.second != RhsMasks.second)
384-
return LessThan(LhsMasks.second, RhsMasks.second);
377+
auto lhsmask_first = PopulationCountAndLeftBit(LhsMasks.first);
378+
auto rhsmask_first = PopulationCountAndLeftBit(RhsMasks.first);
379+
if (lhsmask_first != rhsmask_first)
380+
return lhsmask_first < rhsmask_first;
381+
382+
auto lhsmask_second = PopulationCountAndLeftBit(LhsMasks.second);
383+
auto rhsmask_second = PopulationCountAndLeftBit(RhsMasks.second);
384+
if (lhsmask_second != rhsmask_second)
385+
return lhsmask_second < rhsmask_second;
385386

386387
return LhsIdx < RhsIdx;
387388
});

0 commit comments

Comments
 (0)