[Mlir-commits] [mlir] ee3c6de - [mlir] use stable_sort for OperationLegalizer::computeOpLegalizationDepth
Xiang Li
llvmlistbot at llvm.org
Fri Jan 20 08:33:03 PST 2023
Author: Xiang Li
Date: 2023-01-20T11:32:42-05:00
New Revision: ee3c6de722e77a7966764133b1b8a5cd1a1f562f
URL: https://github.com/llvm/llvm-project/commit/ee3c6de722e77a7966764133b1b8a5cd1a1f562f
DIFF: https://github.com/llvm/llvm-project/commit/ee3c6de722e77a7966764133b1b8a5cd1a1f562f.diff
LOG: [mlir] use stable_sort for OperationLegalizer::computeOpLegalizationDepth
For https://github.com/llvm/llvm-project/issues/60070.
llvm::array_pod_sort will cause non-determinism when select pattern.
It is exposed by difference between windows build and linux build.
Differential Revision: https://reviews.llvm.org/D142110
Added:
Modified:
mlir/lib/Transforms/Utils/DialectConversion.cpp
Removed:
################################################################################
diff --git a/mlir/lib/Transforms/Utils/DialectConversion.cpp b/mlir/lib/Transforms/Utils/DialectConversion.cpp
index 0213c63d7b0b1..abdf0a9533b56 100644
--- a/mlir/lib/Transforms/Utils/DialectConversion.cpp
+++ b/mlir/lib/Transforms/Utils/DialectConversion.cpp
@@ -2300,21 +2300,19 @@ unsigned OperationLegalizer::applyCostModelToPatterns(
return minDepth;
// Sort the patterns by those likely to be the most beneficial.
- llvm::array_pod_sort(patternsByDepth.begin(), patternsByDepth.end(),
- [](const std::pair<const Pattern *, unsigned> *lhs,
- const std::pair<const Pattern *, unsigned> *rhs) {
- // First sort by the smaller pattern legalization
- // depth.
- if (lhs->second != rhs->second)
- return llvm::array_pod_sort_comparator<unsigned>(
- &lhs->second, &rhs->second);
-
- // Then sort by the larger pattern benefit.
- auto lhsBenefit = lhs->first->getBenefit();
- auto rhsBenefit = rhs->first->getBenefit();
- return llvm::array_pod_sort_comparator<PatternBenefit>(
- &rhsBenefit, &lhsBenefit);
- });
+ std::stable_sort(patternsByDepth.begin(), patternsByDepth.end(),
+ [](const std::pair<const Pattern *, unsigned> &lhs,
+ const std::pair<const Pattern *, unsigned> &rhs) {
+ // First sort by the smaller pattern legalization
+ // depth.
+ if (lhs.second != rhs.second)
+ return lhs.second < rhs.second;
+
+ // Then sort by the larger pattern benefit.
+ auto lhsBenefit = lhs.first->getBenefit();
+ auto rhsBenefit = rhs.first->getBenefit();
+ return lhsBenefit > rhsBenefit;
+ });
// Update the legalization pattern to use the new sorted list.
patterns.clear();
More information about the Mlir-commits
mailing list