[Mlir-commits] [mlir] [mlir][tosa] Add min/max_shape ops (PR #175146)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Fri Jan 9 07:56:28 PST 2026
https://github.com/Philip742 updated https://github.com/llvm/llvm-project/pull/175146
>From 09301cb6fe876f9c2a267b4bddd2c7966a4a4af1 Mon Sep 17 00:00:00 2001
From: Philip Wilkinson <philip.wilkinson at arm.com>
Date: Wed, 10 Dec 2025 10:54:00 +0000
Subject: [PATCH] [mlir][tosa] Add min/max_shape ops
Signed-off-by: Philip Wilkinson <philip.wilkinson at arm.com>
Change-Id: Ifa230a41e186c8e594c4750eee96d537ceb638b9
---
.../mlir/Dialect/Tosa/IR/TosaShapeOps.td | 36 +++++++++++++++++++
.../Tosa/Transforms/TosaProfileCompliance.cpp | 2 ++
.../Tosa/Transforms/TosaValidation.cpp | 4 ++-
mlir/test/Dialect/Tosa/invalid_extension.mlir | 20 +++++++++++
mlir/test/Dialect/Tosa/ops.mlir | 18 ++++++++++
5 files changed, 79 insertions(+), 1 deletion(-)
diff --git a/mlir/include/mlir/Dialect/Tosa/IR/TosaShapeOps.td b/mlir/include/mlir/Dialect/Tosa/IR/TosaShapeOps.td
index f4ac59ebdbdba..be5789c1be7bf 100644
--- a/mlir/include/mlir/Dialect/Tosa/IR/TosaShapeOps.td
+++ b/mlir/include/mlir/Dialect/Tosa/IR/TosaShapeOps.td
@@ -175,6 +175,42 @@ def Tosa_DivFloorShapeOp : Tosa_ElementwiseShapeOp<"div_floor_shape", [Pure]> {
let results = (outs Tosa_Shape:$output);
}
+//===----------------------------------------------------------------------===//
+// Operator: MaxShape
+//===----------------------------------------------------------------------===//
+def Tosa_MaxShapeOp : Tosa_ElementwiseShapeOp<"max_shape", [Pure]> {
+ let summary = "Elementwise maximum of shapes.";
+
+ let description = [{
+ Elementwise maximum of input1 and input2.
+ }];
+
+ let arguments = (ins
+ Tosa_Shape:$input1,
+ Tosa_Shape:$input2
+ );
+
+ let results = (outs Tosa_Shape:$output);
+}
+
+//===----------------------------------------------------------------------===//
+// Operator: MinShape
+//===----------------------------------------------------------------------===//
+def Tosa_MinShapeOp : Tosa_ElementwiseShapeOp<"min_shape", [Pure]> {
+ let summary = "Elementwise minimum of shapes.";
+
+ let description = [{
+ Elementwise minimum of input1 and input2.
+ }];
+
+ let arguments = (ins
+ Tosa_Shape:$input1,
+ Tosa_Shape:$input2
+ );
+
+ let results = (outs Tosa_Shape:$output);
+}
+
//===----------------------------------------------------------------------===//
// Operator: ModShape
//===----------------------------------------------------------------------===//
diff --git a/mlir/lib/Dialect/Tosa/Transforms/TosaProfileCompliance.cpp b/mlir/lib/Dialect/Tosa/Transforms/TosaProfileCompliance.cpp
index 0b7925549771f..46c8c32324313 100644
--- a/mlir/lib/Dialect/Tosa/Transforms/TosaProfileCompliance.cpp
+++ b/mlir/lib/Dialect/Tosa/Transforms/TosaProfileCompliance.cpp
@@ -329,6 +329,8 @@ LogicalResult ProfileInfoDepot::populatationDispatch(Operation *op) {
POPULATE_PROFILE_INFO_SKIP(ConstShape)
POPULATE_PROFILE_INFO_SKIP(DivCeilShape)
POPULATE_PROFILE_INFO_SKIP(DivFloorShape)
+ POPULATE_PROFILE_INFO_SKIP(MaxShape)
+ POPULATE_PROFILE_INFO_SKIP(MinShape)
POPULATE_PROFILE_INFO_SKIP(ModShape)
POPULATE_PROFILE_INFO_SKIP(MulShape)
POPULATE_PROFILE_INFO_SKIP(SliceShape)
diff --git a/mlir/lib/Dialect/Tosa/Transforms/TosaValidation.cpp b/mlir/lib/Dialect/Tosa/Transforms/TosaValidation.cpp
index 99eb83ad6d12c..dc2c90bbf1199 100644
--- a/mlir/lib/Dialect/Tosa/Transforms/TosaValidation.cpp
+++ b/mlir/lib/Dialect/Tosa/Transforms/TosaValidation.cpp
@@ -6,7 +6,7 @@
//
//===----------------------------------------------------------------------===//
//
-// Validate if TOSA dialect input matchs with the specification for given
+// Validate if TOSA dialect input matches with the specification for given
// requirements.
//
//===----------------------------------------------------------------------===//
@@ -708,6 +708,8 @@ LogicalResult TosaValidation::levelCheckRanksAndSizes(Operation *op) {
CHECK_RANKS(ConcatShape);
CHECK_RANKS(DivCeilShape);
CHECK_RANKS(DivFloorShape);
+ CHECK_RANKS(MaxShape);
+ CHECK_RANKS(MinShape);
CHECK_RANKS(ModShape);
CHECK_RANKS(MulShape);
CHECK_RANKS(SliceShape);
diff --git a/mlir/test/Dialect/Tosa/invalid_extension.mlir b/mlir/test/Dialect/Tosa/invalid_extension.mlir
index 0daa0c52941e0..9162f6167f7ec 100644
--- a/mlir/test/Dialect/Tosa/invalid_extension.mlir
+++ b/mlir/test/Dialect/Tosa/invalid_extension.mlir
@@ -587,3 +587,23 @@ func.func @test_mul_shape() -> !tosa.shape<4> {
%c = tosa.mul_shape %a, %b : (!tosa.shape<4>, !tosa.shape<4>) -> !tosa.shape<4>
return %c : !tosa.shape<4>
}
+
+// -----
+
+func.func @test_max_shape() -> !tosa.shape<4> {
+ %a = tosa.const_shape {values = dense<[1, 2, 3, 4]> : tensor<4xindex>} : () -> !tosa.shape<4>
+ %b = tosa.const_shape {values = dense<[5, 6, 7, 8]> : tensor<4xindex>} : () -> !tosa.shape<4>
+ // expected-error at +1 {{'tosa.max_shape' op illegal: requires [shape] but not enabled in target}}
+ %c = tosa.max_shape %a, %b : (!tosa.shape<4>, !tosa.shape<4>) -> !tosa.shape<4>
+ return %c : !tosa.shape<4>
+}
+
+// -----
+
+func.func @test_min_shape() -> !tosa.shape<4> {
+ %a = tosa.const_shape {values = dense<[1, 2, 3, 4]> : tensor<4xindex>} : () -> !tosa.shape<4>
+ %b = tosa.const_shape {values = dense<[5, 6, 7, 8]> : tensor<4xindex>} : () -> !tosa.shape<4>
+ // expected-error at +1 {{'tosa.min_shape' op illegal: requires [shape] but not enabled in target}}
+ %c = tosa.min_shape %a, %b : (!tosa.shape<4>, !tosa.shape<4>) -> !tosa.shape<4>
+ return %c : !tosa.shape<4>
+}
diff --git a/mlir/test/Dialect/Tosa/ops.mlir b/mlir/test/Dialect/Tosa/ops.mlir
index 9da17cf4f9552..8d7d703e2f450 100644
--- a/mlir/test/Dialect/Tosa/ops.mlir
+++ b/mlir/test/Dialect/Tosa/ops.mlir
@@ -1480,3 +1480,21 @@ func.func @test_slice_shape_dynamic(%arg0: tensor<1xi32>, %arg1: tensor<1xi32>)
%3 = tosa.slice_shape %0, %arg0, %arg1 : (!tosa.shape<6>, tensor<1xi32>, tensor<1xi32>) -> !tosa.shape<3>
return %3 : !tosa.shape<3>
}
+
+// -----
+// CHECK-LABEL: test_max_shape
+func.func @test_max_shape() -> !tosa.shape<4> {
+ %a = tosa.const_shape {values = dense<[5, 7, 10, 1]> : tensor<4xindex>} : () -> !tosa.shape<4>
+ %b = tosa.const_shape {values = dense<[2, 3, 4, 3]> : tensor<4xindex>} : () -> !tosa.shape<4>
+ %c = tosa.max_shape %a, %b : (!tosa.shape<4>, !tosa.shape<4>) -> !tosa.shape<4>
+ return %c : !tosa.shape<4>
+}
+
+// -----
+// CHECK-LABEL: test_min_shape
+func.func @test_min_shape() -> !tosa.shape<4> {
+ %a = tosa.const_shape {values = dense<[5, 7, 10, 1]> : tensor<4xindex>} : () -> !tosa.shape<4>
+ %b = tosa.const_shape {values = dense<[2, 3, 4, 3]> : tensor<4xindex>} : () -> !tosa.shape<4>
+ %c = tosa.min_shape %a, %b : (!tosa.shape<4>, !tosa.shape<4>) -> !tosa.shape<4>
+ return %c : !tosa.shape<4>
+}
More information about the Mlir-commits
mailing list