From: Ivan Butygin Date: Tue, 11 Oct 2022 23:14:35 +0000 (+0200) Subject: [mlir][linalg] Fix canonicalizer crash for `linalg.generic` with mixed semantics X-Git-Tag: upstream/17.0.6~30374 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=04ac8cb8e1faf16cab71add0eaa6c591db91c341;p=platform%2Fupstream%2Fllvm.git [mlir][linalg] Fix canonicalizer crash for `linalg.generic` with mixed semantics `EraseIdentityGenericOp` for `!hasBufferSemantics()` assumed fully tensor semantics and tried to access non-existent return values. Differential Revision: https://reviews.llvm.org/D135725 --- diff --git a/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp b/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp index 586d198..2fcd21c 100644 --- a/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp +++ b/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp @@ -1176,6 +1176,10 @@ struct EraseIdentityGenericOp : public OpRewritePattern { return failure(); } + // Mixed semantics is not supported yet. + if (!genericOp.hasTensorSemantics()) + return failure(); + // Get the argument number of the returned values. That is the operand // number to use for replacing uses of this operation. SmallVector returnedArgs; diff --git a/mlir/test/Dialect/Linalg/canonicalize.mlir b/mlir/test/Dialect/Linalg/canonicalize.mlir index 2062c65..8f8f600 100644 --- a/mlir/test/Dialect/Linalg/canonicalize.mlir +++ b/mlir/test/Dialect/Linalg/canonicalize.mlir @@ -821,3 +821,28 @@ func.func @fold_multi_use_generic_op_with_consumer(%arg0 : tensor) -> // CHECK-SAME: outs(%[[INIT2]], %[[INIT1]] : // CHECK: %[[RETURN_CAST:.+]] = tensor.cast %[[GENERIC]]#0 : tensor<3x2x4xf32> to tensor // CHECK: return %[[RETURN_CAST]], %[[GENERIC]]#1 + +// ----- + +#map = affine_map<(d0) -> (d0)> +func.func @identity_mixed(%arg0 : tensor, %arg1: memref) { + linalg.generic { + indexing_maps = [#map, #map], + iterator_types = ["parallel"] + } ins(%arg0 : tensor) + outs(%arg1 : memref) { + ^bb0(%arg2 : f32, %arg3 : f32): + linalg.yield %arg2 : f32 + } + return +} + +// There was a crash in EraseIdentityGenericOp for generic with mixed semantics. +// For now, check generic remained unchanged. +// CHECK-LABEL: func @identity_mixed +// CHECK-SAME: (%[[ARG1:.*]]: tensor, %[[ARG2:.*]]: memref) +// CHECK: linalg.generic { +// CHECK-SAME: indexing_maps = [#map, #map], +// CHECK-SAME: iterator_types = ["parallel"] +// CHECK-SAME: } ins(%[[ARG1]] : tensor) +// CHECK-SAME: outs(%[[ARG2]] : memref) {