Skip to content

Commit 4aeb2a5

Browse files
committed
[MLIR][Presburger][Simplex] addSymbolicCut: don't add symbol div if denom is 1
This is unncessary, so we remove it as an optimization. Reviewed By: Groverkss Differential Revision: https://reviews.llvm.org/D123540
1 parent bb1a1f4 commit 4aeb2a5

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

mlir/lib/Analysis/Presburger/Simplex.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -357,8 +357,8 @@ bool SymbolicLexSimplex::isSymbolicSampleIntegral(unsigned row) const {
357357
isRangeDivisibleBy(tableau.getRow(row).slice(3, nSymbol), denom);
358358
}
359359

360-
/// This proceeds similarly to LexSimplex::addCut(). We are given a row that has
361-
/// a symbolic sample value with fractional coefficients.
360+
/// This proceeds similarly to LexSimplexBase::addCut(). We are given a row that
361+
/// has a symbolic sample value with fractional coefficients.
362362
///
363363
/// Let the row be
364364
/// (c + coeffM*M + sum_i a_i*s_i + sum_j b_j*y_j)/d,
@@ -374,10 +374,11 @@ bool SymbolicLexSimplex::isSymbolicSampleIntegral(unsigned row) const {
374374
/// sum_i (b_i%d)y_i = ((-c%d) + sum_i (-a_i%d)s_i)%d + k*d for some integer k
375375
///
376376
/// where we take a modulo of the whole symbolic expression on the right to
377-
/// bring it into the range [0, d - 1]. Therefore, as in LexSimplex::addCut,
377+
/// bring it into the range [0, d - 1]. Therefore, as in addCut(),
378378
/// k is the quotient on dividing the LHS by d, and since LHS >= 0, we have
379-
/// k >= 0 as well. We realize the modulo of the symbolic expression by adding a
380-
/// division variable
379+
/// k >= 0 as well. If all the a_i are divisible by d, then we can add the
380+
/// constraint directly. Otherwise, we realize the modulo of the symbolic
381+
/// expression by adding a division variable
381382
///
382383
/// q = ((-c%d) + sum_i (-a_i%d)s_i)/d
383384
///
@@ -392,16 +393,22 @@ bool SymbolicLexSimplex::isSymbolicSampleIntegral(unsigned row) const {
392393
LogicalResult SymbolicLexSimplex::addSymbolicCut(unsigned row) {
393394
int64_t d = tableau(row, 0);
394395

395-
// Add the division variable `q` described above to the symbol domain.
396-
// q = ((-c%d) + sum_i (-a_i%d)s_i)/d.
396+
// Construct the division variable `q = ((-c%d) + sum_i (-a_i%d)s_i)/d`.
397397
SmallVector<int64_t, 8> divCoeffs;
398398
divCoeffs.reserve(nSymbol + 1);
399399
int64_t divDenom = d;
400400
for (unsigned col = 3; col < 3 + nSymbol; ++col)
401401
divCoeffs.push_back(mod(-tableau(row, col), divDenom)); // (-a_i%d)s_i
402402
divCoeffs.push_back(mod(-tableau(row, 1), divDenom)); // -c%d.
403-
404403
normalizeDiv(divCoeffs, divDenom);
404+
405+
if (divDenom == 1) {
406+
// The symbolic sample numerator is divisible by the denominator,
407+
// so the division isn't needed. We can add the constraint directly,
408+
// i.e., ignore the symbols and add a regular cut as in addCut().
409+
return addCut(row);
410+
}
411+
405412
domainSimplex.addDivisionVariable(divCoeffs, divDenom);
406413
domainPoly.addLocalFloorDiv(divCoeffs, divDenom);
407414

0 commit comments

Comments
 (0)