diff --git a/mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp b/mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp --- a/mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp +++ b/mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp @@ -614,7 +614,7 @@ operands.push_back(operand); indexingMaps.push_back(AffineMap::get( - /*dimCount=*/type.getRank(), /*symbolCount=*/0, affineExprs, + /*dimCount=*/rank, /*symbolCount=*/0, affineExprs, rewriter.getContext())); } diff --git a/mlir/test/Conversion/TosaToLinalg/tosa-to-linalg.mlir b/mlir/test/Conversion/TosaToLinalg/tosa-to-linalg.mlir --- a/mlir/test/Conversion/TosaToLinalg/tosa-to-linalg.mlir +++ b/mlir/test/Conversion/TosaToLinalg/tosa-to-linalg.mlir @@ -1990,3 +1990,18 @@ %output = "tosa.resize"(%input) { scale = [4, 2, 4, 2], offset = [-1, -1], border = [1, 1], mode = "BILINEAR" } : (tensor) -> (tensor) return } + +// ----- + +// Regression test for using the wrong rank. + +// CHECK-DAG: affine_map<(d0, d1, d2, d3) -> (d0, d2, d3)> +// CHECK-DAG: affine_map<(d0, d1, d2, d3) -> (d0, d1, d2, d3)> +// CHECK-DAG: affine_map<(d0, d1, d2, d3) -> ()> +// CHECK-LABEL: @select_fp32 +func.func @select_fp32(%arg0: tensor<1x1x5x5xi1>, %arg1: tensor<1x12x5x5xf32>, %arg2: tensor) -> tensor<1x12x5x5xf32> { + // CHECK: linalg.generic + %0 = "tosa.select"(%arg0, %arg1, %arg2) : (tensor<1x1x5x5xi1>, tensor<1x12x5x5xf32>, tensor) -> tensor<1x12x5x5xf32> + return %0 : tensor<1x12x5x5xf32> +} +