[MLIR] Support symbols in emptiness checks for FlatAffineConstraints
authorArjun P <arjunpitchanathan@gmail.com>
Thu, 8 Apr 2021 15:29:58 +0000 (20:59 +0530)
committerArjun P <arjunpitchanathan@gmail.com>
Thu, 8 Apr 2021 16:08:47 +0000 (21:38 +0530)
Reviewed By: ftynse

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

mlir/lib/Analysis/AffineStructures.cpp
mlir/lib/Analysis/LinearTransform.cpp
mlir/unittests/Analysis/AffineStructuresTest.cpp

index 30b00bd..75bc6b7 100644 (file)
@@ -1151,14 +1151,14 @@ Matrix FlatAffineConstraints::getBoundedDirections() const {
 
 bool eqInvolvesSuffixDims(const FlatAffineConstraints &fac, unsigned eqIndex,
                           unsigned numDims) {
-  for (unsigned e = fac.getNumDimIds(), j = e - numDims; j < e; ++j)
+  for (unsigned e = fac.getNumIds(), j = e - numDims; j < e; ++j)
     if (fac.atEq(eqIndex, j) != 0)
       return true;
   return false;
 }
 bool ineqInvolvesSuffixDims(const FlatAffineConstraints &fac,
                             unsigned ineqIndex, unsigned numDims) {
-  for (unsigned e = fac.getNumDimIds(), j = e - numDims; j < e; ++j)
+  for (unsigned e = fac.getNumIds(), j = e - numDims; j < e; ++j)
     if (fac.atIneq(ineqIndex, j) != 0)
       return true;
   return false;
index e8b82c1..c4dc0e7 100644 (file)
@@ -137,7 +137,7 @@ LinearTransform::preMultiplyColumn(ArrayRef<int64_t> colVec) const {
 
 FlatAffineConstraints
 LinearTransform::applyTo(const FlatAffineConstraints &fac) const {
-  FlatAffineConstraints result(fac.getNumDimIds());
+  FlatAffineConstraints result(fac.getNumIds());
 
   for (unsigned i = 0, e = fac.getNumEqualities(); i < e; ++i) {
     ArrayRef<int64_t> eq = fac.getEquality(i);
index 1f97d0b..2121fec 100644 (file)
@@ -51,9 +51,11 @@ static void checkSample(bool hasSample, const FlatAffineConstraints &fac,
 /// Construct a FlatAffineConstraints from a set of inequality and
 /// equality constraints.
 static FlatAffineConstraints
-makeFACFromConstraints(unsigned dims, ArrayRef<SmallVector<int64_t, 4>> ineqs,
-                       ArrayRef<SmallVector<int64_t, 4>> eqs) {
-  FlatAffineConstraints fac(ineqs.size(), eqs.size(), dims + 1, dims);
+makeFACFromConstraints(unsigned ids, ArrayRef<SmallVector<int64_t, 4>> ineqs,
+                       ArrayRef<SmallVector<int64_t, 4>> eqs,
+                       unsigned syms = 0) {
+  FlatAffineConstraints fac(ineqs.size(), eqs.size(), ids + 1, ids - syms,
+                            syms);
   for (const auto &eq : eqs)
     fac.addEquality(eq);
   for (const auto &ineq : ineqs)
@@ -419,6 +421,17 @@ TEST(FlatAffineConstraintsTest, IsIntegerEmptyTest) {
                   },
                   {{2, -3, 0, 0, 0}, {1, -1, 6, 0, -1}, {1, 1, 0, -6, -2}})
                   .isIntegerEmpty());
+
+  // Set with symbols.
+  FlatAffineConstraints fac6 = makeFACFromConstraints(2,
+                                                      {
+                                                          {1, 1, 0},
+                                                      },
+                                                      {
+                                                          {1, -1, 0},
+                                                      },
+                                                      1);
+  EXPECT_FALSE(fac6.isIntegerEmpty());
 }
 
 TEST(FlatAffineConstraintsTest, removeRedundantConstraintsTest) {