[Mlir-commits] [mlir] [mlir] [presburger] Add IntegerRelation::rangeProduct (PR #148092)
Arjun P
llvmlistbot at llvm.org
Wed Jul 16 08:51:11 PDT 2025
================
@@ -608,3 +608,48 @@ TEST(IntegerRelationTest, convertVarKindToLocal) {
EXPECT_EQ(space.getId(VarKind::Symbol, 0), Identifier(&identifiers[3]));
EXPECT_EQ(space.getId(VarKind::Symbol, 1), Identifier(&identifiers[4]));
}
+
+TEST(IntegerRelationTest, rangeProduct) {
+ IntegerRelation r1 = parseRelationFromSet(
+ "(i, j, k) : (2*i + 3*k == 0, i >= 0, j >= 0, k >= 0)", 2);
+ IntegerRelation r2 = parseRelationFromSet(
+ "(i, j, l) : (4*i + 6*j + 9*l == 0, i >= 0, j >= 0, l >= 0)", 2);
+
+ IntegerRelation rangeProd = r1.rangeProduct(r2);
+ IntegerRelation expected =
+ parseRelationFromSet("(i, j, k, l) : (2*i + 3*k == 0, 4*i + 6*j + 9*l == "
+ "0, i >= 0, j >= 0, k >= 0, l >= 0)",
+ 2);
+
+ EXPECT_TRUE(expected.isEqual(rangeProd));
+}
+
+TEST(IntegerRelationTest, rangeProductMultdimRange) {
+ IntegerRelation r1 =
+ parseRelationFromSet("(i, k) : (2*i + 3*k == 0, i >= 0, k >= 0)", 1);
+ IntegerRelation r2 = parseRelationFromSet(
+ "(i, l, m) : (4*i + 6*m + 9*l == 0, i >= 0, l >= 0, m >= 0)", 1);
+
+ IntegerRelation rangeProd = r1.rangeProduct(r2);
+ IntegerRelation expected =
+ parseRelationFromSet("(i, k, l, m) : (2*i + 3*k == 0, 4*i + 6*m + 9*l == "
+ "0, i >= 0, k >= 0, l >= 0, m >= 0)",
+ 1);
+
+ EXPECT_TRUE(expected.isEqual(rangeProd));
+}
+
+TEST(IntegerRelationTest, rangeProductMultdimRangeSwapped) {
+ IntegerRelation r1 = parseRelationFromSet(
+ "(i, l, m) : (4*i + 6*m + 9*l == 0, i >= 0, l >= 0, m >= 0)", 1);
+ IntegerRelation r2 =
+ parseRelationFromSet("(i, k) : (2*i + 3*k == 0, i >= 0, k >= 0)", 1);
+
+ IntegerRelation rangeProd = r1.rangeProduct(r2);
+ IntegerRelation expected =
+ parseRelationFromSet("(i, l, m, k) : (2*i + 3*k == 0, 4*i + 6*m + 9*l == "
+ "0, i >= 0, k >= 0, l >= 0, m >= 0)",
+ 1);
+
+ EXPECT_TRUE(expected.isEqual(rangeProd));
+}
----------------
Superty wrote:
No, the unit test parser doesn't add identifiers. Currently, binary operations that don't explicitly mention merging generally require that both have the same number of symbols; these are considered to be the same symbols in both. i.e., in your case, you can just ignore the symbols. Just assert that `getSpace().getDomainSpace().isCompatible(rel.getSpace().getDomainSpace())`. Sorry I didn't make this explicit earlier, and thanks for checking in early :)
https://github.com/llvm/llvm-project/pull/148092
More information about the Mlir-commits
mailing list