[Mlir-commits] [mlir] [mlir][tosa] Canonicalize avg_pool2d/max_pool2d no-ops (PR #203571)
Sayan Saha
llvmlistbot at llvm.org
Thu Jun 18 06:04:37 PDT 2026
================
@@ -271,6 +271,41 @@ struct AvgPool2dAdaptiveToAvgPool2d
}
};
+struct AvgPool2dIsNoOp : public OpRewritePattern<tosa::AvgPool2dOp> {
+ using OpRewritePattern::OpRewritePattern;
+
+ LogicalResult matchAndRewrite(tosa::AvgPool2dOp op,
+ PatternRewriter &rewriter) const override {
+ const auto inputType = llvm::cast<ShapedType>(op.getInput().getType());
+ if (!llvm::isa<FloatType>(inputType.getElementType()))
+ return rewriter.notifyMatchFailure(op,
+ "expected floating-point input type");
+
+ if (!matchPattern(op.getInputZp(), m_Constant()) ||
----------------
sahas3 wrote:
I think comment that the op-verifier verifies constant ZP is zero for avgpool with float inputs will be helpful for readability as we don't check for the constant to be zero here.
https://github.com/llvm/llvm-project/pull/203571
More information about the Mlir-commits
mailing list