diff --git a/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp b/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp index 780cd03d974382..3a025437bc05bf 100644 --- a/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp +++ b/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp @@ -813,12 +813,18 @@ LogicalResult tosa::TransposeOp::inferReturnTypeComponents( // If input rank and permutation length is unknown, the output rank is // unknown. - if (!inputShape.hasRank() && - (!permsShape.hasRank() || permsShape.isDynamicDim(0))) { + if (!inputShape.hasRank() || !permsShape.hasRank() || + permsShape.isDynamicDim(0)) { inferredReturnShapes.push_back(ShapedTypeComponents()); return success(); } + // This would imply the number of permutations does not match the rank of the + // input which is illegal. + if (permsShape.getDimSize(0) != inputShape.getRank()) { + return failure(); + } + // Without the input dims we cannot determine the output dim sizes but we // can determine the output rank. SmallVector outputShape;