diff --git a/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp b/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp --- a/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp +++ b/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp @@ -935,10 +935,9 @@ // Create the new op with the body being empty. Location loc = genericOp.getLoc(); SmallVector newResultTypes; - if (genericOp.hasTensorSemantics()) { - newResultTypes = llvm::to_vector(llvm::map_range( - newOutputOperands, [](Value v) { return v.getType(); })); - } + for (Value v : newOutputOperands) + if (v.getType().isa()) + newResultTypes.push_back(v.getType()); auto newOp = rewriter.create( loc, newResultTypes, newInputOperands, newOutputOperands, rewriter.getAffineMapArrayAttr(newIndexingMaps), diff --git a/mlir/test/Dialect/Linalg/canonicalize.mlir b/mlir/test/Dialect/Linalg/canonicalize.mlir --- a/mlir/test/Dialect/Linalg/canonicalize.mlir +++ b/mlir/test/Dialect/Linalg/canonicalize.mlir @@ -846,3 +846,27 @@ // CHECK-SAME: iterator_types = ["parallel"] // CHECK-SAME: } ins(%[[ARG1]] : tensor) // CHECK-SAME: outs(%[[ARG2]] : memref) { + +// ----- + +// Just make sure that we don't crash. + +// CHECK-LABEL: func @dedeplicate_regression_test +func.func @dedeplicate_regression_test(%0: tensor<4xf32>, %1: memref<4xf32>) { + %36 = linalg.generic + {indexing_maps = [affine_map<(d0) -> (d0)>, + affine_map<(d0) -> (d0)>, affine_map<(d0) -> (d0)>], + iterator_types = ["parallel"]} + ins(%1, %1 : memref<4xf32>, memref<4xf32>) + outs(%0 : tensor<4xf32>) { + ^bb0(%in: f32, %in_24: f32, %out: f32): + linalg.yield %in : f32 + } -> tensor<4xf32> + %53 = linalg.generic {indexing_maps = [affine_map<(d0) -> (d0)>], + iterator_types = ["parallel"]} + outs(%36 : tensor<4xf32>) { + ^bb0(%out: f32): + linalg.yield %out : f32 + } -> tensor<4xf32> + return +}