[Mlir-commits] [mlir] [mlir][tosa] Fix pad op verifier when padding is dynamic (PR #177622)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Fri Jan 23 09:33:59 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir
Author: Luke Hutton (lhutton1)
<details>
<summary>Changes</summary>
When padding is dynamic the verifier should not return failure, it shouldn't try to check the pad values.
---
Full diff: https://github.com/llvm/llvm-project/pull/177622.diff
2 Files Affected:
- (modified) mlir/lib/Dialect/Tosa/IR/TosaOps.cpp (+2-3)
- (modified) mlir/test/Dialect/Tosa/ops.mlir (+11-1)
``````````diff
diff --git a/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp b/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp
index 033feb79405df..bf82745e2bc5e 100644
--- a/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp
+++ b/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp
@@ -2147,9 +2147,8 @@ LogicalResult tosa::PadOp::verify() {
auto inputRank = inputType.getRank();
DenseIntElementsAttr paddingAttr;
- if (!matchPattern(getPadding(), m_Constant(&paddingAttr))) {
- return failure();
- }
+ if (!matchPattern(getPadding(), m_Constant(&paddingAttr)))
+ return success();
auto paddingValues = paddingAttr.getValues<APInt>();
if (paddingValues.size() != static_cast<size_t>(inputRank * 2))
diff --git a/mlir/test/Dialect/Tosa/ops.mlir b/mlir/test/Dialect/Tosa/ops.mlir
index 8b4b972d2633d..44cfd5cfc9400 100644
--- a/mlir/test/Dialect/Tosa/ops.mlir
+++ b/mlir/test/Dialect/Tosa/ops.mlir
@@ -686,6 +686,16 @@ func.func @test_pad_explicit_value(%arg0: tensor<13x21x3xf32>) -> tensor<13x21x3
return %1 : tensor<13x21x3xf32>
}
+// -----
+// CHECK-LABEL: test_pad_dynamic_padding
+func.func @test_pad_dynamic_padding(%arg0: tensor<1x?x?x576xf32>) -> tensor<1x?x?x576xf32> {
+ %0 = tosa.const_shape {values = dense<0> : tensor<1xindex>} : () -> !tosa.shape<1>
+ %1 = tosa.concat_shape %0, %0, %0, %0, %0, %0, %0, %0 : (!tosa.shape<1>, !tosa.shape<1>, !tosa.shape<1>, !tosa.shape<1>, !tosa.shape<1>, !tosa.shape<1>, !tosa.shape<1>, !tosa.shape<1>) -> !tosa.shape<8>
+ %2 = "tosa.const"() <{values = dense<0.000000e+00> : tensor<1xf32>}> : () -> tensor<1xf32>
+ %3 = tosa.pad %arg0, %1, %2 : (tensor<1x?x?x576xf32>, !tosa.shape<8>, tensor<1xf32>) -> tensor<1x?x?x576xf32>
+ return %3 : tensor<1x?x?x576xf32>
+}
+
// -----
// CHECK-LABEL: reshape
func.func @test_reshape(%arg0: tensor<13x21x3xf32>) -> tensor<1x819xf32> {
@@ -1586,4 +1596,4 @@ func.func @test_assert_equal_shape() {
%1 = tosa.const_shape {values = dense<[5, 2]> : tensor<2xindex>} : () -> !tosa.shape<2>
tosa.assert_equal_shape %0, %1 {allow_broadcast = true} : (!tosa.shape<2>, !tosa.shape<2>) -> ()
return
-}
\ No newline at end of file
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/177622
More information about the Mlir-commits
mailing list