From cd57994e95fddcd64ef81f8b3bca15faa181422b Mon Sep 17 00:00:00 2001 From: Alexander Belyaev Date: Thu, 12 Jan 2023 12:51:23 +0100 Subject: [PATCH] Revert "[mlir][linalg] Swap extract_slice(fill(x)) ops" This reverts commit bcfd32adc4b658dc45aa8c338d5dd03837e2a0e4. There is already a similar pattern in mlir/lib/Dialect/Linalg/Transforms/SwapExtractSliceWithFillPatterns.cpp Differential Revision: https://reviews.llvm.org/D141597 --- mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp | 32 +----------------------------- mlir/test/Dialect/Linalg/canonicalize.mlir | 14 ------------- 2 files changed, 1 insertion(+), 45 deletions(-) diff --git a/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp b/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp index 7f5bcce..0b7642f 100644 --- a/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp +++ b/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp @@ -463,36 +463,6 @@ struct FoldFillWithTensorReshape : OpRewritePattern { } }; -/// Swap extract_slice(fill) to fill(extract_slice). -/// -/// Only swap the two ops if the extract_slice is the only user of the fill. -struct SwapExtractSliceOfFill : OpRewritePattern { - using OpRewritePattern::OpRewritePattern; - LogicalResult matchAndRewrite(tensor::ExtractSliceOp extractSliceOp, - PatternRewriter &rewriter) const override { - auto oldFill = extractSliceOp.getSource().getDefiningOp(); - if (!oldFill) - return failure(); - // Only swap the ops if there is no other user of the fill. - if (!extractSliceOp.getSource().hasOneUse()) - return failure(); - // Extract from the old fill's source. - rewriter.updateRootInPlace(extractSliceOp, [&]() { - extractSliceOp.getSourceMutable().assign(oldFill.output()); - }); - // Create a new fill and remove the old one. - rewriter.setInsertionPointAfter(extractSliceOp); - auto newFill = - rewriter.create(oldFill.getLoc(), ValueRange{oldFill.value()}, - ValueRange{extractSliceOp.getResult()}); - rewriter.eraseOp(oldFill); - // Use the new fill instead of the extract_slice. - rewriter.replaceAllUsesExcept(extractSliceOp.getResult(), - newFill.getResult(0), newFill); - return success(); - } -}; - /// Fold tensor.pad(linalg.fill) into linalg.fill if the padding value and the /// filling value are the same. struct FoldFillWithPad final : public OpRewritePattern { @@ -637,7 +607,7 @@ void FillOp::getCanonicalizationPatterns(RewritePatternSet &results, results .add, FoldFillWithTensorReshape, - FoldInsertPadIntoFill, SwapExtractSliceOfFill>(context); + FoldInsertPadIntoFill>(context); } //===----------------------------------------------------------------------===// diff --git a/mlir/test/Dialect/Linalg/canonicalize.mlir b/mlir/test/Dialect/Linalg/canonicalize.mlir index ee94d07..9e4d886c 100644 --- a/mlir/test/Dialect/Linalg/canonicalize.mlir +++ b/mlir/test/Dialect/Linalg/canonicalize.mlir @@ -312,20 +312,6 @@ func.func @fold_fill_reshape() -> tensor<6x4xf32> { // ----- -// CHECK-LABEL: func @fold_fill_extract_slice( -// CHECK-SAME: %[[t:.*]]: tensor<1x1xf32> -func.func @fold_fill_extract_slice(%t: tensor<1x1xf32>) -> (tensor) { - %cst = arith.constant 0.000000e+00 : f32 - // CHECK: %[[e:.*]] = tensor.extract_slice %[[t]] - // CHECK: %[[f:.*]] = linalg.fill {{.*}} outs(%[[e]] : tensor) - %0 = linalg.fill ins(%cst : f32) outs(%t : tensor<1x1xf32>) -> tensor<1x1xf32> - %1 = tensor.extract_slice %0[0, 0] [1, 1] [1, 1] : tensor<1x1xf32> to tensor - // CHECK: return %[[f]] - return %1 : tensor -} - -// ----- - // CHECK: func @fold_fill_reshape_dynamic // CHECK-SAME: %[[ARG0:.+]]: tensor func.func @fold_fill_reshape_dynamic(%arg0 : tensor) -> tensor { -- 2.7.4