[Mlir-commits] [mlir] Presburger/test: increase coverage of parser (PR #95705)

Ramkumar Ramachandra llvmlistbot at llvm.org
Sun Jun 16 07:06:45 PDT 2024


https://github.com/artagnon updated https://github.com/llvm/llvm-project/pull/95705

>From 27476f043f185edd6988b3564c7ebff5f5b91440 Mon Sep 17 00:00:00 2001
From: Ramkumar Ramachandra <ramkumar.ramachandra at codasip.com>
Date: Sun, 16 Jun 2024 14:36:44 +0100
Subject: [PATCH 1/2] Presburger/test: increase coverage of parser

In preparation to write a free-standing parser for Presburger, improve
the test coverage of the existing parser.
---
 .../Analysis/Presburger/ParserTest.cpp        | 22 +++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/mlir/unittests/Analysis/Presburger/ParserTest.cpp b/mlir/unittests/Analysis/Presburger/ParserTest.cpp
index 4c9f54f97d246..07d641a9b133a 100644
--- a/mlir/unittests/Analysis/Presburger/ParserTest.cpp
+++ b/mlir/unittests/Analysis/Presburger/ParserTest.cpp
@@ -57,6 +57,11 @@ TEST(ParseFACTest, ParseAndCompareTest) {
   EXPECT_TRUE(parseAndCompare("(x)[] : (7 * x >= 0, -7 * x + 5 >= 0)",
                               makeFACFromConstraints(1, 0, {{7, 0}, {-7, 5}})));
 
+  // multiplication distribution
+  EXPECT_TRUE(
+      parseAndCompare("(x) : (2 * x >= 2, (-7 + x * 9) * 5 >= 0)",
+                      makeFACFromConstraints(1, 0, {{2, -2}, {45, -35}})));
+
   // multiple dimensions
   EXPECT_TRUE(parseAndCompare("(x,y,z)[] : (x + y - z >= 0)",
                               makeFACFromConstraints(3, 0, {{1, 1, -1, 0}})));
@@ -75,15 +80,32 @@ TEST(ParseFACTest, ParseAndCompareTest) {
       "(x, y) : (y - 3 * ((x + y - 13) floordiv 3) - 42 == 0)",
       makeFACFromConstraints(2, 0, {}, {{0, 1, -3, -42}}, {{{1, 1, -13}, 3}})));
 
+  // simple ceildiv
+  EXPECT_TRUE(parseAndCompare(
+      "(x, y) : (y - 3 * ((x + y - 13) ceildiv 3) - 42 == 0)",
+      makeFACFromConstraints(2, 0, {}, {{0, 1, -3, -42}}, {{{1, 1, -11}, 3}})));
+
   // multiple floordiv
   EXPECT_TRUE(parseAndCompare(
       "(x, y) : (y - x floordiv 3 - y floordiv 2 == 0)",
       makeFACFromConstraints(2, 0, {}, {{0, 1, -1, -1, 0}},
                              {{{1, 0, 0}, 3}, {{0, 1, 0, 0}, 2}})));
 
+  // multiple ceildiv
+  EXPECT_TRUE(parseAndCompare(
+      "(x, y) : (y - x ceildiv 3 - y ceildiv 2 == 0)",
+      makeFACFromConstraints(2, 0, {}, {{0, 1, -1, -1, 0}},
+                             {{{1, 0, 2}, 3}, {{0, 1, 0, 1}, 2}})));
+
   // nested floordiv
   EXPECT_TRUE(parseAndCompare(
       "(x, y) : (y - (x + y floordiv 2) floordiv 3 == 0)",
       makeFACFromConstraints(2, 0, {}, {{0, 1, 0, -1, 0}},
                              {{{0, 1, 0}, 2}, {{1, 0, 1, 0}, 3}})));
+  // deeply nested floordiv + ceildiv
+  EXPECT_TRUE(parseAndCompare(
+      "(x, y) : (y - (2 * x + y floordiv 2 + x ceildiv 7 + 1) ceildiv 3 == 42)",
+      makeFACFromConstraints(
+          2, 0, {}, {{0, 1, 0, 0, -1, -42}},
+          {{{0, 1, 0}, 2}, {{1, 0, 0, 6}, 7}, {{2, 0, 1, 1, 3}, 3}})));
 }

>From 5de202cb480ed6b90626a70ce8cbd1f0b3014740 Mon Sep 17 00:00:00 2001
From: Ramkumar Ramachandra <ramkumar.ramachandra at codasip.com>
Date: Sun, 16 Jun 2024 15:05:41 +0100
Subject: [PATCH 2/2] ParserTest: add some constant-folding tests

---
 mlir/unittests/Analysis/Presburger/ParserTest.cpp | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/mlir/unittests/Analysis/Presburger/ParserTest.cpp b/mlir/unittests/Analysis/Presburger/ParserTest.cpp
index 07d641a9b133a..11c06042e474c 100644
--- a/mlir/unittests/Analysis/Presburger/ParserTest.cpp
+++ b/mlir/unittests/Analysis/Presburger/ParserTest.cpp
@@ -45,6 +45,18 @@ static bool parseAndCompare(StringRef str, const IntegerPolyhedron &ex) {
 }
 
 TEST(ParseFACTest, ParseAndCompareTest) {
+  // constant-fold addition
+  EXPECT_TRUE(parseAndCompare("() : (4 + 3 >= 0)",
+                              makeFACFromConstraints(0, 0, {}, {})));
+
+  // constant-fold addition + multiplication
+  EXPECT_TRUE(parseAndCompare("()[a] : (4 * 3 == 10 + 2)",
+                              makeFACFromConstraints(0, 1, {}, {})));
+
+  // constant-fold ceildiv + floordiv
+  EXPECT_TRUE(parseAndCompare("(x) : (11 ceildiv 3 == 13 floordiv 3)",
+                              makeFACFromConstraints(1, 0, {}, {})));
+
   // simple ineq
   EXPECT_TRUE(parseAndCompare("(x)[] : (x >= 0)",
                               makeFACFromConstraints(1, 0, {{1, 0}})));
@@ -102,6 +114,7 @@ TEST(ParseFACTest, ParseAndCompareTest) {
       "(x, y) : (y - (x + y floordiv 2) floordiv 3 == 0)",
       makeFACFromConstraints(2, 0, {}, {{0, 1, 0, -1, 0}},
                              {{{0, 1, 0}, 2}, {{1, 0, 1, 0}, 3}})));
+
   // deeply nested floordiv + ceildiv
   EXPECT_TRUE(parseAndCompare(
       "(x, y) : (y - (2 * x + y floordiv 2 + x ceildiv 7 + 1) ceildiv 3 == 42)",



More information about the Mlir-commits mailing list