From 58c188507f724feee181018bfb6a330be2c6ac9a Mon Sep 17 00:00:00 2001 From: Alexander Belyaev Date: Fri, 3 Sep 2021 19:06:15 +0200 Subject: [PATCH] [mlir][linalg] Fix `FoldInitTensorWithDimOp` if dim(init_tensor) is static. It looks like it was a typo. Instead of `*maybeConstantIndex`, `initTensorOp.getStaticSize(*maybeConstantIndex)` should be used to access the dim size of the tensor. There is a test for that in `canonicalize.mlir`, but it was working correctly because `ReplaceStaticShapeDims` was canonicalizing DimOp before `FoldInitTensorWithDimOp`. So, to make the patterns more "orthogonal", this case is disabled. Differential Revision: https://reviews.llvm.org/D109247 --- mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp b/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp index abb3c4415838..e2b9436f4a10 100644 --- a/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp +++ b/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp @@ -977,12 +977,9 @@ struct FoldInitTensorWithDimOp : public OpRewritePattern { auto initTensorOp = dimOp.source().getDefiningOp(); if (!initTensorOp || !maybeConstantIndex) return failure(); - if (initTensorOp.isDynamicSize(*maybeConstantIndex)) { - rewriter.replaceOp(dimOp, - initTensorOp.getDynamicSize(*maybeConstantIndex)); - return success(); - } - rewriter.replaceOpWithNewOp(dimOp, *maybeConstantIndex); + if (!initTensorOp.isDynamicSize(*maybeConstantIndex)) + return failure(); + rewriter.replaceOp(dimOp, initTensorOp.getDynamicSize(*maybeConstantIndex)); return success(); } };