-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[mlir][Transforms] Dialect conversion: Fix bug in UnresolvedMaterializationRewrite
rollback
#105949
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][Transforms] Dialect conversion: Fix bug in UnresolvedMaterializationRewrite
rollback
#105949
Conversation
@llvm/pr-subscribers-mlir-core @llvm/pr-subscribers-mlir Author: Matthias Springer (matthias-springer) ChangesWhen an unresolved materialization ( It is not possible to write a test case for this because I cannot trigger the pointer reuse programmatically. Full diff: https://github.com/llvm/llvm-project/pull/105949.diff 1 Files Affected:
diff --git a/mlir/lib/Transforms/Utils/DialectConversion.cpp b/mlir/lib/Transforms/Utils/DialectConversion.cpp
index 4058ed39621198..11e40b74b00424 100644
--- a/mlir/lib/Transforms/Utils/DialectConversion.cpp
+++ b/mlir/lib/Transforms/Utils/DialectConversion.cpp
@@ -1062,10 +1062,8 @@ void CreateOperationRewrite::rollback() {
}
void UnresolvedMaterializationRewrite::rollback() {
- if (getMaterializationKind() == MaterializationKind::Target) {
- for (Value input : op->getOperands())
- rewriterImpl.mapping.erase(input);
- }
+ for (Value input : op->getOperands())
+ rewriterImpl.mapping.erase(input);
op->erase();
}
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems fine to me, as in being a step in the right direction, but it doesn't seem guaranteed to me that the input operand was actually the operand that was originally mapped to the materilization:
mapping.map(mapping.lookupOrDefault(newOperand), castValue); |
That said, this seems to be more of a pre-existing issue to me.
You are right, it's not a perfect rollback and there are probably other issues that are not fixed by this PR. It's actually not just that line of code that you pointed out. Here's another one:
I think this is due to the fact that:
I'm thinking about fixing that. But not sure if it's worth it, because ultimately I want to get to a state where all IR changes are materialized immediately, and there is no need for a (The purpose of this change was mostly to cut down on code size. Bonus points if it fixes something. Anything that reduces complexity and the lines of code will make it easier to maintain the code base and/or build a new conversion driver.) |
0b9a69b
to
6a76672
Compare
@zero9178 I never merged this PR, but this issue was now triggered by a Google-internal test case when I asked @jpienaar to test #116470 internally before merging it. (I originally put these changes into #116470, but I think it's better to merge two smaller PRs with a day in-between.) My original fix may not have been enough. (Or maybe it was, I don't want to take any chances...) This is now rolling back the mapping exactly to the previous state, addressing your comment here. I'm still not able to write a test case for this. (Because Can you take an other brief look at this before I merge it? |
6a76672
to
85a297e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thank you! Greatly prefer this more principled approache.
One minor possible enhancement in the comment.
When an unresolved materialization (
unrealized_conversion_cast
op) is rolled back, the mapping should be rolled back as well, regardless of whether it is a source, target or argument materialization. Otherwise, we accumulate pointers to erased IR in themapping
. This is harmless in most cases, but can cause issues when a new operation is allocated at the same memory location and the pointer is "reused".It is not possible to write a test case for this because I cannot trigger the pointer reuse programmatically.