[Mlir-commits] [mlir] [MLIR][Presburger] Fix bug in Identifier::isEqual assert (PR #76380)
Bharathi Ramana Joshi
llvmlistbot at llvm.org
Mon Dec 25 20:56:05 PST 2023
https://github.com/iambrj created https://github.com/llvm/llvm-project/pull/76380
Make identifiers::isEqual return false instead of failing assertion when identifiers are not equal.
>From 20499665c72c89e395e2b795e0aa118232989ff0 Mon Sep 17 00:00:00 2001
From: iambrj <joshibharathiramana at gmail.com>
Date: Tue, 26 Dec 2023 10:16:46 +0530
Subject: [PATCH] [MLIR][Presburger] Fix bug in Identifier::isEqual assert
Make identifiers::isEqual return false instead of failing assertion when
identifiers are not equal.
---
mlir/lib/Analysis/Presburger/PresburgerSpace.cpp | 5 +++--
.../Analysis/Presburger/PresburgerSpaceTest.cpp | 14 ++++++++++++++
2 files changed, 17 insertions(+), 2 deletions(-)
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();
More information about the Mlir-commits
mailing list