Skip to content

ConstRange: exhaustively test makeExactICmpRegion #127058

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

Merged
merged 2 commits into from
Feb 17, 2025

Conversation

artagnon
Copy link
Contributor

Exhaustively test makeExactICmpRegion by comparing makeAllowedICmpRegion against makeSatisfyingICmpRegion for all APInts.

Exhaustively test makeExactICmpRegion by comparing makeAllowedICmpRegion
against makeSatisfyingICmpRegion for all APInts.
@artagnon artagnon requested review from nikic and dtcxzyw February 13, 2025 13:09
@llvmbot
Copy link
Member

llvmbot commented Feb 13, 2025

@llvm/pr-subscribers-llvm-ir

Author: Ramkumar Ramachandra (artagnon)

Changes

Exhaustively test makeExactICmpRegion by comparing makeAllowedICmpRegion against makeSatisfyingICmpRegion for all APInts.


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

1 Files Affected:

  • (modified) llvm/unittests/IR/ConstantRangeTest.cpp (+11)
diff --git a/llvm/unittests/IR/ConstantRangeTest.cpp b/llvm/unittests/IR/ConstantRangeTest.cpp
index c390ffea1c352..a85e111146c01 100644
--- a/llvm/unittests/IR/ConstantRangeTest.cpp
+++ b/llvm/unittests/IR/ConstantRangeTest.cpp
@@ -1638,6 +1638,17 @@ TEST(ConstantRange, MakeAllowedICmpRegion) {
                   .isEmptySet());
 }
 
+TEST(ConstantRange, MakeExactICmpRegion) {
+  for (unsigned Bits : {1, 4}) {
+    EnumerateAPInts(Bits, [](const APInt &N) {
+      for (auto Pred : ICmpInst::predicates()) {
+        EXPECT_EQ(ConstantRange::makeAllowedICmpRegion(Pred, N),
+                  ConstantRange::makeSatisfyingICmpRegion(Pred, N));
+      };
+    });
+  }
+}
+
 TEST(ConstantRange, MakeSatisfyingICmpRegion) {
   ConstantRange LowHalf(APInt(8, 0), APInt(8, 128));
   ConstantRange HighHalf(APInt(8, 128), APInt(8, 0));

Copy link
Member

@dtcxzyw dtcxzyw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we remove the assertion here?

assert(makeAllowedICmpRegion(Pred, C) == makeSatisfyingICmpRegion(Pred, C));

Do you have a plan to test with samesign in follow-up patches?

@artagnon
Copy link
Contributor Author

Should we remove the assertion here?

assert(makeAllowedICmpRegion(Pred, C) == makeSatisfyingICmpRegion(Pred, C));

Good idea.

Do you have a plan to test with samesign in follow-up patches?

As I described on the other patch, samesign produces a disjoint union of two ConstantRanges, so I don't think it makes sense to teach ConstantRange about samesign anymore.

@artagnon artagnon merged commit 8eba128 into llvm:main Feb 17, 2025
8 checks passed
@artagnon artagnon deleted the constange-exact-icmp-test branch February 17, 2025 12:30
sivan-shani pushed a commit to sivan-shani/llvm-project that referenced this pull request Feb 24, 2025
Exhaustively test makeExactICmpRegion by comparing makeAllowedICmpRegion
against makeSatisfyingICmpRegion for all APInts.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants