[Mlir-commits] [mlir] 4cec5ea - [mlir][tosa] Set explicit benefit for tosa.reshape to linalg
Rob Suderman
llvmlistbot at llvm.org
Wed Jan 18 08:52:14 PST 2023
Author: Rob Suderman
Date: 2023-01-18T08:38:02-08:00
New Revision: 4cec5eadfd1f5ed7f7037e0c7e6b5fcd59045125
URL: https://github.com/llvm/llvm-project/commit/4cec5eadfd1f5ed7f7037e0c7e6b5fcd59045125
DIFF: https://github.com/llvm/llvm-project/commit/4cec5eadfd1f5ed7f7037e0c7e6b5fcd59045125.diff
LOG: [mlir][tosa] Set explicit benefit for tosa.reshape to linalg
The patterns used to lower tosa.reshape to linalg are order
dependent which varies depending on platform. Setting the
benefit appropriately guarantees compilation executes the
rewriters in the correct ordering.
Reviewed By: benvanik
Differential Revision: https://reviews.llvm.org/D141981
Added:
Modified:
mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp
Removed:
################################################################################
diff --git a/mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp b/mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp
index bb4072e70209b..aa41c962826da 100644
--- a/mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp
+++ b/mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp
@@ -963,11 +963,6 @@ class ReshapeConverterCollapse : public OpConversionPattern<tosa::ReshapeOp> {
reshape, "Cannot collapse dynamic dims to more than one dimension");
}
- if (operandTy == resultTy) {
- rewriter.replaceOp(reshape, adaptor.getOperands()[0]);
- return success();
- }
-
SmallVector<ReassociationExprs, 4> reassociationMap;
if (!createReassociationMapsForCollapse(rewriter, operandTy.getShape(),
resultTy.getShape(),
@@ -1001,11 +996,6 @@ class ReshapeConverterExpand : public OpConversionPattern<tosa::ReshapeOp> {
ShapedType resultTy = reshape.getType().template cast<ShapedType>();
bool isDynamic = !operandTy.hasStaticShape();
- if (operandTy == resultTy) {
- rewriter.replaceOp(reshape, adaptor.getOperands()[0]);
- return success();
- }
-
if (isDynamic && operandTy.getRank() != 1) {
return rewriter.notifyMatchFailure(
reshape, "Cannot expand dynamic dims from more than one dimension");
@@ -1045,11 +1035,6 @@ class ReshapeConverterCollapseExpand
ShapedType resultTy = reshape.getType().template cast<ShapedType>();
bool isDynamic = !operandTy.hasStaticShape();
- if (operandTy == resultTy) {
- rewriter.replaceOp(reshape, adaptor.getOperands()[0]);
- return success();
- }
-
SmallVector<int64_t> intermediateShape;
if (!findIntermediateShape(resultTy.getShape(), operandTy.getShape(),
intermediateShape, isDynamic)) {
@@ -2310,6 +2295,13 @@ void mlir::tosa::populateTosaToLinalgConversionPatterns(
patterns->add<MaterializeResizeBroadcast>(patterns->getContext(),
/*benefit=*/300);
+ patterns->add<ReshapeConverterCollapse>(patterns->getContext(),
+ /*benefit=*/100);
+ patterns->add<ReshapeConverterExpand>(patterns->getContext(),
+ /*benefit=*/200);
+ patterns->add<ReshapeConverterCollapseExpand>(patterns->getContext(),
+ /*benefit=*/300);
+
patterns->add<
// clang-format off
PointwiseConverter<tosa::AddOp>,
@@ -2357,9 +2349,6 @@ void mlir::tosa::populateTosaToLinalgConversionPatterns(
ArgMaxConverter,
ConcatConverter,
GatherConverter,
- ReshapeConverterCollapse,
- ReshapeConverterExpand,
- ReshapeConverterCollapseExpand,
RescaleConverter,
ReverseConverter,
TableConverter,
More information about the Mlir-commits
mailing list