[Mlir-commits] [mlir] e9253f0 - [mlir][tosa] Prevent creation of `tosa.concat_shape` for scalar shape values (#176120)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Wed Feb 4 07:24:41 PST 2026
Author: Luke Hutton
Date: 2026-02-04T15:24:36Z
New Revision: e9253f0e355f8818fd06124ec393fc4841bbb560
URL: https://github.com/llvm/llvm-project/commit/e9253f0e355f8818fd06124ec393fc4841bbb560
DIFF: https://github.com/llvm/llvm-project/commit/e9253f0e355f8818fd06124ec393fc4841bbb560.diff
LOG: [mlir][tosa] Prevent creation of `tosa.concat_shape` for scalar shape values (#176120)
Updates `tosa.concat_shape` inline with the following specification
change: https://github.com/arm/tosa-specification/pull/30.
Added:
Modified:
mlir/lib/Dialect/Tosa/IR/TosaOps.cpp
mlir/test/Dialect/Tosa/level_check.mlir
mlir/test/Dialect/Tosa/ops.mlir
mlir/test/Dialect/Tosa/verifier.mlir
Removed:
################################################################################
diff --git a/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp b/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp
index fe107699cc3d3..798fc360d8439 100644
--- a/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp
+++ b/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp
@@ -4923,6 +4923,15 @@ LogicalResult tosa::ConcatShapeOp::verify() {
cast<tosa::shapeType>(getResult().getType());
const int64_t outputRank = outShapeType.getRank();
const Operation::operand_range inputList = getInput();
+
+ if (inputList.size() == 0)
+ return emitOpError("requires at least one input shape");
+
+ if (llvm::any_of(inputList, [](Value v) {
+ return cast<tosa::shapeType>(v.getType()).getRank() == 0;
+ }))
+ return emitOpError("requires all inputs shapes have a rank greater than 0");
+
const int64_t inputsRank =
llvm::accumulate(inputList, 0, [](int64_t acc, const Value &input) {
const tosa::shapeType inShapeType =
diff --git a/mlir/test/Dialect/Tosa/level_check.mlir b/mlir/test/Dialect/Tosa/level_check.mlir
index 216f05a484927..739af6bcac2d8 100644
--- a/mlir/test/Dialect/Tosa/level_check.mlir
+++ b/mlir/test/Dialect/Tosa/level_check.mlir
@@ -1693,34 +1693,6 @@ func.func @test_dim(%arg0: tensor<1x2x3x4x5x6x7x8xi32>) -> !tosa.shape<1> {
// -----
-func.func @test_concat_shape_invalid_list_size() {
- %0 = tosa.const_shape {values = dense<[]> : tensor<0xindex>} : () -> !tosa.shape<0>
- // expected-error at +1 {{'tosa.concat_shape' op failed level check: length(tensor_list_shape(input)) <= MAX_TENSOR_LIST_SIZE (64), got 65}}
- %1 = tosa.concat_shape %0, %0, %0, %0, %0, %0, %0, %0,
- %0, %0, %0, %0, %0, %0, %0, %0,
- %0, %0, %0, %0, %0, %0, %0, %0,
- %0, %0, %0, %0, %0, %0, %0, %0,
- %0, %0, %0, %0, %0, %0, %0, %0,
- %0, %0, %0, %0, %0, %0, %0, %0,
- %0, %0, %0, %0, %0, %0, %0, %0,
- %0, %0, %0, %0, %0, %0, %0, %0,
- %0 :
- (
- !tosa.shape<0>, !tosa.shape<0>, !tosa.shape<0>, !tosa.shape<0>, !tosa.shape<0>, !tosa.shape<0>, !tosa.shape<0>, !tosa.shape<0>,
- !tosa.shape<0>, !tosa.shape<0>, !tosa.shape<0>, !tosa.shape<0>, !tosa.shape<0>, !tosa.shape<0>, !tosa.shape<0>, !tosa.shape<0>,
- !tosa.shape<0>, !tosa.shape<0>, !tosa.shape<0>, !tosa.shape<0>, !tosa.shape<0>, !tosa.shape<0>, !tosa.shape<0>, !tosa.shape<0>,
- !tosa.shape<0>, !tosa.shape<0>, !tosa.shape<0>, !tosa.shape<0>, !tosa.shape<0>, !tosa.shape<0>, !tosa.shape<0>, !tosa.shape<0>,
- !tosa.shape<0>, !tosa.shape<0>, !tosa.shape<0>, !tosa.shape<0>, !tosa.shape<0>, !tosa.shape<0>, !tosa.shape<0>, !tosa.shape<0>,
- !tosa.shape<0>, !tosa.shape<0>, !tosa.shape<0>, !tosa.shape<0>, !tosa.shape<0>, !tosa.shape<0>, !tosa.shape<0>, !tosa.shape<0>,
- !tosa.shape<0>, !tosa.shape<0>, !tosa.shape<0>, !tosa.shape<0>, !tosa.shape<0>, !tosa.shape<0>, !tosa.shape<0>, !tosa.shape<0>,
- !tosa.shape<0>, !tosa.shape<0>, !tosa.shape<0>, !tosa.shape<0>, !tosa.shape<0>, !tosa.shape<0>, !tosa.shape<0>, !tosa.shape<0>,
- !tosa.shape<0>
- ) -> !tosa.shape<0>
- return
-}
-
-// -----
-
func.func @test_exp2_shape_invalid_rank() -> !tosa.shape<17> {
%0 = tosa.const_shape {values = dense<0> : tensor<17xindex>} : () -> !tosa.shape<17>
// expected-error at +1 {{'tosa.exp2_shape' op failed shape type level check: '!tosa.shape<17>' exceeds MAX_SHAPE_LEN}}
diff --git a/mlir/test/Dialect/Tosa/ops.mlir b/mlir/test/Dialect/Tosa/ops.mlir
index 44cfd5cfc9400..56811891e8f95 100644
--- a/mlir/test/Dialect/Tosa/ops.mlir
+++ b/mlir/test/Dialect/Tosa/ops.mlir
@@ -1499,16 +1499,6 @@ func.func @test_concat_shape() -> !tosa.shape<5> {
return %3 : !tosa.shape<5>
}
-// -----
-// CHECK-LABEL: test_concat_shape_rank_0
-func.func @test_concat_shape_rank_0() -> !tosa.shape<0> {
- %0 = tosa.const_shape {values = dense<[]> : tensor<0xindex>} : () -> !tosa.shape<0>
- %1 = tosa.const_shape {values = dense<[]> : tensor<0xindex>} : () -> !tosa.shape<0>
- %2 = tosa.const_shape {values = dense<[]> : tensor<0xindex>} : () -> !tosa.shape<0>
- %3 = tosa.concat_shape %0, %1, %2 : (!tosa.shape<0>, !tosa.shape<0>, !tosa.shape<0>) -> !tosa.shape<0>
- return %3 : !tosa.shape<0>
-}
-
// -----
// CHECK-LABEL: test_slice_shape
func.func @test_slice_shape() -> !tosa.shape<3> {
diff --git a/mlir/test/Dialect/Tosa/verifier.mlir b/mlir/test/Dialect/Tosa/verifier.mlir
index 742bae3847da5..3621c25005862 100644
--- a/mlir/test/Dialect/Tosa/verifier.mlir
+++ b/mlir/test/Dialect/Tosa/verifier.mlir
@@ -1284,6 +1284,25 @@ func.func @test_concat_shape_rank_mismatch() -> !tosa.shape<4> {
// -----
+func.func @test_concat_shape_no_inputs() -> !tosa.shape<0> {
+ // expected-error at +1 {{'tosa.concat_shape' op requires at least one input shape}}
+ %0 = tosa.concat_shape {} : () -> !tosa.shape<0>
+ return %0 : !tosa.shape<0>
+}
+
+// -----
+
+func.func @test_concat_shape_rank_0() -> !tosa.shape<0> {
+ %0 = tosa.const_shape {values = dense<[]> : tensor<0xindex>} : () -> !tosa.shape<0>
+ %1 = tosa.const_shape {values = dense<[]> : tensor<0xindex>} : () -> !tosa.shape<0>
+ %2 = tosa.const_shape {values = dense<[]> : tensor<0xindex>} : () -> !tosa.shape<0>
+ // expected-error at +1 {{'tosa.concat_shape' op requires all inputs shapes have a rank greater than 0}}
+ %3 = tosa.concat_shape %0, %1, %2 : (!tosa.shape<0>, !tosa.shape<0>, !tosa.shape<0>) -> !tosa.shape<0>
+ return %3 : !tosa.shape<0>
+}
+
+// -----
+
func.func @test_slice_shape_negative_start() -> !tosa.shape<3> {
%0 = tosa.const_shape {values = dense<[4, 5, 6, 7, 8, 9]> : tensor<6xindex>} : () -> !tosa.shape<6>
%1 = "tosa.const"() {values = dense<-1> : tensor<1xi32>} : () -> tensor<1xi32>
More information about the Mlir-commits
mailing list