[Mlir-commits] [mlir] [mlir][tosa] Canonicalize avg_pool2d/max_pool2d no-ops (PR #203571)
Luke Hutton
llvmlistbot at llvm.org
Thu Jun 18 06:27:42 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()) ||
+ !matchPattern(op.getOutputZp(), m_Constant()))
+ return rewriter.notifyMatchFailure(
+ op,
+ "expected input and output zero points to be statically verifiable");
+
+ if (!llvm::all_of(op.getKernel(), [](int64_t val) { return val == 1; }))
+ return rewriter.notifyMatchFailure(op, "expected unit kernel");
+
+ if (!llvm::all_of(op.getStride(), [](int64_t val) { return val == 1; }))
+ return rewriter.notifyMatchFailure(op, "expected unit stride");
+
+ if (!llvm::all_of(op.getPad(), [](int64_t val) { return val == 0; }))
+ return rewriter.notifyMatchFailure(op, "expected zero padding");
+
+ rewriter.replaceOp(op, op.getInput());
----------------
lhutton1 wrote:
Argh, thanks! Yes, I'm fairly sure I realised this at the time of writing, but forgot when taking a look just now. I've added it back and added a comment as a reminder
https://github.com/llvm/llvm-project/pull/203571
More information about the Mlir-commits
mailing list