[Mlir-commits] [mlir] 855cd84 - [MLIR][Presburger] normalizeDivisionByGCD: fix bug when constant term is negative
Arjun P
llvmlistbot at llvm.org
Fri Feb 11 03:32:56 PST 2022
Author: Arjun P
Date: 2022-02-11T17:02:52+05:30
New Revision: 855cd847f7f54e7f05bbac94e386aee0d434f685
URL: https://github.com/llvm/llvm-project/commit/855cd847f7f54e7f05bbac94e386aee0d434f685
DIFF: https://github.com/llvm/llvm-project/commit/855cd847f7f54e7f05bbac94e386aee0d434f685.diff
LOG: [MLIR][Presburger] normalizeDivisionByGCD: fix bug when constant term is negative
Reviewed By: Groverkss
Differential Revision: https://reviews.llvm.org/D119531
Added:
Modified:
mlir/lib/Analysis/Presburger/Utils.cpp
mlir/unittests/Analysis/Presburger/IntegerPolyhedronTest.cpp
Removed:
################################################################################
diff --git a/mlir/lib/Analysis/Presburger/Utils.cpp b/mlir/lib/Analysis/Presburger/Utils.cpp
index 48db035268fa6..c6f377acfa608 100644
--- a/mlir/lib/Analysis/Presburger/Utils.cpp
+++ b/mlir/lib/Analysis/Presburger/Utils.cpp
@@ -45,7 +45,7 @@ static void normalizeDivisionByGCD(SmallVectorImpl<int64_t> ÷nd,
// 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
index d2d0df080633d..d3c40237c692d 100644
--- a/mlir/unittests/Analysis/Presburger/IntegerPolyhedronTest.cpp
+++ b/mlir/unittests/Analysis/Presburger/IntegerPolyhedronTest.cpp
@@ -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);
More information about the Mlir-commits
mailing list