Skip to content

Commit

Permalink
[MLIR][Presburger] getDivRepr: fix bug where dividend was negated
Browse files Browse the repository at this point in the history
Also updated the tests, which were asserting the wrong behaviour.

Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D128735
  • Loading branch information
Superty committed Jun 28, 2022
1 parent 25f4608 commit e9fa186
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions mlir/lib/Analysis/Presburger/Utils.cpp
Expand Up @@ -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();
Expand Down
8 changes: 4 additions & 4 deletions mlir/unittests/Analysis/Presburger/IntegerPolyhedronTest.cpp
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit e9fa186

Please sign in to comment.