-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[MLIR][Presburger] Fix bug in Identifier::isEqual assert #76380
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
Make identifiers::isEqual return false instead of failing assertion when identifiers are not equal.
@llvm/pr-subscribers-mlir Author: Bharathi Ramana Joshi (iambrj) ChangesMake identifiers::isEqual return false instead of failing assertion when identifiers are not equal. Full diff: https://github.com/llvm/llvm-project/pull/76380.diff 2 Files Affected:
diff --git a/mlir/lib/Analysis/Presburger/PresburgerSpace.cpp b/mlir/lib/Analysis/Presburger/PresburgerSpace.cpp
index cf1b3befbc89f8..185da462aa4453 100644
--- a/mlir/lib/Analysis/Presburger/PresburgerSpace.cpp
+++ b/mlir/lib/Analysis/Presburger/PresburgerSpace.cpp
@@ -18,8 +18,9 @@ using namespace presburger;
bool Identifier::isEqual(const Identifier &other) const {
if (value == nullptr || other.value == nullptr)
return false;
- assert(value == other.value && idType == other.idType &&
- "Values of Identifiers are equal but their types do not match.");
+ assert(value != other.value ||
+ (value == other.value && idType == other.idType &&
+ "Values of Identifiers are equal but their types do not match."));
return value == other.value;
}
diff --git a/mlir/unittests/Analysis/Presburger/PresburgerSpaceTest.cpp b/mlir/unittests/Analysis/Presburger/PresburgerSpaceTest.cpp
index dd06d462f54bee..8229199b233471 100644
--- a/mlir/unittests/Analysis/Presburger/PresburgerSpaceTest.cpp
+++ b/mlir/unittests/Analysis/Presburger/PresburgerSpaceTest.cpp
@@ -110,6 +110,20 @@ TEST(PresburgerSpaceTest, removeVarRangeIdentifier) {
EXPECT_EQ(space.getId(VarKind::Range, 1), Identifier(&identifiers[5]));
}
+TEST(PresburgerSpaceTest, IdentifierIsEqual) {
+ PresburgerSpace space = PresburgerSpace::getRelationSpace(1, 2, 0, 0);
+ space.resetIds();
+
+ int identifiers[2] = {0, 1};
+ space.getId(VarKind::Domain, 0) = Identifier(&identifiers[0]);
+ space.getId(VarKind::Range, 0) = Identifier(&identifiers[0]);
+ space.getId(VarKind::Range, 1) = Identifier(&identifiers[1]);
+
+ EXPECT_EQ(space.getId(VarKind::Domain, 0), space.getId(VarKind::Range, 0));
+ EXPECT_FALSE(
+ space.getId(VarKind::Range, 0).isEqual(space.getId(VarKind::Range, 1)));
+}
+
TEST(PresburgerSpaceTest, convertVarKind) {
PresburgerSpace space = PresburgerSpace::getRelationSpace(2, 2, 0, 0);
space.resetIds();
|
@llvm/pr-subscribers-mlir-presburger Author: Bharathi Ramana Joshi (iambrj) ChangesMake identifiers::isEqual return false instead of failing assertion when identifiers are not equal. Full diff: https://github.com/llvm/llvm-project/pull/76380.diff 2 Files Affected:
diff --git a/mlir/lib/Analysis/Presburger/PresburgerSpace.cpp b/mlir/lib/Analysis/Presburger/PresburgerSpace.cpp
index cf1b3befbc89f8..185da462aa4453 100644
--- a/mlir/lib/Analysis/Presburger/PresburgerSpace.cpp
+++ b/mlir/lib/Analysis/Presburger/PresburgerSpace.cpp
@@ -18,8 +18,9 @@ using namespace presburger;
bool Identifier::isEqual(const Identifier &other) const {
if (value == nullptr || other.value == nullptr)
return false;
- assert(value == other.value && idType == other.idType &&
- "Values of Identifiers are equal but their types do not match.");
+ assert(value != other.value ||
+ (value == other.value && idType == other.idType &&
+ "Values of Identifiers are equal but their types do not match."));
return value == other.value;
}
diff --git a/mlir/unittests/Analysis/Presburger/PresburgerSpaceTest.cpp b/mlir/unittests/Analysis/Presburger/PresburgerSpaceTest.cpp
index dd06d462f54bee..8229199b233471 100644
--- a/mlir/unittests/Analysis/Presburger/PresburgerSpaceTest.cpp
+++ b/mlir/unittests/Analysis/Presburger/PresburgerSpaceTest.cpp
@@ -110,6 +110,20 @@ TEST(PresburgerSpaceTest, removeVarRangeIdentifier) {
EXPECT_EQ(space.getId(VarKind::Range, 1), Identifier(&identifiers[5]));
}
+TEST(PresburgerSpaceTest, IdentifierIsEqual) {
+ PresburgerSpace space = PresburgerSpace::getRelationSpace(1, 2, 0, 0);
+ space.resetIds();
+
+ int identifiers[2] = {0, 1};
+ space.getId(VarKind::Domain, 0) = Identifier(&identifiers[0]);
+ space.getId(VarKind::Range, 0) = Identifier(&identifiers[0]);
+ space.getId(VarKind::Range, 1) = Identifier(&identifiers[1]);
+
+ EXPECT_EQ(space.getId(VarKind::Domain, 0), space.getId(VarKind::Range, 0));
+ EXPECT_FALSE(
+ space.getId(VarKind::Range, 0).isEqual(space.getId(VarKind::Range, 1)));
+}
+
TEST(PresburgerSpaceTest, convertVarKind) {
PresburgerSpace space = PresburgerSpace::getRelationSpace(2, 2, 0, 0);
space.resetIds();
|
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
Make identifiers::isEqual return false instead of failing assertion when identifiers are not equal.