Skip to content
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

[mlir][EmitC] Fix invalid rewriter API usage #76124

Merged
merged 1 commit into from
Dec 21, 2023

Conversation

matthias-springer
Copy link
Member

When operations are modified in-place, the rewriter must be notified. This commit fixes mlir/test/Dialect/EmitC/transforms.mlir when running with MLIR_ENABLE_EXPENSIVE_PATTERN_API_CHECKS enabled.

When operations are modified in-place, the rewriter must be notified. This commit fixes `mlir/test/Dialect/EmitC/transforms.mlir` when running with `MLIR_ENABLE_EXPENSIVE_PATTERN_API_CHECKS` enabled.
@llvmbot
Copy link
Member

llvmbot commented Dec 21, 2023

@llvm/pr-subscribers-mlir

@llvm/pr-subscribers-mlir-emitc

Author: Matthias Springer (matthias-springer)

Changes

When operations are modified in-place, the rewriter must be notified. This commit fixes mlir/test/Dialect/EmitC/transforms.mlir when running with MLIR_ENABLE_EXPENSIVE_PATTERN_API_CHECKS enabled.


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

1 Files Affected:

  • (modified) mlir/lib/Dialect/EmitC/Transforms/Transforms.cpp (+1-4)
diff --git a/mlir/lib/Dialect/EmitC/Transforms/Transforms.cpp b/mlir/lib/Dialect/EmitC/Transforms/Transforms.cpp
index 593d774cac73bd..88b691b50f325d 100644
--- a/mlir/lib/Dialect/EmitC/Transforms/Transforms.cpp
+++ b/mlir/lib/Dialect/EmitC/Transforms/Transforms.cpp
@@ -96,10 +96,7 @@ struct FoldExpressionOp : public OpRewritePattern<ExpressionOp> {
         assert(clonedExpressionRootOp->getNumResults() == 1 &&
                "Expected cloned root to have a single result");
 
-        Value clonedExpressionResult = clonedExpressionRootOp->getResult(0);
-
-        usedExpression.getResult().replaceAllUsesWith(clonedExpressionResult);
-        rewriter.eraseOp(usedExpression);
+        rewriter.replaceOp(usedExpression, clonedExpressionRootOp);
         anythingFolded = true;
       }
     }

Copy link
Contributor

@aniragil aniragil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this, Matthias!

Copy link
Member

@marbre marbre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@matthias-springer matthias-springer merged commit d8d0929 into llvm:main Dec 21, 2023
5 checks passed
mgehre-amd pushed a commit to Xilinx/llvm-project that referenced this pull request Mar 11, 2024
When operations are modified in-place, the rewriter must be notified.
This commit fixes `mlir/test/Dialect/EmitC/transforms.mlir` when running
with `MLIR_ENABLE_EXPENSIVE_PATTERN_API_CHECKS` enabled.
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.

4 participants