[Mlir-commits] [mlir] e9fa186 - [MLIR][Presburger] getDivRepr: fix bug where dividend was negated

Arjun P llvmlistbot at llvm.org
Tue Jun 28 08:43:27 PDT 2022


Author: Arjun P
Date: 2022-06-28T16:43:32+01:00
New Revision: e9fa18637d6f9d1d40ff1cb48f802d6da23b3b8e

URL: https://github.com/llvm/llvm-project/commit/e9fa18637d6f9d1d40ff1cb48f802d6da23b3b8e
DIFF: https://github.com/llvm/llvm-project/commit/e9fa18637d6f9d1d40ff1cb48f802d6da23b3b8e.diff

LOG: [MLIR][Presburger] getDivRepr: fix bug where dividend was negated

Also updated the tests, which were asserting the wrong behaviour.

Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D128735

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 c6ed7b254621e..2ada5051aa073 100644
--- a/mlir/lib/Analysis/Presburger/Utils.cpp
+++ b/mlir/lib/Analysis/Presburger/Utils.cpp
@@ -172,9 +172,9 @@ static LogicalResult getDivRepr(const IntegerRelation &cst, unsigned pos,
   expr.resize(cst.getNumCols(), 0);
   for (unsigned i = 0, e = cst.getNumIds(); i < e; ++i)
     if (i != pos)
-      expr[i] = signDiv * cst.atEq(eqInd, i);
+      expr[i] = -signDiv * cst.atEq(eqInd, i);
 
-  expr.back() = signDiv * cst.atEq(eqInd, cst.getNumCols() - 1);
+  expr.back() = -signDiv * cst.atEq(eqInd, cst.getNumCols() - 1);
   normalizeDivisionByGCD(expr, divisor);
 
   return success();

diff  --git a/mlir/unittests/Analysis/Presburger/IntegerPolyhedronTest.cpp b/mlir/unittests/Analysis/Presburger/IntegerPolyhedronTest.cpp
index f69b4ee7a6e7f..4364cc8b70380 100644
--- a/mlir/unittests/Analysis/Presburger/IntegerPolyhedronTest.cpp
+++ b/mlir/unittests/Analysis/Presburger/IntegerPolyhedronTest.cpp
@@ -725,7 +725,7 @@ TEST(IntegerPolyhedronTest, computeLocalReprFromEquality) {
     // Convert `q` to a local variable.
     poly.convertToLocal(IdKind::SetDim, 2, 3);
 
-    std::vector<SmallVector<int64_t, 8>> divisions = {{-1, -1, 0, 0}};
+    std::vector<SmallVector<int64_t, 8>> divisions = {{1, 1, 0, 0}};
     SmallVector<unsigned, 8> denoms = {4};
 
     checkDivisionRepresentation(poly, divisions, denoms);
@@ -735,7 +735,7 @@ TEST(IntegerPolyhedronTest, computeLocalReprFromEquality) {
     // Convert `q` to a local variable.
     poly.convertToLocal(IdKind::SetDim, 2, 3);
 
-    std::vector<SmallVector<int64_t, 8>> divisions = {{-1, -1, 0, 0}};
+    std::vector<SmallVector<int64_t, 8>> divisions = {{1, 1, 0, 0}};
     SmallVector<unsigned, 8> denoms = {4};
 
     checkDivisionRepresentation(poly, divisions, denoms);
@@ -745,7 +745,7 @@ TEST(IntegerPolyhedronTest, computeLocalReprFromEquality) {
     // Convert `q` to a local variable.
     poly.convertToLocal(IdKind::SetDim, 2, 3);
 
-    std::vector<SmallVector<int64_t, 8>> divisions = {{1, 1, 0, -2}};
+    std::vector<SmallVector<int64_t, 8>> divisions = {{-1, -1, 0, 2}};
     SmallVector<unsigned, 8> denoms = {3};
 
     checkDivisionRepresentation(poly, divisions, denoms);
@@ -761,7 +761,7 @@ TEST(IntegerPolyhedronTest, computeLocalReprFromEqualityAndInequality) {
     poly.convertToLocal(IdKind::SetDim, 2, 4);
 
     std::vector<SmallVector<int64_t, 8>> divisions = {{1, 1, 0, 0, 1},
-                                                      {-1, -1, 0, 0, 0}};
+                                                      {1, 1, 0, 0, 0}};
     SmallVector<unsigned, 8> denoms = {4, 3};
 
     checkDivisionRepresentation(poly, divisions, denoms);


        


More information about the Mlir-commits mailing list