Skip to content

Commit e9fa186

Browse files
committed
[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
1 parent 25f4608 commit e9fa186

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

mlir/lib/Analysis/Presburger/Utils.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,9 @@ static LogicalResult getDivRepr(const IntegerRelation &cst, unsigned pos,
172172
expr.resize(cst.getNumCols(), 0);
173173
for (unsigned i = 0, e = cst.getNumIds(); i < e; ++i)
174174
if (i != pos)
175-
expr[i] = signDiv * cst.atEq(eqInd, i);
175+
expr[i] = -signDiv * cst.atEq(eqInd, i);
176176

177-
expr.back() = signDiv * cst.atEq(eqInd, cst.getNumCols() - 1);
177+
expr.back() = -signDiv * cst.atEq(eqInd, cst.getNumCols() - 1);
178178
normalizeDivisionByGCD(expr, divisor);
179179

180180
return success();

mlir/unittests/Analysis/Presburger/IntegerPolyhedronTest.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,7 @@ TEST(IntegerPolyhedronTest, computeLocalReprFromEquality) {
725725
// Convert `q` to a local variable.
726726
poly.convertToLocal(IdKind::SetDim, 2, 3);
727727

728-
std::vector<SmallVector<int64_t, 8>> divisions = {{-1, -1, 0, 0}};
728+
std::vector<SmallVector<int64_t, 8>> divisions = {{1, 1, 0, 0}};
729729
SmallVector<unsigned, 8> denoms = {4};
730730

731731
checkDivisionRepresentation(poly, divisions, denoms);
@@ -735,7 +735,7 @@ TEST(IntegerPolyhedronTest, computeLocalReprFromEquality) {
735735
// Convert `q` to a local variable.
736736
poly.convertToLocal(IdKind::SetDim, 2, 3);
737737

738-
std::vector<SmallVector<int64_t, 8>> divisions = {{-1, -1, 0, 0}};
738+
std::vector<SmallVector<int64_t, 8>> divisions = {{1, 1, 0, 0}};
739739
SmallVector<unsigned, 8> denoms = {4};
740740

741741
checkDivisionRepresentation(poly, divisions, denoms);
@@ -745,7 +745,7 @@ TEST(IntegerPolyhedronTest, computeLocalReprFromEquality) {
745745
// Convert `q` to a local variable.
746746
poly.convertToLocal(IdKind::SetDim, 2, 3);
747747

748-
std::vector<SmallVector<int64_t, 8>> divisions = {{1, 1, 0, -2}};
748+
std::vector<SmallVector<int64_t, 8>> divisions = {{-1, -1, 0, 2}};
749749
SmallVector<unsigned, 8> denoms = {3};
750750

751751
checkDivisionRepresentation(poly, divisions, denoms);
@@ -761,7 +761,7 @@ TEST(IntegerPolyhedronTest, computeLocalReprFromEqualityAndInequality) {
761761
poly.convertToLocal(IdKind::SetDim, 2, 4);
762762

763763
std::vector<SmallVector<int64_t, 8>> divisions = {{1, 1, 0, 0, 1},
764-
{-1, -1, 0, 0, 0}};
764+
{1, 1, 0, 0, 0}};
765765
SmallVector<unsigned, 8> denoms = {4, 3};
766766

767767
checkDivisionRepresentation(poly, divisions, denoms);

0 commit comments

Comments
 (0)