[Mlir-commits] [mlir] [mlir][vector] Support MaskableOpRewritePattern of op without a result. (PR #92526)

Hugo Trachino llvmlistbot at llvm.org
Fri May 17 04:21:28 PDT 2024


https://github.com/nujaa created https://github.com/llvm/llvm-project/pull/92526

`MaskableOpRewritePattern` implements a wrapper of `MatchAndRewrite` as a solution to rewrite masked operators to prevent rewritepatterns to generate multiple ops inside a `MaskOp` (illegal).

This fix aims to target the case where the target op does not have a result (such as a transfer_write at memref_level). `replaceOp` would break if given an empty value.
Stems from : https://github.com/llvm/llvm-project/pull/91987

>From 2f7fc4bcc667aeea40357dfe1ac5d12a2162f61b Mon Sep 17 00:00:00 2001
From: Hugo <hugo.trachino at huawei.com>
Date: Fri, 17 May 2024 18:49:31 +0800
Subject: [PATCH] [mlir][vector] Support MaskableOpRewritePattern of Op without
 a result.

---
 mlir/include/mlir/Dialect/Vector/Utils/VectorUtils.h | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/mlir/include/mlir/Dialect/Vector/Utils/VectorUtils.h b/mlir/include/mlir/Dialect/Vector/Utils/VectorUtils.h
index 030be328e97fd..bf9694556f901 100644
--- a/mlir/include/mlir/Dialect/Vector/Utils/VectorUtils.h
+++ b/mlir/include/mlir/Dialect/Vector/Utils/VectorUtils.h
@@ -157,7 +157,10 @@ struct MaskableOpRewritePattern : OpRewritePattern<SourceOp> {
     if (failed(newOp))
       return failure();
 
-    rewriter.replaceOp(rootOp, *newOp);
+    if (rootOp->getNumResults() == 0 || *newOp == Value())
+      rewriter.eraseOp(rootOp);
+    else
+      rewriter.replaceOp(rootOp, *newOp);
     return success();
   }
 



More information about the Mlir-commits mailing list