[Mlir-commits] [mlir] [mlir][tosa] Add concat/slice_shape ops (PR #174620)
Peng Sun
llvmlistbot at llvm.org
Wed Jan 7 13:50:26 PST 2026
================
@@ -4666,6 +4666,56 @@ LogicalResult tosa::DimOp::verify() {
return success();
}
+LogicalResult tosa::ConcatShapeOp::verify() {
+ const tosa::shapeType outShapeType =
+ cast<tosa::shapeType>(getResult().getType());
+ const int64_t outputRank = outShapeType.getRank();
+ const Operation::operand_range inputList = getInput();
+ const int64_t inputsRank =
+ llvm::accumulate(inputList, 0, [](int64_t acc, const Value &input) {
+ const tosa::shapeType inShapeType =
+ cast<tosa::shapeType>(input.getType());
+ return acc + inShapeType.getRank();
+ });
+ if (outputRank != inputsRank)
+ return emitOpError("requires output shape rank to be equal to the sum of "
+ "the input shape ranks (")
+ << inputsRank << "), got " << outputRank;
+
+ return success();
+}
+
+LogicalResult tosa::SliceShapeOp::verify() {
----------------
psunn wrote:
`slice_shape` verifier never checks that the declared result rank matches the requested slice length when `size` is constant.
For example, this testcase would pass, even though the op promises a 3‑element slice. That can propagate inconsistent shape types into later passes
```
func.func @test_slice_shape_result_rank_mismatch() -> !tosa.shape<4> {
%shape = tosa.const_shape {values = dense<[4, 5, 6, 7, 8, 9]> : tensor<6xindex>} : () -> !tosa.shape<6>
%start = "tosa.const"() {values = dense<1> : tensor<1xi32>} : () -> tensor<1xi32>
%size = "tosa.const"() {values = dense<3> : tensor<1xi32>} : () -> tensor<1xi32>
%slice = tosa.slice_shape %shape, %start, %size : (!tosa.shape<6>, tensor<1xi32>, tensor<1xi32>) -> !tosa.shape<4>
return %slice : !tosa.shape<4>
}
```
https://github.com/llvm/llvm-project/pull/174620
More information about the Mlir-commits
mailing list