diff --git a/mlir/unittests/Analysis/AffineStructuresTest.cpp b/mlir/unittests/Analysis/AffineStructuresTest.cpp --- a/mlir/unittests/Analysis/AffineStructuresTest.cpp +++ b/mlir/unittests/Analysis/AffineStructuresTest.cpp @@ -651,63 +651,36 @@ /// representation. static void checkDivisionRepresentation( FlatAffineConstraints &fac, - const std::vector> &divisions, - const SmallVector &denoms) { + const std::vector> &true_dividends, + const SmallVector &true_denominators) { - assert(divisions.size() == fac.getNumLocalIds() && - "Size of expected divisions does not match number of local variables"); - assert( - denoms.size() == fac.getNumLocalIds() && - "Size of expected denominators does not match number of local variables"); + std::vector> dividends; + SmallVector denominators; + std::vector>> repr; - std::vector>> res( - fac.getNumLocalIds(), llvm::None); - fac.getLocalReprs(res); + fac.getLocalReprs(dividends, denominators, repr); + + assert(true_dividends.size() == dividends.size() && + "Size of expected dividends does not match the calculated dividends"); + assert(true_denominators.size() == denominators.size() && + "Size of expected denominators does not match the calculated " + "denominators"); // Check if all expected divisions are computed. for (unsigned i = 0, e = fac.getNumLocalIds(); i < e; ++i) - if (denoms[i] > 0) - EXPECT_TRUE(res[i].hasValue()); + if (true_denominators[i] > 0) + EXPECT_TRUE(repr[i].hasValue()); else - EXPECT_FALSE(res[i].hasValue()); - - unsigned divOffset = fac.getNumDimAndSymbolIds(); - for (unsigned i = 0, e = fac.getNumLocalIds(); i < e; ++i) { - if (!res[i]) - continue; - - // Check if the bounds are of the form: - // 0 <= expr - divisor * id <= divisor - 1 - // Rearranging, we have: - // divisor * id - expr + (divisor - 1) >= 0 <-- Lower bound for 'id' - // -divisor * id + expr >= 0 <-- Upper bound for 'id' - // where `id = expr floordiv divisor`. - unsigned ubPos = res[i]->first, lbPos = res[i]->second; - const SmallVector &expr = divisions[i]; - - // Check if lower bound is of the correct form. - int64_t computedDivisorLb = fac.atIneq(lbPos, i + divOffset); - EXPECT_EQ(computedDivisorLb, denoms[i]); - for (unsigned c = 0, f = fac.getNumLocalIds(); c < f; ++c) { - if (c == i + divOffset) - continue; - EXPECT_EQ(fac.atIneq(lbPos, c), -expr[c]); - } - // Check if constant term of lower bound matches expected constant term. - EXPECT_EQ(fac.atIneq(lbPos, fac.getNumCols() - 1), - -expr.back() + (denoms[i] - 1)); - - // Check if upper bound is of the correct form. - int64_t computedDivisorUb = fac.atIneq(ubPos, i + divOffset); - EXPECT_EQ(computedDivisorUb, -denoms[i]); - for (unsigned c = 0, f = fac.getNumLocalIds(); c < f; ++c) { - if (c == i + divOffset) - continue; - EXPECT_EQ(fac.atIneq(ubPos, c), expr[c]); - } - // Check if constant term of upper bound matches expected constant term. - EXPECT_EQ(fac.atIneq(ubPos, fac.getNumCols() - 1), expr.back()); - } + EXPECT_FALSE(repr[i].hasValue()); + + // Check that the `dividends` and `true dividends` match. + for (unsigned i = 0, e = dividends.size(); i < e; ++i) + for (unsigned j = 0, m = dividends[i].size(); j < m; ++j) + EXPECT_EQ(true_dividends[i][j], dividends[i][j]); + + // Check that the `denominators` and `true_denominators` match. + for (unsigned i = 0, e = denominators.size(); i < e; ++i) + EXPECT_EQ(true_denominators[i], denominators[i]); } TEST(FlatAffineConstraintsTest, computeLocalReprSimple) { @@ -756,9 +729,11 @@ fac.addInequality({1, 2, -2, 1, -5, 0, 6, 100}); fac.addInequality({1, 2, -8, 1, 3, 7, 0, -9}); - std::vector> divisions = {{0, -2, 7, 2, 0, 0, 0, 10}, - {3, 0, 9, 2, 2, 0, 0, 10}, - {0, 1, -123, 2, 0, -4, 10}}; + std::vector> divisions = { + {0, -2, 7, 2, 0, 0, 0, 10}, + {3, 0, 9, 2, 2, 0, 0, 10}, + {0, 1, -123, 2, 0, -4, 0, 10}}; + SmallVector denoms = {3, 5, 3}; // Check if floordivs which may depend on other floordivs can be computed.