-
Notifications
You must be signed in to change notification settings - Fork 15.5k
[MLIR][Conversion] PDLToPDLInterp: Don't shadow maximum depth position when creating constraint position. #162265
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
base: main
Are you sure you want to change the base?
Conversation
|
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
|
Ping |
|
@llvm/pr-subscribers-mlir Author: None (jumerckx) Changes
// Push the constraint to the furthest position.
Position *pos = *llvm::max_element(allPositions, comparePosDepth);
ResultRange results = op.getResults();
PredicateBuilder::Predicate pred = builder.getConstraint(
op.getName(), allPositions, SmallVector<Type>(results.getTypes()),
op.getIsNegated());
// For each result register a position so it can be used later
for (auto [i, result] : llvm::enumerate(results)) {
ConstraintQuestion *q = cast<ConstraintQuestion>(pred.first);
ConstraintPosition *pos = builder.getConstraintPosition(q, i);
auto [it, inserted] = inputs.try_emplace(result, pos);
// If this is an input value that has been visited in the tree, add a
// constraint to ensure that both instances refer to the same value.
if (!inserted) {
Position *first = pos;
Position *second = it->second;
if (comparePosDepth(second, first))
std::tie(second, first) = std::make_pair(first, second);
predList.emplace_back(second, builder.getEqualTo(first));
}
I believe this is not the intended behavior since This pr makes it such that the original Full diff: https://github.com/llvm/llvm-project/pull/162265.diff 1 Files Affected:
diff --git a/mlir/lib/Conversion/PDLToPDLInterp/PredicateTree.cpp b/mlir/lib/Conversion/PDLToPDLInterp/PredicateTree.cpp
index 39d4815dc73b7..e95a178c030d4 100644
--- a/mlir/lib/Conversion/PDLToPDLInterp/PredicateTree.cpp
+++ b/mlir/lib/Conversion/PDLToPDLInterp/PredicateTree.cpp
@@ -279,14 +279,14 @@ static void getConstraintPredicates(pdl::ApplyNativeConstraintOp op,
// For each result register a position so it can be used later
for (auto [i, result] : llvm::enumerate(results)) {
ConstraintQuestion *q = cast<ConstraintQuestion>(pred.first);
- ConstraintPosition *pos = builder.getConstraintPosition(q, i);
- auto [it, inserted] = inputs.try_emplace(result, pos);
+ ConstraintPosition *constraintPos = builder.getConstraintPosition(q, i);
+ auto [it, inserted] = inputs.try_emplace(result, constraintPos);
// If this is an input value that has been visited in the tree, add a
// constraint to ensure that both instances refer to the same value.
if (!inserted) {
- Position *first = pos;
+ Position *first = constraintPos;
Position *second = it->second;
- if (comparePosDepth(second, first))
+ if (comparePosDepth(second, pos))
std::tie(second, first) = std::make_pair(first, second);
predList.emplace_back(second, builder.getEqualTo(first));
|
getConstraintPredicatesgenerates an EqualToConstraint if a constraint result is used elsewhere. There is logic that decides at which position this should occur:comparePosDepth(second, first)I believe this is not the intended behavior since
posat this point is a ConstraintPosition. This means that, whencomparePosDepthis later called, the depth will always be zero.This pr makes it such that the original
posdefined above is not shadowed by the new one. And the depth comparison is not made with the NativeConstraint's result position, but the deepest position of the operands of the NativeConstraint. I believe this is the intended behavior because this way the position of the "deepest" operand to the native constraint will be considered.