-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[mlir] fix dialect conversion with no type converter #123154
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
Conversation
|
@llvm/pr-subscribers-mlir-core Author: Maksim Levental (makslevental) Changes
if (!currentTypeConverter) {
// The current pattern does not have a type converter. I.e., it does not
// distinguish between legal and illegal types. For each operand, simply
// pass through the most recently mapped values.
remapped.push_back(mapping.lookupOrDefault(operand));
continue;
}Emphasis on ValueVector
ConversionValueMapping::lookupOrDefault(...) const {
...
do {
...
if (TypeRange(ValueRange(current)) == desiredTypes)
desiredValue = current;
....
if (next != current) {
// If at least one value was replaced, continue the lookup from there.
current = std::move(next);
continue;
}
...
if (it == mapping.end()) {
// No mapping found: The lookup stops here.
break;
}
current = it->second;
} while (true);
// If the desired values were found use them, otherwise default to the leaf values.
return !desiredValue.empty() ? std::move(desiredValue) : std::move(current);
}Note, that The fix is to condition continuing the while loop on Full diff: https://github.com/llvm/llvm-project/pull/123154.diff 1 Files Affected:
diff --git a/mlir/lib/Transforms/Utils/DialectConversion.cpp b/mlir/lib/Transforms/Utils/DialectConversion.cpp
index 403321d40d53c9..34e5d56bd95055 100644
--- a/mlir/lib/Transforms/Utils/DialectConversion.cpp
+++ b/mlir/lib/Transforms/Utils/DialectConversion.cpp
@@ -208,7 +208,7 @@ ConversionValueMapping::lookupOrDefault(Value from,
next.push_back(v);
}
}
- if (next != current) {
+ if (!desiredTypes.empty() && next != current) {
// If at least one value was replaced, continue the lookup from there.
current = std::move(next);
continue;
|
|
@llvm/pr-subscribers-mlir Author: Maksim Levental (makslevental) Changes
if (!currentTypeConverter) {
// The current pattern does not have a type converter. I.e., it does not
// distinguish between legal and illegal types. For each operand, simply
// pass through the most recently mapped values.
remapped.push_back(mapping.lookupOrDefault(operand));
continue;
}Emphasis on ValueVector
ConversionValueMapping::lookupOrDefault(...) const {
...
do {
...
if (TypeRange(ValueRange(current)) == desiredTypes)
desiredValue = current;
....
if (next != current) {
// If at least one value was replaced, continue the lookup from there.
current = std::move(next);
continue;
}
...
if (it == mapping.end()) {
// No mapping found: The lookup stops here.
break;
}
current = it->second;
} while (true);
// If the desired values were found use them, otherwise default to the leaf values.
return !desiredValue.empty() ? std::move(desiredValue) : std::move(current);
}Note, that The fix is to condition continuing the while loop on Full diff: https://github.com/llvm/llvm-project/pull/123154.diff 1 Files Affected:
diff --git a/mlir/lib/Transforms/Utils/DialectConversion.cpp b/mlir/lib/Transforms/Utils/DialectConversion.cpp
index 403321d40d53c9..34e5d56bd95055 100644
--- a/mlir/lib/Transforms/Utils/DialectConversion.cpp
+++ b/mlir/lib/Transforms/Utils/DialectConversion.cpp
@@ -208,7 +208,7 @@ ConversionValueMapping::lookupOrDefault(Value from,
next.push_back(v);
}
}
- if (next != current) {
+ if (!desiredTypes.empty() && next != current) {
// If at least one value was replaced, continue the lookup from there.
current = std::move(next);
continue;
|
f9c2990 to
a37315c
Compare
a37315c to
b3fc08a
Compare
ConversionPatternRewriterImpl::remapValueshas a bug when no type converter is used for a 1:N dialect conversion:Emphasis on
most recently mapped values.But the implementation of
mapping.lookupOrDefaultin such a case does not coincide; it always recurses all the way back to the leaf values:Note, that
desiredTypesis empty and thusdesiredValue.empty()is always true and thusstd::move(current)is returned i.e., the leaf nodes.The fix is to simply do what it says it should do i.e.: