[Mlir-commits] [mlir] 445e2b2 - [MLIR][Presburger] Fix subtract processing extra inequalities

llvmlistbot at llvm.org llvmlistbot at llvm.org
Tue Jun 7 10:22:05 PDT 2022


Author: Groverkss
Date: 2022-06-07T22:51:03+05:30
New Revision: 445e2b2aa06927a503232516203885cb0ed59ac5

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

LOG: [MLIR][Presburger] Fix subtract processing extra inequalities

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

Added: 
    

Modified: 
    mlir/lib/Analysis/Presburger/PresburgerRelation.cpp
    mlir/unittests/Analysis/Presburger/PresburgerSetTest.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Analysis/Presburger/PresburgerRelation.cpp b/mlir/lib/Analysis/Presburger/PresburgerRelation.cpp
index 375ea70c60cd6..4bb726d798cfa 100644
--- a/mlir/lib/Analysis/Presburger/PresburgerRelation.cpp
+++ b/mlir/lib/Analysis/Presburger/PresburgerRelation.cpp
@@ -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);

diff  --git a/mlir/unittests/Analysis/Presburger/PresburgerSetTest.cpp b/mlir/unittests/Analysis/Presburger/PresburgerSetTest.cpp
index b21bcc5812779..fbd3e3c48ccad 100644
--- a/mlir/unittests/Analysis/Presburger/PresburgerSetTest.cpp
+++ b/mlir/unittests/Analysis/Presburger/PresburgerSetTest.cpp
@@ -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);
+}


        


More information about the Mlir-commits mailing list