[llvm] ConstRange: exhaustively test makeExactICmpRegion (PR #127058)

Ramkumar Ramachandra via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 17 03:15:43 PST 2025


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

>From 17bdd904db70705e86275382556c5c812e286a19 Mon Sep 17 00:00:00 2001
From: Ramkumar Ramachandra <ramkumar.ramachandra at codasip.com>
Date: Thu, 13 Feb 2025 13:04:24 +0000
Subject: [PATCH 1/2] ConstRange: exhaustively test makeExactICmpRegion

Exhaustively test makeExactICmpRegion by comparing makeAllowedICmpRegion
against makeSatisfyingICmpRegion for all APInts.
---
 llvm/unittests/IR/ConstantRangeTest.cpp | 11 +++++++++++
 1 file changed, 11 insertions(+)

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));

>From 81863a3d3b481794ad6d4efb03768d21573124a6 Mon Sep 17 00:00:00 2001
From: Ramkumar Ramachandra <ramkumar.ramachandra at codasip.com>
Date: Mon, 17 Feb 2025 11:14:57 +0000
Subject: [PATCH 2/2] ConstRange: strip assert

---
 llvm/lib/IR/ConstantRange.cpp | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/llvm/lib/IR/ConstantRange.cpp b/llvm/lib/IR/ConstantRange.cpp
index 3566435398992..4349303146780 100644
--- a/llvm/lib/IR/ConstantRange.cpp
+++ b/llvm/lib/IR/ConstantRange.cpp
@@ -159,11 +159,10 @@ ConstantRange ConstantRange::makeExactICmpRegion(CmpInst::Predicate Pred,
                                                  const APInt &C) {
   // Computes the exact range that is equal to both the constant ranges returned
   // by makeAllowedICmpRegion and makeSatisfyingICmpRegion. This is always true
-  // when RHS is a singleton such as an APInt and so the assert is valid.
-  // However for non-singleton RHS, for example ult [2,5) makeAllowedICmpRegion
-  // returns [0,4) but makeSatisfyICmpRegion returns [0,2).
+  // when RHS is a singleton such as an APInt. However for non-singleton RHS,
+  // for example ult [2,5) makeAllowedICmpRegion returns [0,4) but
+  // makeSatisfyICmpRegion returns [0,2).
   //
-  assert(makeAllowedICmpRegion(Pred, C) == makeSatisfyingICmpRegion(Pred, C));
   return makeAllowedICmpRegion(Pred, C);
 }
 



More information about the llvm-commits mailing list