Skip to content

Commit 69c1a35

Browse files
committed
[MLIR][Presburger][Simplex] moveRowUnknownToColumn: support the row sample value being zero
When the sample value is zero, everything is the same except that failure to pivot does not imply emptiness. So, leave it to the user to mark as empty if necessary, if they know the sample value is strictly negative. This is needed for an upcoming symbolic lexmin heuristic. Reviewed By: Groverkss Differential Revision: https://reviews.llvm.org/D123604
1 parent 0df963e commit 69c1a35

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

mlir/include/mlir/Analysis/Presburger/Simplex.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -440,10 +440,9 @@ class LexSimplexBase : public SimplexBase {
440440
void appendSymbol();
441441

442442
/// Try to move the specified row to column orientation while preserving the
443-
/// lexicopositivity of the basis transform. The row must have a negative
444-
/// sample value. If this is not possible, return failure. This only occurs
445-
/// when the constraints have no solution; the tableau will be marked empty in
446-
/// such a case.
443+
/// lexicopositivity of the basis transform. The row must have a non-positive
444+
/// sample value. If this is not possible, return failure. This occurs when
445+
/// the constraints have no solution or the sample value is zero.
447446
LogicalResult moveRowUnknownToColumn(unsigned row);
448447

449448
/// Given a row that has a non-integer sample value, add an inequality to cut

mlir/lib/Analysis/Presburger/Simplex.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,10 @@ Direction flippedDirection(Direction direction) {
212212
/// add these to the set of ignored columns and continue to the next row. If we
213213
/// run out of rows, then A*y is zero and we are done.
214214
MaybeOptimum<SmallVector<Fraction, 8>> LexSimplex::findRationalLexMin() {
215-
if (restoreRationalConsistency().failed())
215+
if (restoreRationalConsistency().failed()) {
216+
markEmpty();
216217
return OptimumKind::Empty;
218+
}
217219
return getRationalSample();
218220
}
219221

@@ -679,16 +681,16 @@ LogicalResult LexSimplex::restoreRationalConsistency() {
679681
}
680682

681683
// Move the row unknown to column orientation while preserving lexicopositivity
682-
// of the basis transform. The sample value of the row must be negative.
684+
// of the basis transform. The sample value of the row must be non-positive.
683685
//
684686
// We only consider pivots where the pivot element is positive. Suppose no such
685687
// pivot exists, i.e., some violated row has no positive coefficient for any
686688
// basis unknown. The row can be represented as (s + c_1*u_1 + ... + c_n*u_n)/d,
687689
// where d is the denominator, s is the sample value and the c_i are the basis
688-
// coefficients. Since any feasible assignment of the basis satisfies u_i >= 0
689-
// for all i, and we have s < 0 as well as c_i < 0 for all i, any feasible
690-
// assignment would violate this row and therefore the constraints have no
691-
// solution.
690+
// coefficients. If s != 0, then since any feasible assignment of the basis
691+
// satisfies u_i >= 0 for all i, and we have s < 0 as well as c_i < 0 for all i,
692+
// any feasible assignment would violate this row and therefore the constraints
693+
// have no solution.
692694
//
693695
// We can preserve lexicopositivity by picking the pivot column with positive
694696
// pivot element that makes the lexicographically smallest change to the sample
@@ -726,10 +728,10 @@ LogicalResult LexSimplex::restoreRationalConsistency() {
726728
// B'.col(k) = B.col(k) - B(i,k) * B.col(j) / B(i,j) for k != j
727729
// and similarly, s' = s - s_i * B.col(j) / B(i,j).
728730
//
729-
// Since the row is violated, we have s_i < 0, so the change in sample value
730-
// when pivoting with column a is lexicographically smaller than that when
731-
// pivoting with column b iff B.col(a) / B(i, a) is lexicographically smaller
732-
// than B.col(b) / B(i, b).
731+
// If s_i == 0, then the sample value remains unchanged. Otherwise, if s_i < 0,
732+
// the change in sample value when pivoting with column a is lexicographically
733+
// smaller than that when pivoting with column b iff B.col(a) / B(i, a) is
734+
// lexicographically smaller than B.col(b) / B(i, b).
733735
//
734736
// Since B(i, j) > 0, column j remains lexicopositive.
735737
//
@@ -749,10 +751,8 @@ LogicalResult LexSimplexBase::moveRowUnknownToColumn(unsigned row) {
749751
!maybeColumn ? col : getLexMinPivotColumn(row, *maybeColumn, col);
750752
}
751753

752-
if (!maybeColumn) {
753-
markEmpty();
754+
if (!maybeColumn)
754755
return failure();
755-
}
756756

757757
pivot(row, *maybeColumn);
758758
return success();

0 commit comments

Comments
 (0)