diff --git a/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp b/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp index 58af9995548e93..86e5215d72ac5f 100644 --- a/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp +++ b/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp @@ -716,11 +716,16 @@ struct FoldInsertPadIntoFill : public OpRewritePattern { rewriter, loc, addMap, {std::get<0>(p), std::get<1>(p)})); } + RankedTensorType srcPadType = srcPadOp.getSourceType(); SmallVector newSizes; - for (int i = 0, e = srcPadOp.getSourceType().getRank(); i < e; ++i) { - newSizes.push_back( - rewriter.create(loc, srcPadOp.getSource(), i) - .getResult()); + for (int i = 0, e = srcPadType.getRank(); i < e; ++i) { + if (srcPadType.isDynamicDim(i)) { + newSizes.push_back( + rewriter.create(loc, srcPadOp.getSource(), i) + .getResult()); + } else { + newSizes.push_back(rewriter.getIndexAttr(srcPadType.getDimSize(i))); + } } rewriter.replaceOpWithNewOp(