[Mlir-commits] [mlir] [tosa]: canonicalize dynamic size of tosa.slice to static output shape (PR #135429)
Sayan Saha
llvmlistbot at llvm.org
Sat Apr 12 13:42:15 PDT 2025
================
@@ -731,9 +731,64 @@ struct ConcatSliceOptimization : public OpRewritePattern<tosa::SliceOp> {
}
};
+// Update size operand of tosa.slice if size has dynamic dims but corresponding
+// output dim is static
+struct SliceDynamicSizeCanonicalization
+ : public OpRewritePattern<tosa::SliceOp> {
+ using OpRewritePattern<tosa::SliceOp>::OpRewritePattern;
+
+ LogicalResult matchAndRewrite(tosa::SliceOp sliceOp,
+ PatternRewriter &rewriter) const override {
+ ShapedType resultType = cast<ShapedType>(sliceOp.getType());
+
+ ElementsAttr sizeElems;
+ if (!matchPattern(sliceOp.getSize(), m_Constant(&sizeElems))) {
+ return rewriter.notifyMatchFailure(
+ sliceOp, "size of slice must be a static ranked shape");
+ }
+
+ llvm::SmallVector<int64_t> sliceSizes =
+ llvm::to_vector(sizeElems.getValues<int64_t>());
+
+ bool replaceSliceSize{false};
+ // if size op has -1 indicating dynamic shape but corresponding dim on the
+ // output is statically known, update size to match with known output dim
+ // shape
+ for (const auto i : llvm::enumerate(sliceSizes)) {
----------------
sahas3 wrote:
Done.
https://github.com/llvm/llvm-project/pull/135429
More information about the Mlir-commits
mailing list