[MLIR][Presburger] IntegerRelation::truncate: fix bug when truncating equalities
authorArjun P <arjunpitchanathan@gmail.com>
Thu, 31 Mar 2022 13:43:44 +0000 (14:43 +0100)
committerArjun P <arjunpitchanathan@gmail.com>
Thu, 31 Mar 2022 14:16:30 +0000 (15:16 +0100)
This was truncating inequalities instead of equalities.

Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D122811

mlir/lib/Analysis/Presburger/IntegerRelation.cpp
mlir/unittests/Analysis/Presburger/IntegerPolyhedronTest.cpp

index 50ced2a..de95511 100644 (file)
@@ -142,7 +142,7 @@ void IntegerRelation::truncate(const CountsSnapshot &counts) {
   truncateIdKind(IdKind::Symbol, counts);
   truncateIdKind(IdKind::Local, counts);
   removeInequalityRange(counts.getNumIneqs(), getNumInequalities());
-  removeInequalityRange(counts.getNumEqs(), getNumEqualities());
+  removeEqualityRange(counts.getNumEqs(), getNumEqualities());
 }
 
 unsigned IntegerRelation::insertId(IdKind kind, unsigned pos, unsigned num) {
index e7bbac3..4d55036 100644 (file)
@@ -1202,3 +1202,13 @@ TEST(IntegerPolyhedronTest, containsPointNoLocal) {
   EXPECT_TRUE(poly3.containsPointNoLocal({0, 0}));
   EXPECT_FALSE(poly3.containsPointNoLocal({1, 0}));
 }
+
+TEST(IntegerPolyhedronTest, truncateEqualityRegressionTest) {
+  // IntegerRelation::truncate was truncating inequalities to the number of
+  // equalities.
+  IntegerRelation set(1);
+  IntegerRelation::CountsSnapshot snapshot = set.getCounts();
+  set.addEquality({1, 0});
+  set.truncate(snapshot);
+  EXPECT_EQ(set.getNumEqualities(), 0u);
+}