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

llvmlistbot at llvm.org llvmlistbot at llvm.org
Fri May 17 04:21:57 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlir-vector

Author: Hugo Trachino (nujaa)

<details>
<summary>Changes</summary>

`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

---
Full diff: https://github.com/llvm/llvm-project/pull/92526.diff


1 Files Affected:

- (modified) mlir/include/mlir/Dialect/Vector/Utils/VectorUtils.h (+4-1) 


``````````diff
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();
   }
 

``````````

</details>


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


More information about the Mlir-commits mailing list