Skip to content

Commit 58c1885

Browse files
committed
[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
1 parent 915a8bb commit 58c1885

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -977,12 +977,9 @@ struct FoldInitTensorWithDimOp : public OpRewritePattern<tensor::DimOp> {
977977
auto initTensorOp = dimOp.source().getDefiningOp<linalg::InitTensorOp>();
978978
if (!initTensorOp || !maybeConstantIndex)
979979
return failure();
980-
if (initTensorOp.isDynamicSize(*maybeConstantIndex)) {
981-
rewriter.replaceOp(dimOp,
982-
initTensorOp.getDynamicSize(*maybeConstantIndex));
983-
return success();
984-
}
985-
rewriter.replaceOpWithNewOp<ConstantIndexOp>(dimOp, *maybeConstantIndex);
980+
if (!initTensorOp.isDynamicSize(*maybeConstantIndex))
981+
return failure();
982+
rewriter.replaceOp(dimOp, initTensorOp.getDynamicSize(*maybeConstantIndex));
986983
return success();
987984
}
988985
};

0 commit comments

Comments
 (0)