[Mlir-commits] [mlir] [mlir][tensor] Fold pack and unpack of empty input tensor (PR #92247)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Mon May 20 13:38:50 PDT 2024
================
@@ -93,12 +93,76 @@ struct FoldEmptyTensorWithExtractSliceOp
bool foldSingleUseOnly = false;
};
+/// tensor.empty does not define any tensor contents, so an unpadded pack
+/// can be folded away.
+struct FoldEmptyTensorWithPackOp : public OpRewritePattern<PackOp> {
+ FoldEmptyTensorWithPackOp(MLIRContext *ctx, PatternBenefit benefit = 1,
+ bool foldSingleUseOnly = false)
+ : OpRewritePattern<PackOp>(ctx, benefit),
+ foldSingleUseOnly(foldSingleUseOnly) {}
+
+ LogicalResult matchAndRewrite(PackOp packOp,
+ PatternRewriter &rewriter) const override {
+ // Check for tensor.empty source.
+ auto emptyOp = packOp.getSource().getDefiningOp<EmptyOp>();
+ if (!emptyOp)
+ return failure();
+
+ // Check for single use.
+ if (foldSingleUseOnly && !llvm::hasSingleElement(emptyOp->getUses()))
----------------
MaheshRavishankar wrote:
I dont think you need this. You can drop it I think. I dont know why the other patterns do that, probably being too conservative,
https://github.com/llvm/llvm-project/pull/92247
More information about the Mlir-commits
mailing list