[Mlir-commits] [mlir] [mlir][tosa] Stop folding pad into avg_pool2d (PR #164599)
Vitalii Shutov
llvmlistbot at llvm.org
Wed Oct 22 03:52:54 PDT 2025
https://github.com/Lallapallooza created https://github.com/llvm/llvm-project/pull/164599
Keep explicit padding ahead of tosa.avg_pool2d to preserve semantics. Folding a pad into the op drops padded values from the average divisor.
>From a18ab3fa2b012408d7d1df4339a5399bffeec078 Mon Sep 17 00:00:00 2001
From: Vitalii Shutov <vitalii.shutov at arm.com>
Date: Tue, 21 Oct 2025 07:49:21 +0100
Subject: [PATCH] [mlir][tosa] Stop folding pad into avg_pool2d
Keep explicit padding ahead of tosa.avg_pool2d to preserve semantics.
Folding a pad into the op drops padded values from the average divisor.
Change-Id: I229bbdc0a8ef5d4ff4c6942788614c55593ce30f
---
mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp | 5 ++---
mlir/test/Dialect/Tosa/canonicalize.mlir | 8 ++++----
2 files changed, 6 insertions(+), 7 deletions(-)
diff --git a/mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp b/mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp
index caf80165fc640..fef37d1de3a34 100644
--- a/mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp
+++ b/mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp
@@ -247,9 +247,8 @@ struct FoldPadToTensorOp : public OpRewritePattern<OpTy> {
void AvgPool2dOp::getCanonicalizationPatterns(RewritePatternSet &results,
MLIRContext *context) {
- results.add<FoldPadToTensorOp<tosa::AvgPool2dOp,
- PoolPadFoldAdaptor<tosa::AvgPool2dOp>>>(
- context);
+ (void)results;
+ (void)context;
}
void Conv2DOp::getCanonicalizationPatterns(RewritePatternSet &results,
diff --git a/mlir/test/Dialect/Tosa/canonicalize.mlir b/mlir/test/Dialect/Tosa/canonicalize.mlir
index e8525a5d2ed62..45d942bb92d6c 100644
--- a/mlir/test/Dialect/Tosa/canonicalize.mlir
+++ b/mlir/test/Dialect/Tosa/canonicalize.mlir
@@ -9,11 +9,11 @@ func.func @argmax_nofold(%arg0: tensor<?x1xf32>) -> tensor<1xi32> {
// -----
-// CHECK-LABEL: @pad_wh_avg_pool2d_fold
-func.func @pad_wh_avg_pool2d_fold(%input: tensor<1x10x8x3xf32>) -> tensor<1x6x5x3xf32> {
- // CHECK-NOT: tosa.pad
+// CHECK-LABEL: @pad_wh_avg_pool2d_nofold
+func.func @pad_wh_avg_pool2d_nofold(%input: tensor<1x10x8x3xf32>) -> tensor<1x6x5x3xf32> {
+ // CHECK: tosa.pad
// CHECK: tosa.avg_pool2d
- // CHECK-SAME: pad = array<i64: 1, 1, 1, 1>
+ // CHECK-SAME: pad = array<i64: 0, 1, 0, 1>
%pad_shape = tosa.const_shape { values = dense<[0, 0, 1, 0, 1, 0, 0, 0]> : tensor<8xindex>} : () -> !tosa.shape<8>
%pad_const = "tosa.const"() <{values = dense<0.0> : tensor<1xf32>}> : ()-> tensor<1xf32>
%input_zp = "tosa.const"() <{values = dense<0.0> : tensor<1xf32>}> : ()-> tensor<1xf32>
More information about the Mlir-commits
mailing list