[Mlir-commits] [mlir] [MLIR][Presburger] Fix full dimension check (PR #175422)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Sun Jan 11 01:40:24 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir-presburger
Author: Yue Huang (AdUhTkJm)
<details>
<summary>Changes</summary>
Currently, the code mistakenly thinks `(x): (1 >= 0)` as non-full-dimensional.
The code determines full-dimensionality by testing whether an inequality is flat, i.e. takes the same value regardless of variable assignments. However, `1 >= 0` is obviously flat, and this case should be ignored since it didn't involve any variables.
To remove these inequalities, we can call `removeTrivialRedundancy`.
---
Full diff: https://github.com/llvm/llvm-project/pull/175422.diff
2 Files Affected:
- (modified) mlir/lib/Analysis/Presburger/IntegerRelation.cpp (+6-2)
- (modified) mlir/unittests/Analysis/Presburger/IntegerRelationTest.cpp (+8)
``````````diff
diff --git a/mlir/lib/Analysis/Presburger/IntegerRelation.cpp b/mlir/lib/Analysis/Presburger/IntegerRelation.cpp
index 26197ce7da374..34531d1284b69 100644
--- a/mlir/lib/Analysis/Presburger/IntegerRelation.cpp
+++ b/mlir/lib/Analysis/Presburger/IntegerRelation.cpp
@@ -2643,8 +2643,12 @@ bool IntegerRelation::isFullDim() {
if (getNumEqualities() > 0)
return false;
- // The polytope is full-dimensional iff it is not flat along any of the
- // inequality directions.
+ // The polytope is full-dimensional iff it is not flat along every
+ // inequality directions that involve at least one variable.
+ //
+ // To check this, we first remove inequalities involving no variables,
+ // which is done in the following function.
+ removeTrivialRedundancy();
Simplex simplex(*this);
return llvm::none_of(llvm::seq<int>(getNumInequalities()), [&](int i) {
return simplex.isFlatAlong(getInequality(i));
diff --git a/mlir/unittests/Analysis/Presburger/IntegerRelationTest.cpp b/mlir/unittests/Analysis/Presburger/IntegerRelationTest.cpp
index 599db4cc74983..b94b86057b650 100644
--- a/mlir/unittests/Analysis/Presburger/IntegerRelationTest.cpp
+++ b/mlir/unittests/Analysis/Presburger/IntegerRelationTest.cpp
@@ -740,3 +740,11 @@ TEST(IntegerRelationTest, simplify) {
// It can be obtained from 2 times the first equality minus the second.
EXPECT_TRUE(rel.getNumEqualities() == 2);
}
+
+TEST(IntegerRelationTest, isFullDim) {
+ IntegerRelation rel = parseRelationFromSet("(x): (1 >= 0)", 1);
+ EXPECT_TRUE(rel.isFullDim());
+
+ rel = parseRelationFromSet("(x): (-1 >= 0)", 1);
+ EXPECT_FALSE(rel.isFullDim());
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/175422
More information about the Mlir-commits
mailing list