diff --git a/llvm/utils/TableGen/CodeGenSchedule.cpp b/llvm/utils/TableGen/CodeGenSchedule.cpp --- a/llvm/utils/TableGen/CodeGenSchedule.cpp +++ b/llvm/utils/TableGen/CodeGenSchedule.cpp @@ -369,19 +369,20 @@ const std::pair &LhsMasks = OpcodeMasks[LhsIdx]; const std::pair &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 { + return std::pair(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; });