[Mlir-commits] [mlir] ac2333f - [mlir][Presburger] NFC: factor out removeRedundantConstraintsFromSimplex (#235955)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Mon Nov 2 19:10:40 PST 2026
Author: Jeremy Kun
Date: 2026-11-02T19:10:32-08:00
New Revision: ac2333f7dc116ca8be1a5dbe56741ba3243b9d5c
URL: https://github.com/llvm/llvm-project/commit/ac2333f7dc116ca8be1a5dbe56741ba3243b9d5c
DIFF: https://github.com/llvm/llvm-project/commit/ac2333f7dc116ca8be1a5dbe56741ba3243b9d5c.diff
LOG: [mlir][Presburger] NFC: factor out removeRedundantConstraintsFromSimplex (#235955)
Split the compaction loops of
IntegerRelation::removeRedundantConstraints
into a new protected helper, removeRedundantConstraintsFromSimplex,
which
removes the constraints of the relation that are marked redundant in a
given Simplex, where the relation's constraints start at a given offset
in the Simplex (inequalities first, then each equality as a pair).
This allows reusing the same compaction logic when the relation's
constraints have been added to a Simplex that already contains other
constraints, e.g., for context-based simplification (gist), where the
context's constraints come first and are never marked redundant.
---
<sub>Stack created with <a
href="https://github.com/github/gh-stack">GitHub Stacks CLI</a> • <a
href="https://gh.io/stacks-feedback">Give Feedback 💬</a></sub>
---------
Co-authored-by: Siddharth <siddu.druid at gmail.com>
Added:
Modified:
mlir/include/mlir/Analysis/Presburger/IntegerRelation.h
mlir/lib/Analysis/Presburger/IntegerRelation.cpp
Removed:
################################################################################
diff --git a/mlir/include/mlir/Analysis/Presburger/IntegerRelation.h b/mlir/include/mlir/Analysis/Presburger/IntegerRelation.h
index f79152f46ca73a..2d995e24b8afec 100644
--- a/mlir/include/mlir/Analysis/Presburger/IntegerRelation.h
+++ b/mlir/include/mlir/Analysis/Presburger/IntegerRelation.h
@@ -38,6 +38,7 @@ class IntegerRelation;
class IntegerPolyhedron;
class PresburgerSet;
class PresburgerRelation;
+class Simplex;
struct SymbolicLexOpt;
/// The type of bound: equal, lower bound or upper bound.
@@ -925,6 +926,18 @@ class IntegerRelation {
/// Returns whether the constraint system was modified.
bool removeDuplicateConstraints();
+ /// Removes the constraints of `this` that have been marked redundant in
+ /// `simplex` (see `Simplex::detectRedundant`). The constraints of `this`
+ /// must be in the `simplex` starting at constraint index `offset`,
+ /// and in the same order as `SimplexBase::intersectIntegerRelation`.
+ /// That is, inequality `i` corresponds to simplex constraint `offset + i`,
+ /// and equality `j` corresponds to the pair of simplex constraints
+ /// `offset + numIneqs + 2 * j` , and `offset + numIneqs + 2 * j + 1`.
+ /// An equality is removed only if both constraints of its pair are marked
+ /// redundant.
+ void removeRedundantConstraintsFromSimplex(const Simplex &simplex,
+ unsigned offset);
+
/// Returns false if the fields corresponding to various variable counts, or
/// equality/inequality buffer sizes aren't consistent; true otherwise. This
/// is meant to be used within an assert internally.
diff --git a/mlir/lib/Analysis/Presburger/IntegerRelation.cpp b/mlir/lib/Analysis/Presburger/IntegerRelation.cpp
index e76e2ead02e64c..88012b846133c2 100644
--- a/mlir/lib/Analysis/Presburger/IntegerRelation.cpp
+++ b/mlir/lib/Analysis/Presburger/IntegerRelation.cpp
@@ -1231,13 +1231,21 @@ void IntegerRelation::removeRedundantConstraints() {
gcdTightenInequalities();
Simplex simplex(*this);
simplex.detectRedundant();
+ removeRedundantConstraintsFromSimplex(simplex, /*offset=*/0);
+}
- unsigned pos = 0;
+void IntegerRelation::removeRedundantConstraintsFromSimplex(
+ const Simplex &simplex, unsigned offset) {
unsigned numIneqs = getNumInequalities();
+ assert(offset + numIneqs + 2 * getNumEqualities() <=
+ simplex.getNumConstraints() &&
+ "simplex does not contain all constraints of this relation");
+
+ unsigned pos = 0;
// Scan to get rid of all inequalities marked redundant, in-place. In Simplex,
// the first constraints added are the inequalities.
for (unsigned r = 0; r < numIneqs; r++) {
- if (!simplex.isMarkedRedundant(r))
+ if (!simplex.isMarkedRedundant(offset + r))
inequalities.copyRow(r, pos++);
}
inequalities.resizeVertically(pos);
@@ -1248,8 +1256,8 @@ void IntegerRelation::removeRedundantConstraints() {
// redundant.
pos = 0;
for (unsigned r = 0, e = getNumEqualities(); r < e; r++) {
- if (!(simplex.isMarkedRedundant(numIneqs + 2 * r) &&
- simplex.isMarkedRedundant(numIneqs + 2 * r + 1)))
+ if (!(simplex.isMarkedRedundant(offset + numIneqs + 2 * r) &&
+ simplex.isMarkedRedundant(offset + numIneqs + 2 * r + 1)))
equalities.copyRow(r, pos++);
}
equalities.resizeVertically(pos);
More information about the Mlir-commits
mailing list