diff --git a/mlir/lib/Dialect/Linalg/Transforms/Transforms.cpp b/mlir/lib/Dialect/Linalg/Transforms/Transforms.cpp index 7dcc9770de6c..f98666751eef 100644 --- a/mlir/lib/Dialect/Linalg/Transforms/Transforms.cpp +++ b/mlir/lib/Dialect/Linalg/Transforms/Transforms.cpp @@ -592,6 +592,10 @@ LogicalResult mlir::linalg::LinalgTileAndFuseTensorOpsPattern::matchAndRewrite( SmallVector rootTileSizes(options.tileSizes.begin(), options.tileSizes.begin() + rootOp.getNumLoops()); + if (llvm::all_of(rootTileSizes, [](int64_t ts) { return ts == 0; })) { + return rewriter.notifyMatchFailure( + op, "all tile sizes are zero, nothing to do"); + } SmallVector rootInterchange = options.tileInterchange.empty() ? llvm::to_vector<6>(llvm::seq(0, rootOp.getNumLoops())) diff --git a/mlir/test/Dialect/Linalg/tile-and-fuse-no-fuse.mlir b/mlir/test/Dialect/Linalg/tile-and-fuse-no-fuse.mlir new file mode 100644 index 000000000000..80fc9bb4c596 --- /dev/null +++ b/mlir/test/Dialect/Linalg/tile-and-fuse-no-fuse.mlir @@ -0,0 +1,19 @@ +// RUN: mlir-opt %s -test-linalg-codegen-strategy="anchor-op=linalg.generic fuse tile-sizes=0,0 run-enable-pass=false" -cse -split-input-file | FileCheck %s + +builtin.func @no_fuse_gemm(%arg0 : tensor, %arg1 : tensor) -> tensor { + %c0 = arith.constant 0 : index + %c1 = arith.constant 1 : index + %cst = arith.constant 0.0 : f32 + %d0 = tensor.dim %arg0, %c0 : tensor + %d1 = tensor.dim %arg1, %c1 : tensor + %init = linalg.init_tensor [%d0, %d1] : tensor + %fill = linalg.fill(%cst, %init) : f32, tensor -> tensor + %result = linalg.matmul ins(%arg0, %arg1 : tensor, tensor) + outs(%fill : tensor) -> tensor + return %result : tensor +} +// CHECK-LABEL: @no_fuse_gemm( +// CHECK-NOT: scf.for +// CHECK: linalg.fill +// CHECK-NOT: scf.for +// CHECK: linalg.matmul