Skip to content

Commit

Permalink
[MLIR][Presburger] Fix subtract processing extra inequalities
Browse files Browse the repository at this point in the history
This patch fixes a bug in PresburgeRelation::subtract that made it process the
inequality at index 0, multiple times. This was caused by allocating memory
instead of reserving memory in llvm::SmallVector.

Reviewed By: arjunp

Differential Revision: https://reviews.llvm.org/D127228
  • Loading branch information
Groverkss committed Jun 7, 2022
1 parent ae38e48 commit 445e2b2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
3 changes: 2 additions & 1 deletion mlir/lib/Analysis/Presburger/PresburgerRelation.cpp
Expand Up @@ -300,7 +300,8 @@ static PresburgerRelation getSetDifference(IntegerRelation b,
canIgnoreIneq[j] = simplex.isMarkedRedundant(offset + j);
simplex.rollback(snapshotBeforeIntersect);

SmallVector<unsigned, 8> ineqsToProcess(totalNewSimplexInequalities);
SmallVector<unsigned, 8> ineqsToProcess;
ineqsToProcess.reserve(totalNewSimplexInequalities);
for (unsigned i = 0; i < totalNewSimplexInequalities; ++i)
if (!canIgnoreIneq[i])
ineqsToProcess.push_back(i);
Expand Down
18 changes: 18 additions & 0 deletions mlir/unittests/Analysis/Presburger/PresburgerSetTest.cpp
Expand Up @@ -746,3 +746,21 @@ TEST(SetTest, computeVolume) {
/*trueVolume=*/{},
/*resultBound=*/{});
}

TEST(SetTest, subtractOutputSizeRegression) {
PresburgerSet set1 =
parsePresburgerSetFromPolyStrings(1, {"(i) : (i >= 0, 10 - i >= 0)"});
PresburgerSet set2 =
parsePresburgerSetFromPolyStrings(1, {"(i) : (i - 5 >= 0)"});

PresburgerSet set3 =
parsePresburgerSetFromPolyStrings(1, {"(i) : (i >= 0, 4 - i >= 0)"});

PresburgerSet result = set1.subtract(set2);

EXPECT_TRUE(result.isEqual(set3));

// Previously, the subtraction result was producing an extra empty set, which
// is correct, but bad for output size.
EXPECT_EQ(result.getNumDisjuncts(), 1u);
}

0 comments on commit 445e2b2

Please sign in to comment.