diff --git a/mlir/lib/Analysis/Presburger/Utils.cpp b/mlir/lib/Analysis/Presburger/Utils.cpp --- a/mlir/lib/Analysis/Presburger/Utils.cpp +++ b/mlir/lib/Analysis/Presburger/Utils.cpp @@ -45,7 +45,7 @@ // 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; } diff --git a/mlir/unittests/Analysis/Presburger/IntegerPolyhedronTest.cpp b/mlir/unittests/Analysis/Presburger/IntegerPolyhedronTest.cpp --- a/mlir/unittests/Analysis/Presburger/IntegerPolyhedronTest.cpp +++ b/mlir/unittests/Analysis/Presburger/IntegerPolyhedronTest.cpp @@ -794,6 +794,21 @@ 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> divisions = {{-1, 0, -1}}; + SmallVector denoms = {2}; + checkDivisionRepresentation(poly, divisions, denoms); +} + TEST(IntegerPolyhedronTest, simplifyLocalsTest) { // (x) : (exists y: 2x + y = 1 and y = 2). IntegerPolyhedron poly(1, 0, 1);