[PATCH] D157955: [TableGen] Make OpcodeMappings sort comparator strict weak ordering compliant

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 29 13:55:11 PDT 2023


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGbf2f9d2b64b8: [TableGen] Make OpcodeMappings sort comparator strict weak ordering compliant (authored by danlark, committed by MaskRay).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157955/new/

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.554488.patch
Type: text/x-patch
Size: 1923 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230829/c5bb7f6b/attachment.bin>


More information about the llvm-commits mailing list