Skip to content

[mlir][vector] Support MaskableOpRewritePattern of op without a result. #92526

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

nujaa
Copy link
Contributor

@nujaa nujaa commented May 17, 2024

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 : #91987

@nujaa
Copy link
Contributor Author

nujaa commented May 17, 2024

CC @banach-space .

@llvmbot
Copy link
Member

llvmbot commented May 17, 2024

@llvm/pr-subscribers-mlir

@llvm/pr-subscribers-mlir-vector

Author: Hugo Trachino (nujaa)

Changes

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 : #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 --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();
   }
 

nujaa added a commit to nujaa/llvm-project that referenced this pull request May 17, 2024
nujaa added a commit to nujaa/llvm-project that referenced this pull request May 17, 2024
@banach-space
Copy link
Contributor

banach-space commented May 17, 2024

Thanks, now I realise what I was missing in #91987 (it was there, but I didn't notice). I think that it's fine to keep this within #91987 - that way it's easier to test.

@nujaa nujaa closed this May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants