[Mlir-commits] [mlir] [MLIR][Presburger] Fix full dimension check (PR #175422)
Yue Huang
llvmlistbot at llvm.org
Sun Jan 11 01:39:50 PST 2026
https://github.com/AdUhTkJm created https://github.com/llvm/llvm-project/pull/175422
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`.
>From 937bb4cc59756f7e69e3a7e7ea91f0379f90a093 Mon Sep 17 00:00:00 2001
From: Yue Huang <yh548 at cam.ac.uk>
Date: Sun, 11 Jan 2026 17:34:53 +0800
Subject: [PATCH] [MLIR][Presburger] Fix full dimension check
---
mlir/lib/Analysis/Presburger/IntegerRelation.cpp | 8 ++++++--
.../unittests/Analysis/Presburger/IntegerRelationTest.cpp | 8 ++++++++
2 files changed, 14 insertions(+), 2 deletions(-)
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());
+}
More information about the Mlir-commits
mailing list