Skip to content

Commit

Permalink
[MLIR][Presburger] normalizeDivisionByGCD: fix bug when constant term…
Browse files Browse the repository at this point in the history
… is negative

Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D119531
  • Loading branch information
Superty committed Feb 11, 2022
1 parent 8f1350e commit 855cd84
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion mlir/lib/Analysis/Presburger/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ static void normalizeDivisionByGCD(SmallVectorImpl<int64_t> &dividend,

// Normalize the dividend and the denominator.
std::transform(dividend.begin(), dividend.end(), dividend.begin(),
[gcd](int64_t &n) { return floor((double)(n / gcd)); });
[gcd](int64_t &n) { return floorDiv(n, gcd); });
divisor /= gcd;
}

Expand Down
15 changes: 15 additions & 0 deletions mlir/unittests/Analysis/Presburger/IntegerPolyhedronTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,21 @@ TEST(IntegerPolyhedronTest, computeLocalReprNoRepr) {
checkDivisionRepresentation(poly, divisions, denoms);
}

TEST(IntegerPolyhedronTest, computeLocalReprNegConstNormalize) {
MLIRContext context;
IntegerPolyhedron poly = parsePoly(
"(x, q) : (-1 - 3*x - 6 * q >= 0, 6 + 3*x + 6*q >= 0)", &context);
// Convert q to a local variable.
poly.convertDimToLocal(1, 2);

// q = floor((-1/3 - x)/2)
// = floor((1/3) + (-1 - x)/2)
// = floor((-1 - x)/2).
std::vector<SmallVector<int64_t, 8>> divisions = {{-1, 0, -1}};
SmallVector<unsigned, 8> denoms = {2};
checkDivisionRepresentation(poly, divisions, denoms);
}

TEST(IntegerPolyhedronTest, simplifyLocalsTest) {
// (x) : (exists y: 2x + y = 1 and y = 2).
IntegerPolyhedron poly(1, 0, 1);
Expand Down

0 comments on commit 855cd84

Please sign in to comment.