[Mlir-commits] [mlir] [MLIR][Presburger] Add simplify function (PR #69107)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Sat Oct 21 22:30:03 PDT 2023


================
@@ -2216,6 +2288,74 @@ IntegerPolyhedron IntegerRelation::getDomainSet() const {
   return IntegerPolyhedron(std::move(copyRel));
 }
 
+bool IntegerRelation::removeDuplicateConstraints() {
+  bool changed = false;
+  SmallDenseMap<ArrayRef<MPInt>, unsigned> hashTable;
+  unsigned ineqs = getNumInequalities(), cols = getNumCols();
+
+  if (ineqs <= 1)
+    return changed;
+
+  // Check only the non-constant part of the constraint is the same.
+  auto row = getInequality(0).drop_back();
+  hashTable.insert({row, 0});
+  for (unsigned k = 1; k < ineqs; ++k) {
+    auto nRow = getInequality(k).drop_back();
+    if (!hashTable.contains(nRow)) {
+      hashTable.insert({nRow, k});
+      continue;
+    }
+
+    // For identical cases, keep only the smaller part of the constant term.
+    unsigned l = hashTable[nRow];
+    changed = true;
+    if (atIneq(k, cols - 1) <= atIneq(l, cols - 1))
+      inequalities.swapRows(k, l);
+    removeInequality(k);
+    --k;
+    --ineqs;
+  }
+
+  // Check the neg form of each inequality, need an extra space to store it.
+  inequalities.appendExtraRow();
----------------
gilsaia wrote:

Now here an additional smallvector is used as temporary storage,and as for changing the hash function, since we need to take into account both positive and negative ineqs, I haven't found a good way to implement such a hash function

https://github.com/llvm/llvm-project/pull/69107


More information about the Mlir-commits mailing list