[Mlir-commits] [mlir] [MLIR][Presburger] Fix simplify() of IntegerRelation (PR #181469)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Sat Feb 14 02:44:05 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir-presburger
@llvm/pr-subscribers-mlir
Author: Yue Huang (AdUhTkJm)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/181469.diff
2 Files Affected:
- (modified) mlir/lib/Analysis/Presburger/IntegerRelation.cpp (-5)
- (modified) mlir/unittests/Analysis/Presburger/IntegerRelationTest.cpp (+21)
``````````diff
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());
``````````
</details>
https://github.com/llvm/llvm-project/pull/181469
More information about the Mlir-commits
mailing list