[Mlir-commits] [mlir] [MLIR][Presburger] Fix simplify() of IntegerRelation (PR #181469)

Yue Huang llvmlistbot at llvm.org
Sat Feb 14 02:43:32 PST 2026


https://github.com/AdUhTkJm created https://github.com/llvm/llvm-project/pull/181469

Actually, I'm not sure why doing Gaussian elimination for inequalities is incorrect.
It is not about `gcdTightenInequalities()`; when I remove it without removing the elimination of inequalities, it does not work. The test only passes when I remove them all.

>From 8251de8842aa72f88d7df4f670a1012c0430894d Mon Sep 17 00:00:00 2001
From: Yue Huang <yh548 at cam.ac.uk>
Date: Wed, 11 Feb 2026 16:35:13 +0000
Subject: [PATCH] [MLIR][Presburger] Fix simplify() of IntegerRelation

---
 .../Analysis/Presburger/IntegerRelation.cpp   |  5 -----
 .../Presburger/IntegerRelationTest.cpp        | 21 +++++++++++++++++++
 2 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/mlir/lib/Analysis/Presburger/IntegerRelation.cpp b/mlir/lib/Analysis/Presburger/IntegerRelation.cpp
index cf93fbd9a0dc7..1ef921d9f6b30 100644
--- a/mlir/lib/Analysis/Presburger/IntegerRelation.cpp
+++ b/mlir/lib/Analysis/Presburger/IntegerRelation.cpp
@@ -1161,11 +1161,6 @@ bool IntegerRelation::gaussianEliminate() {
       eliminateFromConstraint(this, i, *pivotRow, firstVar, 0, true);
       equalities.normalizeRow(i);
     }
-    for (unsigned i = 0, ineqs = getNumInequalities(); i < ineqs; ++i) {
-      eliminateFromConstraint(this, i, *pivotRow, firstVar, 0, false);
-      inequalities.normalizeRow(i);
-    }
-    gcdTightenInequalities();
 
     // The column is finished. Tell the next iteration to start at the next
     // column.
diff --git a/mlir/unittests/Analysis/Presburger/IntegerRelationTest.cpp b/mlir/unittests/Analysis/Presburger/IntegerRelationTest.cpp
index b94b86057b650..a1197466f0da1 100644
--- a/mlir/unittests/Analysis/Presburger/IntegerRelationTest.cpp
+++ b/mlir/unittests/Analysis/Presburger/IntegerRelationTest.cpp
@@ -741,6 +741,27 @@ TEST(IntegerRelationTest, simplify) {
   EXPECT_TRUE(rel.getNumEqualities() == 2);
 }
 
+TEST(IntegerRelationTest, simplify2) {
+  IntegerRelation rel(PresburgerSpace::getRelationSpace(0, 6));
+  rel.addEquality({-1, 0, 0, 0, 0, 3, 0});
+  rel.addEquality({0, 1, 0, -3, 0, 0, 0});
+  rel.addEquality({0, -1, 0, 0, 2, 0, 0});
+  rel.addInequality({0, 1, 0, 0, 0, 0, -6});
+  rel.addInequality({0, 0, 0, 0, 0, -1, 6});
+  rel.addInequality({0, 1, 0, -3, 0, 0, 0});
+  rel.addInequality({0, -1, 0, 3, 0, 0, 0});
+  rel.addInequality({0, -1, 3, 0, 0, 0, 2});
+  rel.addInequality({0, 1, -3, 0, 0, 0, 0});
+  rel.addInequality({0, 0, -1, 0, 0, 1, -1});
+  EXPECT_FALSE(rel.isIntegerEmpty());
+
+  auto simplified = rel;
+  simplified.simplify();
+  EXPECT_TRUE(rel.isEqual(simplified));
+  simplified.dump();
+  EXPECT_FALSE(simplified.isIntegerEmpty());
+}
+
 TEST(IntegerRelationTest, isFullDim) {
   IntegerRelation rel = parseRelationFromSet("(x): (1 >= 0)", 1);
   EXPECT_TRUE(rel.isFullDim());



More information about the Mlir-commits mailing list