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 @@ -1780,19 +1780,13 @@ Value emptyTensor = rewriter.create( loc, resultType.getShape(), resultType.getElementType(), dynDims); - Value zeroVal = rewriter.createOrFold( - loc, rewriter.getZeroAttr(resultType.getElementType())); - Value result = rewriter - .create(loc, ValueRange{zeroVal}, - ValueRange{emptyTensor}) - .result(); - auto toOpFoldResult = [](Value v) -> OpFoldResult { auto op = v.getDefiningOp(); if (!op) return v; return op.getValue(); }; + Value result = emptyTensor; for (auto arg : adaptor.getOperands()) { sizes[axis] = rewriter.createOrFold(loc, arg, axisValue); result = rewriter.createOrFold( 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 @@ -929,9 +929,7 @@ // CHECK: [[IDX0:%.+]] = arith.constant 0 : index // CHECK: [[IDX1:%.+]] = arith.constant 1 : index // CHECK: [[INIT:%.+]] = tensor.empty() : tensor<11x1xf32> - // CHECK: [[CST:%.+]] = arith.constant 0.0 - // CHECK: [[FILL:%.+]] = linalg.fill ins([[CST]]{{.*}}outs([[INIT]] - // CHECK: [[INSERT0:%.+]] = tensor.insert_slice %[[ARG0]] into [[FILL]][0, 0] [5, 1] [1, 1] + // CHECK: [[INSERT0:%.+]] = tensor.insert_slice %[[ARG0]] into [[INIT]][0, 0] [5, 1] [1, 1] // CHECK: [[INSERT1:%.+]] = tensor.insert_slice %[[ARG1]] into [[INSERT0]][5, 0] [6, 1] [1, 1] %0 = "tosa.concat"(%arg0, %arg1) { axis = 0 : i64} : (tensor<5x1xf32>, tensor<6x1xf32>) -> (tensor<11x1xf32>) @@ -941,9 +939,7 @@ // CHECK: [[IDX0:%.+]] = arith.constant 0 : index // CHECK: [[IDX1:%.+]] = arith.constant 1 : index // CHECK: [[INIT:%.+]] = tensor.empty() : tensor<5x2xf32> - // CHECK: [[CST:%.+]] = arith.constant 0.0 - // CHECK: [[FILL:%.+]] = linalg.fill ins([[CST]]{{.*}}outs([[INIT]] - // CHECK: [[INSERT0:%.+]] = tensor.insert_slice %[[ARG0]] into [[FILL]][0, 0] [5, 1] [1, 1] + // CHECK: [[INSERT0:%.+]] = tensor.insert_slice %[[ARG0]] into [[INIT]][0, 0] [5, 1] [1, 1] // CHECK: [[INSERT1:%.+]] = tensor.insert_slice %[[ARG0]] into [[INSERT0]][0, 1] [5, 1] [1, 1] %1 = "tosa.concat"(%arg0, %arg0) { axis = 1 : i64} : (tensor<5x1xf32>, tensor<5x1xf32>) -> (tensor<5x2xf32>) return @@ -964,9 +960,7 @@ // CHECK: %[[IDX1_2:.+]] = arith.constant 1 : index // CHECK: %[[DYN:.+]] = tensor.dim %[[ARG0]], %[[IDX1_2]] // CHECK: %[[INIT:.+]] = tensor.empty(%[[DYN]]) : tensor<11x?xf32> - // CHECK: %[[CST:.+]] = arith.constant 0.0 - // CHECK: %[[FILL:.+]] = linalg.fill ins(%[[CST]]{{.*}}outs(%[[INIT]] - // CHECK: %[[INSERT0:.+]] = tensor.insert_slice %[[ARG0]] into %[[FILL]][0, 0] [5, %[[SIZE]]] [1, 1] + // CHECK: %[[INSERT0:.+]] = tensor.insert_slice %[[ARG0]] into %[[INIT]][0, 0] [5, %[[SIZE]]] [1, 1] // CHECK: %[[INSERT1:.+]] = tensor.insert_slice %[[ARG1]] into %[[INSERT0]][5, 0] [6, %[[SIZE]]] [1, 1] %0 = "tosa.concat"(%arg0, %arg1) { axis = 0 : i64} : (tensor<5x?xf32>, tensor<6x?xf32>) -> (tensor<11x?xf32>) return @@ -987,10 +981,8 @@ // CHECK: %[[DYN:.+]] = tensor.dim %[[ARG0]], %[[IDX0_2]] // CHECK: %[[IDX1:.+]] = arith.constant 1 : index // CHECK: %[[INIT:.+]] = tensor.empty(%[[DYN]]) : tensor - // CHECK: %[[CST:.+]] = arith.constant 0.0 - // CHECK: %[[FILL:.+]] = linalg.fill ins(%[[CST]]{{.*}}outs(%[[INIT]] // CHECK: %[[DYN1:.+]] = tensor.dim %[[ARG0]], %[[AXIS]] - // CHECK: %[[INSERT0:.+]] = tensor.insert_slice %[[ARG0]] into %[[FILL]][0, 0] [%[[DYN1]], 3] [1, 1] + // CHECK: %[[INSERT0:.+]] = tensor.insert_slice %[[ARG0]] into %[[INIT]][0, 0] [%[[DYN1]], 3] [1, 1] // CHECK: %[[SUM:.+]] = arith.addi %[[OFFSET]], %[[DYN1]] // CHECK: %[[DYN2:.+]] = tensor.dim %[[ARG1]], %[[AXIS]] // CHECK: %[[INSERT1:.+]] = tensor.insert_slice %[[ARG1]] into %[[INSERT0]][%[[SUM]], 0] [%[[DYN2]], 3] [1, 1]