Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Presburger/test: increase coverage of parser #95705

Merged
merged 1 commit into from
Jul 2, 2024

Conversation

artagnon
Copy link
Contributor

In preparation to write a free-standing parser for Presburger, improve the test coverage of the existing parser.

@llvmbot
Copy link
Collaborator

llvmbot commented Jun 16, 2024

@llvm/pr-subscribers-mlir

@llvm/pr-subscribers-mlir-presburger

Author: Ramkumar Ramachandra (artagnon)

Changes

In preparation to write a free-standing parser for Presburger, improve the test coverage of the existing parser.


Full diff: https://github.com/llvm/llvm-project/pull/95705.diff

1 Files Affected:

  • (modified) mlir/unittests/Analysis/Presburger/ParserTest.cpp (+22)
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}})));
 }

@Superty
Copy link
Member

Superty commented Jun 21, 2024

The tests look correct to me. I'll leave it to @Groverkss to give final approval for the parser stuff

In preparation to write a free-standing parser for Presburger, improve
the test coverage of the existing parser.
@Superty
Copy link
Member

Superty commented Jul 1, 2024

Kunwar is on vacation, I'm ok to merge this for now

@artagnon artagnon merged commit 01134e6 into llvm:main Jul 2, 2024
7 checks passed
@artagnon artagnon deleted the presburger-parser-test branch July 2, 2024 09:38
kirillpyasecky pushed a commit to kirillpyasecky/llvm-project that referenced this pull request Jul 3, 2024
In preparation to write a free-standing parser for Presburger, improve
the test coverage of the existing parser.
kbluck pushed a commit to kbluck/llvm-project that referenced this pull request Jul 6, 2024
In preparation to write a free-standing parser for Presburger, improve
the test coverage of the existing parser.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants