[llvm] Add ConstantRangeList::unionWith() and ::intersectWith() (PR #96547)
Haopeng Liu via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 24 17:55:36 PDT 2024
https://github.com/haopliu updated https://github.com/llvm/llvm-project/pull/96547
>From 606435b502dcabd4a4fb7fe861ac1ae933acf018 Mon Sep 17 00:00:00 2001
From: Haopeng Liu <haopliu at google.com>
Date: Mon, 24 Jun 2024 20:07:36 +0000
Subject: [PATCH 1/2] Add ConstantRangeList::unionWith() and ::intersectWith()
---
llvm/include/llvm/IR/ConstantRangeList.h | 8 ++
llvm/lib/IR/ConstantRangeList.cpp | 80 +++++++++++++
llvm/unittests/IR/ConstantRangeListTest.cpp | 118 ++++++++++++++++++++
3 files changed, 206 insertions(+)
diff --git a/llvm/include/llvm/IR/ConstantRangeList.h b/llvm/include/llvm/IR/ConstantRangeList.h
index f696bd6cc6a3d..3b32f92a76653 100644
--- a/llvm/include/llvm/IR/ConstantRangeList.h
+++ b/llvm/include/llvm/IR/ConstantRangeList.h
@@ -72,6 +72,14 @@ class [[nodiscard]] ConstantRangeList {
APInt(64, Upper, /*isSigned=*/true)));
}
+ /// Return the range list that results from the union of this range
+ /// with another range list.
+ ConstantRangeList unionWith(const ConstantRangeList &CRL) const;
+
+ /// Return the range list that results from the intersection of this range
+ /// with another range list.
+ ConstantRangeList intersectWith(const ConstantRangeList &CRL) const;
+
/// Return true if this range list is equal to another range list.
bool operator==(const ConstantRangeList &CRL) const {
return Ranges == CRL.Ranges;
diff --git a/llvm/lib/IR/ConstantRangeList.cpp b/llvm/lib/IR/ConstantRangeList.cpp
index 2cc483d4e4962..2d93d06ad30b1 100644
--- a/llvm/lib/IR/ConstantRangeList.cpp
+++ b/llvm/lib/IR/ConstantRangeList.cpp
@@ -81,6 +81,86 @@ void ConstantRangeList::insert(const ConstantRange &NewRange) {
}
}
+ConstantRangeList
+ConstantRangeList::unionWith(const ConstantRangeList &CRL) const {
+ assert(getBitWidth() == CRL.getBitWidth() &&
+ "ConstantRangeList types don't agree!");
+ // Handle common cases.
+ if (empty())
+ return CRL;
+ if (CRL.empty())
+ return *this;
+
+ ConstantRangeList Result;
+ size_t i = 0, j = 0;
+ ConstantRange PreviousRange(getBitWidth(), false);
+ if (Ranges[i].getLower().slt(CRL.Ranges[j].getLower())) {
+ PreviousRange = Ranges[i++];
+ } else {
+ PreviousRange = CRL.Ranges[j++];
+ }
+ auto UnionAndUpdateRange = [&PreviousRange,
+ &Result](const ConstantRange &CR) {
+ assert(!CR.isSignWrappedSet() && "Upper wrapped ranges are not supported");
+ if (PreviousRange.getUpper().slt(CR.getLower())) {
+ Result.Ranges.push_back(PreviousRange);
+ PreviousRange = CR;
+ } else {
+ PreviousRange = ConstantRange(
+ PreviousRange.getLower(),
+ APIntOps::smax(PreviousRange.getUpper(), CR.getUpper()));
+ }
+ };
+ while (i < size() || j < CRL.size()) {
+ if (j == CRL.size() ||
+ (i < size() && Ranges[i].getLower().slt(CRL.Ranges[j].getLower()))) {
+ // Merge PreviousRange with this.
+ UnionAndUpdateRange(Ranges[i++]);
+ } else {
+ // Merge PreviousRange with CRL.
+ UnionAndUpdateRange(CRL.Ranges[j++]);
+ }
+ }
+ Result.Ranges.push_back(PreviousRange);
+ return Result;
+}
+
+ConstantRangeList
+ConstantRangeList::intersectWith(const ConstantRangeList &CRL) const {
+ assert(getBitWidth() == CRL.getBitWidth() &&
+ "ConstantRangeList types don't agree!");
+
+ // Handle common cases.
+ if (empty())
+ return *this;
+ if (CRL.empty())
+ return CRL;
+
+ ConstantRangeList Result;
+ size_t i = 0, j = 0;
+ while (i < size() && j < CRL.size()) {
+ auto &Range = this->Ranges[i];
+ auto &OtherRange = CRL.Ranges[j];
+ assert(!Range.isSignWrappedSet() && !OtherRange.isSignWrappedSet() &&
+ "Upper wrapped ranges are not supported");
+
+ APInt Start = Range.getLower().slt(OtherRange.getLower())
+ ? OtherRange.getLower()
+ : Range.getLower();
+ APInt End = Range.getUpper().slt(OtherRange.getUpper())
+ ? Range.getUpper()
+ : OtherRange.getUpper();
+ if (Start.slt(End))
+ Result.Ranges.push_back(ConstantRange(Start, End));
+
+ if (Range.getUpper().slt(OtherRange.getUpper()))
+ i++;
+ else
+ j++;
+ }
+ return Result;
+}
+
void ConstantRangeList::print(raw_ostream &OS) const {
interleaveComma(Ranges, OS, [&](ConstantRange CR) {
OS << "(" << CR.getLower() << ", " << CR.getUpper() << ")";
diff --git a/llvm/unittests/IR/ConstantRangeListTest.cpp b/llvm/unittests/IR/ConstantRangeListTest.cpp
index 144b5ccdc1fc0..d2fee18c88b5a 100644
--- a/llvm/unittests/IR/ConstantRangeListTest.cpp
+++ b/llvm/unittests/IR/ConstantRangeListTest.cpp
@@ -94,4 +94,122 @@ TEST_F(ConstantRangeListTest, Insert) {
EXPECT_TRUE(CRL == Expected);
}
+ConstantRangeList GetCRL(const SmallVector<std::pair<APInt, APInt>, 2> &Pairs) {
+ SmallVector<ConstantRange, 2> Ranges;
+ for (auto &[Start, End] : Pairs)
+ Ranges.push_back(ConstantRange(Start, End));
+ return ConstantRangeList(Ranges);
+}
+
+TEST_F(ConstantRangeListTest, Union) {
+ APInt AP0 = APInt(64, 0, /*isSigned=*/true);
+ APInt AP2 = APInt(64, 2, /*isSigned=*/true);
+ APInt AP4 = APInt(64, 4, /*isSigned=*/true);
+ APInt AP8 = APInt(64, 8, /*isSigned=*/true);
+ APInt AP10 = APInt(64, 10, /*isSigned=*/true);
+ APInt AP11 = APInt(64, 11, /*isSigned=*/true);
+ APInt AP12 = APInt(64, 12, /*isSigned=*/true);
+ ConstantRangeList CRL = GetCRL({{AP0, AP4}, {AP8, AP12}});
+
+ // Union with a subset.
+ ConstantRangeList Empty;
+ EXPECT_TRUE(CRL.unionWith(Empty) == CRL);
+ EXPECT_TRUE(Empty.unionWith(CRL) == CRL);
+
+ EXPECT_TRUE(CRL.unionWith(GetCRL({{AP0, AP2}})) == CRL);
+ EXPECT_TRUE(CRL.unionWith(GetCRL({{AP10, AP12}})) == CRL);
+
+ EXPECT_TRUE(CRL.unionWith(GetCRL({{AP0, AP2}, {AP8, AP10}})) == CRL);
+ EXPECT_TRUE(CRL.unionWith(GetCRL({{AP0, AP2}, {AP10, AP12}})) == CRL);
+ EXPECT_TRUE(CRL.unionWith(GetCRL({{AP2, AP4}, {AP8, AP10}})) == CRL);
+ EXPECT_TRUE(CRL.unionWith(GetCRL({{AP2, AP4}, {AP10, AP12}})) == CRL);
+
+ EXPECT_TRUE(CRL.unionWith(GetCRL({{AP0, AP4}, {AP8, AP10}, {AP11, AP12}})) ==
+ CRL);
+
+ EXPECT_TRUE(CRL.unionWith(CRL) == CRL);
+
+ // Union with new ranges.
+ APInt APN4 = APInt(64, -4, /*isSigned=*/true);
+ APInt APN2 = APInt(64, -2, /*isSigned=*/true);
+ APInt AP6 = APInt(64, 6, /*isSigned=*/true);
+ APInt AP7 = APInt(64, 7, /*isSigned=*/true);
+ APInt AP16 = APInt(64, 16, /*isSigned=*/true);
+ APInt AP18 = APInt(64, 18, /*isSigned=*/true);
+
+ EXPECT_TRUE(CRL.unionWith(GetCRL({{APN4, APN2}})) ==
+ GetCRL({{APN4, APN2}, {AP0, AP4}, {AP8, AP12}}));
+ EXPECT_TRUE(CRL.unionWith(GetCRL({{AP6, AP7}})) ==
+ GetCRL({{AP0, AP4}, {AP6, AP7}, {AP8, AP12}}));
+ EXPECT_TRUE(CRL.unionWith(GetCRL({{AP16, AP18}})) ==
+ GetCRL({{AP0, AP4}, {AP8, AP12}, {AP16, AP18}}));
+
+ EXPECT_TRUE(CRL.unionWith(GetCRL({{APN2, AP2}})) ==
+ GetCRL({{APN2, AP4}, {AP8, AP12}}));
+ EXPECT_TRUE(CRL.unionWith(GetCRL({{AP2, AP6}})) ==
+ GetCRL({{AP0, AP6}, {AP8, AP12}}));
+ EXPECT_TRUE(CRL.unionWith(GetCRL({{AP10, AP16}})) ==
+ GetCRL({{AP0, AP4}, {AP8, AP16}}));
+
+ EXPECT_TRUE(CRL.unionWith(GetCRL({{APN2, AP10}})) == GetCRL({{APN2, AP12}}));
+ EXPECT_TRUE(CRL.unionWith(GetCRL({{AP2, AP10}})) == GetCRL({{AP0, AP12}}));
+ EXPECT_TRUE(CRL.unionWith(GetCRL({{AP4, AP16}})) == GetCRL({{AP0, AP16}}));
+ EXPECT_TRUE(CRL.unionWith(GetCRL({{APN2, AP16}})) == GetCRL({{APN2, AP16}}));
+}
+
+TEST_F(ConstantRangeListTest, Intersect) {
+ APInt APN2 = APInt(64, -2, /*isSigned=*/true);
+ APInt AP0 = APInt(64, 0, /*isSigned=*/true);
+ APInt AP2 = APInt(64, 2, /*isSigned=*/true);
+ APInt AP4 = APInt(64, 4, /*isSigned=*/true);
+ APInt AP6 = APInt(64, 6, /*isSigned=*/true);
+ APInt AP7 = APInt(64, 7, /*isSigned=*/true);
+ APInt AP8 = APInt(64, 8, /*isSigned=*/true);
+ APInt AP10 = APInt(64, 10, /*isSigned=*/true);
+ APInt AP11 = APInt(64, 11, /*isSigned=*/true);
+ APInt AP12 = APInt(64, 12, /*isSigned=*/true);
+ APInt AP16 = APInt(64, 16, /*isSigned=*/true);
+ ConstantRangeList CRL = GetCRL({{AP0, AP4}, {AP8, AP12}});
+
+ // No intersection.
+ ConstantRangeList Empty;
+ EXPECT_TRUE(CRL.intersectWith(Empty) == Empty);
+ EXPECT_TRUE(Empty.intersectWith(CRL) == Empty);
+
+ EXPECT_TRUE(CRL.intersectWith(GetCRL({{APN2, AP0}})) == Empty);
+ EXPECT_TRUE(CRL.intersectWith(GetCRL({{AP6, AP8}})) == Empty);
+ EXPECT_TRUE(CRL.intersectWith(GetCRL({{AP12, AP16}})) == Empty);
+
+ // Single intersect range.
+ EXPECT_TRUE(CRL.intersectWith(GetCRL({{APN2, AP2}})) == GetCRL({{AP0, AP2}}));
+ EXPECT_TRUE(CRL.intersectWith(GetCRL({{APN2, AP6}})) == GetCRL({{AP0, AP4}}));
+ EXPECT_TRUE(CRL.intersectWith(GetCRL({{AP2, AP4}})) == GetCRL({{AP2, AP4}}));
+ EXPECT_TRUE(CRL.intersectWith(GetCRL({{AP2, AP6}})) == GetCRL({{AP2, AP4}}));
+ EXPECT_TRUE(CRL.intersectWith(GetCRL({{AP6, AP10}})) ==
+ GetCRL({{AP8, AP10}}));
+ EXPECT_TRUE(CRL.intersectWith(GetCRL({{AP6, AP16}})) ==
+ GetCRL({{AP8, AP12}}));
+ EXPECT_TRUE(CRL.intersectWith(GetCRL({{AP10, AP12}})) ==
+ GetCRL({{AP10, AP12}}));
+ EXPECT_TRUE(CRL.intersectWith(GetCRL({{AP10, AP16}})) ==
+ GetCRL({{AP10, AP12}}));
+
+ // Multiple intersect ranges.
+ EXPECT_TRUE(CRL.intersectWith(GetCRL({{APN2, AP10}})) ==
+ GetCRL({{AP0, AP4}, {AP8, AP10}}));
+ EXPECT_TRUE(CRL.intersectWith(GetCRL({{APN2, AP16}})) == CRL);
+ EXPECT_TRUE(CRL.intersectWith(GetCRL({{AP2, AP10}})) ==
+ GetCRL({{AP2, AP4}, {AP8, AP10}}));
+ EXPECT_TRUE(CRL.intersectWith(GetCRL({{AP2, AP16}})) ==
+ GetCRL({{AP2, AP4}, {AP8, AP12}}));
+ EXPECT_TRUE(CRL.intersectWith(GetCRL({{{APN2, AP2}, {AP6, AP10}}})) ==
+ GetCRL({{AP0, AP2}, {AP8, AP10}}));
+ EXPECT_TRUE(CRL.intersectWith(GetCRL({{{AP2, AP6}, {AP10, AP16}}})) ==
+ GetCRL({{AP2, AP4}, {AP10, AP12}}));
+ EXPECT_TRUE(
+ CRL.intersectWith(GetCRL({{{APN2, AP2}, {AP7, AP10}, {AP11, AP16}}})) ==
+ GetCRL({{AP0, AP2}, {AP8, AP10}, {AP11, AP12}}));
+ EXPECT_TRUE(CRL.intersectWith(CRL) == CRL);
+}
+
} // anonymous namespace
>From 4a2ef241fbab1feb5e90b2bf66845f83634f1631 Mon Sep 17 00:00:00 2001
From: Haopeng Liu <haopliu at google.com>
Date: Tue, 25 Jun 2024 00:55:24 +0000
Subject: [PATCH 2/2] Update comments, tests, and simplify code a bit
---
llvm/lib/IR/ConstantRangeList.cpp | 31 +++--
llvm/unittests/IR/ConstantRangeListTest.cpp | 131 ++++++++++----------
2 files changed, 84 insertions(+), 78 deletions(-)
diff --git a/llvm/lib/IR/ConstantRangeList.cpp b/llvm/lib/IR/ConstantRangeList.cpp
index 2d93d06ad30b1..880a6cecd9880 100644
--- a/llvm/lib/IR/ConstantRangeList.cpp
+++ b/llvm/lib/IR/ConstantRangeList.cpp
@@ -93,15 +93,23 @@ ConstantRangeList::unionWith(const ConstantRangeList &CRL) const {
ConstantRangeList Result;
size_t i = 0, j = 0;
+ // "PreviousRange" tracks the unioned range (its lower is fixed
+ // and the upper may be updated over iterations).
+ // If "PreviousRange" cannot contain a new unioned range, push it
+ // to the result and assign "PreviousRange" with the new range.
ConstantRange PreviousRange(getBitWidth(), false);
if (Ranges[i].getLower().slt(CRL.Ranges[j].getLower())) {
PreviousRange = Ranges[i++];
} else {
PreviousRange = CRL.Ranges[j++];
}
+
+ // Union "PreviousRange" and "CR". If they are disjoint, push "PreviousRange"
+ // to the result and assign it to "CR", a new union range. Otherwise, update
+ // the upper of "PreviousRange" to cover "CR". Note that, the lower of
+ // "PreviousRange" is always less or equal the lower of "CR".
auto UnionAndUpdateRange = [&PreviousRange,
&Result](const ConstantRange &CR) {
- assert(!CR.isSignWrappedSet() && "Upper wrapped ranges are not supported");
if (PreviousRange.getUpper().slt(CR.getLower())) {
Result.Ranges.push_back(PreviousRange);
PreviousRange = CR;
@@ -141,18 +149,21 @@ ConstantRangeList::intersectWith(const ConstantRangeList &CRL) const {
while (i < size() && j < CRL.size()) {
auto &Range = this->Ranges[i];
auto &OtherRange = CRL.Ranges[j];
- assert(!Range.isSignWrappedSet() && !OtherRange.isSignWrappedSet() &&
- "Upper wrapped ranges are not supported");
-
- APInt Start = Range.getLower().slt(OtherRange.getLower())
- ? OtherRange.getLower()
- : Range.getLower();
- APInt End = Range.getUpper().slt(OtherRange.getUpper())
- ? Range.getUpper()
- : OtherRange.getUpper();
+
+ // The intersection of two Ranges is (max(lowers), min(uppers)), and it's
+ // possible that max(lowers) > min(uppers). Add the intersection to result
+ // only if it's a non-upper-wrapped range.
+ // To keep simple, we don't call ConstantRange::intersectWith() as it
+ // considers the complex upper wrapped case and may result two ranges,
+ // like (2, 8) && (6, 4) = {(2, 4), (6, 8)}.
+ APInt Start = APIntOps::smax(Range.getLower(), OtherRange.getLower());
+ APInt End = APIntOps::smin(Range.getUpper(), OtherRange.getUpper());
if (Start.slt(End))
Result.Ranges.push_back(ConstantRange(Start, End));
+ // Move to the next Range in one list determined by the uppers.
+ // For example: A = {(0, 2), (4, 8)}; B = {(-2, 5), (6, 10)}
+ // We need to intersect three pairs: A0 && B0; A1 && B0; A1 && B1.
if (Range.getUpper().slt(OtherRange.getUpper()))
i++;
else
diff --git a/llvm/unittests/IR/ConstantRangeListTest.cpp b/llvm/unittests/IR/ConstantRangeListTest.cpp
index d2fee18c88b5a..2b3226df84865 100644
--- a/llvm/unittests/IR/ConstantRangeListTest.cpp
+++ b/llvm/unittests/IR/ConstantRangeListTest.cpp
@@ -94,7 +94,7 @@ TEST_F(ConstantRangeListTest, Insert) {
EXPECT_TRUE(CRL == Expected);
}
-ConstantRangeList GetCRL(const SmallVector<std::pair<APInt, APInt>, 2> &Pairs) {
+ConstantRangeList GetCRL(ArrayRef<std::pair<APInt, APInt>> Pairs) {
SmallVector<ConstantRange, 2> Ranges;
for (auto &[Start, End] : Pairs)
Ranges.push_back(ConstantRange(Start, End));
@@ -102,59 +102,58 @@ ConstantRangeList GetCRL(const SmallVector<std::pair<APInt, APInt>, 2> &Pairs) {
}
TEST_F(ConstantRangeListTest, Union) {
+ APInt APN4 = APInt(64, -4, /*isSigned=*/true);
+ APInt APN2 = APInt(64, -2, /*isSigned=*/true);
APInt AP0 = APInt(64, 0, /*isSigned=*/true);
APInt AP2 = APInt(64, 2, /*isSigned=*/true);
APInt AP4 = APInt(64, 4, /*isSigned=*/true);
+ APInt AP6 = APInt(64, 6, /*isSigned=*/true);
+ APInt AP7 = APInt(64, 7, /*isSigned=*/true);
APInt AP8 = APInt(64, 8, /*isSigned=*/true);
APInt AP10 = APInt(64, 10, /*isSigned=*/true);
APInt AP11 = APInt(64, 11, /*isSigned=*/true);
APInt AP12 = APInt(64, 12, /*isSigned=*/true);
+ APInt AP16 = APInt(64, 16, /*isSigned=*/true);
+ APInt AP18 = APInt(64, 18, /*isSigned=*/true);
ConstantRangeList CRL = GetCRL({{AP0, AP4}, {AP8, AP12}});
// Union with a subset.
ConstantRangeList Empty;
- EXPECT_TRUE(CRL.unionWith(Empty) == CRL);
- EXPECT_TRUE(Empty.unionWith(CRL) == CRL);
+ EXPECT_EQ(CRL.unionWith(Empty), CRL);
+ EXPECT_EQ(Empty.unionWith(CRL), CRL);
- EXPECT_TRUE(CRL.unionWith(GetCRL({{AP0, AP2}})) == CRL);
- EXPECT_TRUE(CRL.unionWith(GetCRL({{AP10, AP12}})) == CRL);
+ EXPECT_EQ(CRL.unionWith(GetCRL({{AP0, AP2}})), CRL);
+ EXPECT_EQ(CRL.unionWith(GetCRL({{AP10, AP12}})), CRL);
- EXPECT_TRUE(CRL.unionWith(GetCRL({{AP0, AP2}, {AP8, AP10}})) == CRL);
- EXPECT_TRUE(CRL.unionWith(GetCRL({{AP0, AP2}, {AP10, AP12}})) == CRL);
- EXPECT_TRUE(CRL.unionWith(GetCRL({{AP2, AP4}, {AP8, AP10}})) == CRL);
- EXPECT_TRUE(CRL.unionWith(GetCRL({{AP2, AP4}, {AP10, AP12}})) == CRL);
+ EXPECT_EQ(CRL.unionWith(GetCRL({{AP0, AP2}, {AP8, AP10}})), CRL);
+ EXPECT_EQ(CRL.unionWith(GetCRL({{AP0, AP2}, {AP10, AP12}})), CRL);
+ EXPECT_EQ(CRL.unionWith(GetCRL({{AP2, AP4}, {AP8, AP10}})), CRL);
+ EXPECT_EQ(CRL.unionWith(GetCRL({{AP2, AP4}, {AP10, AP12}})), CRL);
- EXPECT_TRUE(CRL.unionWith(GetCRL({{AP0, AP4}, {AP8, AP10}, {AP11, AP12}})) ==
- CRL);
+ EXPECT_EQ(CRL.unionWith(GetCRL({{AP0, AP4}, {AP8, AP10}, {AP11, AP12}})),
+ CRL);
- EXPECT_TRUE(CRL.unionWith(CRL) == CRL);
+ EXPECT_EQ(CRL.unionWith(CRL), CRL);
// Union with new ranges.
- APInt APN4 = APInt(64, -4, /*isSigned=*/true);
- APInt APN2 = APInt(64, -2, /*isSigned=*/true);
- APInt AP6 = APInt(64, 6, /*isSigned=*/true);
- APInt AP7 = APInt(64, 7, /*isSigned=*/true);
- APInt AP16 = APInt(64, 16, /*isSigned=*/true);
- APInt AP18 = APInt(64, 18, /*isSigned=*/true);
-
- EXPECT_TRUE(CRL.unionWith(GetCRL({{APN4, APN2}})) ==
- GetCRL({{APN4, APN2}, {AP0, AP4}, {AP8, AP12}}));
- EXPECT_TRUE(CRL.unionWith(GetCRL({{AP6, AP7}})) ==
- GetCRL({{AP0, AP4}, {AP6, AP7}, {AP8, AP12}}));
- EXPECT_TRUE(CRL.unionWith(GetCRL({{AP16, AP18}})) ==
- GetCRL({{AP0, AP4}, {AP8, AP12}, {AP16, AP18}}));
-
- EXPECT_TRUE(CRL.unionWith(GetCRL({{APN2, AP2}})) ==
- GetCRL({{APN2, AP4}, {AP8, AP12}}));
- EXPECT_TRUE(CRL.unionWith(GetCRL({{AP2, AP6}})) ==
- GetCRL({{AP0, AP6}, {AP8, AP12}}));
- EXPECT_TRUE(CRL.unionWith(GetCRL({{AP10, AP16}})) ==
- GetCRL({{AP0, AP4}, {AP8, AP16}}));
-
- EXPECT_TRUE(CRL.unionWith(GetCRL({{APN2, AP10}})) == GetCRL({{APN2, AP12}}));
- EXPECT_TRUE(CRL.unionWith(GetCRL({{AP2, AP10}})) == GetCRL({{AP0, AP12}}));
- EXPECT_TRUE(CRL.unionWith(GetCRL({{AP4, AP16}})) == GetCRL({{AP0, AP16}}));
- EXPECT_TRUE(CRL.unionWith(GetCRL({{APN2, AP16}})) == GetCRL({{APN2, AP16}}));
+ EXPECT_EQ(CRL.unionWith(GetCRL({{APN4, APN2}})),
+ GetCRL({{APN4, APN2}, {AP0, AP4}, {AP8, AP12}}));
+ EXPECT_EQ(CRL.unionWith(GetCRL({{AP6, AP7}})),
+ GetCRL({{AP0, AP4}, {AP6, AP7}, {AP8, AP12}}));
+ EXPECT_EQ(CRL.unionWith(GetCRL({{AP16, AP18}})),
+ GetCRL({{AP0, AP4}, {AP8, AP12}, {AP16, AP18}}));
+
+ EXPECT_EQ(CRL.unionWith(GetCRL({{APN2, AP2}})),
+ GetCRL({{APN2, AP4}, {AP8, AP12}}));
+ EXPECT_EQ(CRL.unionWith(GetCRL({{AP2, AP6}})),
+ GetCRL({{AP0, AP6}, {AP8, AP12}}));
+ EXPECT_EQ(CRL.unionWith(GetCRL({{AP10, AP16}})),
+ GetCRL({{AP0, AP4}, {AP8, AP16}}));
+
+ EXPECT_EQ(CRL.unionWith(GetCRL({{APN2, AP10}})), GetCRL({{APN2, AP12}}));
+ EXPECT_EQ(CRL.unionWith(GetCRL({{AP2, AP10}})), GetCRL({{AP0, AP12}}));
+ EXPECT_EQ(CRL.unionWith(GetCRL({{AP4, AP16}})), GetCRL({{AP0, AP16}}));
+ EXPECT_EQ(CRL.unionWith(GetCRL({{APN2, AP16}})), GetCRL({{APN2, AP16}}));
}
TEST_F(ConstantRangeListTest, Intersect) {
@@ -173,43 +172,39 @@ TEST_F(ConstantRangeListTest, Intersect) {
// No intersection.
ConstantRangeList Empty;
- EXPECT_TRUE(CRL.intersectWith(Empty) == Empty);
- EXPECT_TRUE(Empty.intersectWith(CRL) == Empty);
+ EXPECT_EQ(CRL.intersectWith(Empty), Empty);
+ EXPECT_EQ(Empty.intersectWith(CRL), Empty);
- EXPECT_TRUE(CRL.intersectWith(GetCRL({{APN2, AP0}})) == Empty);
- EXPECT_TRUE(CRL.intersectWith(GetCRL({{AP6, AP8}})) == Empty);
- EXPECT_TRUE(CRL.intersectWith(GetCRL({{AP12, AP16}})) == Empty);
+ EXPECT_EQ(CRL.intersectWith(GetCRL({{APN2, AP0}})), Empty);
+ EXPECT_EQ(CRL.intersectWith(GetCRL({{AP6, AP8}})), Empty);
+ EXPECT_EQ(CRL.intersectWith(GetCRL({{AP12, AP16}})), Empty);
// Single intersect range.
- EXPECT_TRUE(CRL.intersectWith(GetCRL({{APN2, AP2}})) == GetCRL({{AP0, AP2}}));
- EXPECT_TRUE(CRL.intersectWith(GetCRL({{APN2, AP6}})) == GetCRL({{AP0, AP4}}));
- EXPECT_TRUE(CRL.intersectWith(GetCRL({{AP2, AP4}})) == GetCRL({{AP2, AP4}}));
- EXPECT_TRUE(CRL.intersectWith(GetCRL({{AP2, AP6}})) == GetCRL({{AP2, AP4}}));
- EXPECT_TRUE(CRL.intersectWith(GetCRL({{AP6, AP10}})) ==
- GetCRL({{AP8, AP10}}));
- EXPECT_TRUE(CRL.intersectWith(GetCRL({{AP6, AP16}})) ==
- GetCRL({{AP8, AP12}}));
- EXPECT_TRUE(CRL.intersectWith(GetCRL({{AP10, AP12}})) ==
- GetCRL({{AP10, AP12}}));
- EXPECT_TRUE(CRL.intersectWith(GetCRL({{AP10, AP16}})) ==
- GetCRL({{AP10, AP12}}));
+ EXPECT_EQ(CRL.intersectWith(GetCRL({{APN2, AP2}})), GetCRL({{AP0, AP2}}));
+ EXPECT_EQ(CRL.intersectWith(GetCRL({{APN2, AP6}})), GetCRL({{AP0, AP4}}));
+ EXPECT_EQ(CRL.intersectWith(GetCRL({{AP2, AP4}})), GetCRL({{AP2, AP4}}));
+ EXPECT_EQ(CRL.intersectWith(GetCRL({{AP2, AP6}})), GetCRL({{AP2, AP4}}));
+ EXPECT_EQ(CRL.intersectWith(GetCRL({{AP6, AP10}})), GetCRL({{AP8, AP10}}));
+ EXPECT_EQ(CRL.intersectWith(GetCRL({{AP6, AP16}})), GetCRL({{AP8, AP12}}));
+ EXPECT_EQ(CRL.intersectWith(GetCRL({{AP10, AP12}})), GetCRL({{AP10, AP12}}));
+ EXPECT_EQ(CRL.intersectWith(GetCRL({{AP10, AP16}})), GetCRL({{AP10, AP12}}));
// Multiple intersect ranges.
- EXPECT_TRUE(CRL.intersectWith(GetCRL({{APN2, AP10}})) ==
- GetCRL({{AP0, AP4}, {AP8, AP10}}));
- EXPECT_TRUE(CRL.intersectWith(GetCRL({{APN2, AP16}})) == CRL);
- EXPECT_TRUE(CRL.intersectWith(GetCRL({{AP2, AP10}})) ==
- GetCRL({{AP2, AP4}, {AP8, AP10}}));
- EXPECT_TRUE(CRL.intersectWith(GetCRL({{AP2, AP16}})) ==
- GetCRL({{AP2, AP4}, {AP8, AP12}}));
- EXPECT_TRUE(CRL.intersectWith(GetCRL({{{APN2, AP2}, {AP6, AP10}}})) ==
- GetCRL({{AP0, AP2}, {AP8, AP10}}));
- EXPECT_TRUE(CRL.intersectWith(GetCRL({{{AP2, AP6}, {AP10, AP16}}})) ==
- GetCRL({{AP2, AP4}, {AP10, AP12}}));
- EXPECT_TRUE(
- CRL.intersectWith(GetCRL({{{APN2, AP2}, {AP7, AP10}, {AP11, AP16}}})) ==
+ EXPECT_EQ(CRL.intersectWith(GetCRL({{APN2, AP10}})),
+ GetCRL({{AP0, AP4}, {AP8, AP10}}));
+ EXPECT_EQ(CRL.intersectWith(GetCRL({{APN2, AP16}})), CRL);
+ EXPECT_EQ(CRL.intersectWith(GetCRL({{AP2, AP10}})),
+ GetCRL({{AP2, AP4}, {AP8, AP10}}));
+ EXPECT_EQ(CRL.intersectWith(GetCRL({{AP2, AP16}})),
+ GetCRL({{AP2, AP4}, {AP8, AP12}}));
+ EXPECT_EQ(CRL.intersectWith(GetCRL({{{APN2, AP2}, {AP6, AP10}}})),
+ GetCRL({{AP0, AP2}, {AP8, AP10}}));
+ EXPECT_EQ(CRL.intersectWith(GetCRL({{{AP2, AP6}, {AP10, AP16}}})),
+ GetCRL({{AP2, AP4}, {AP10, AP12}}));
+ EXPECT_EQ(
+ CRL.intersectWith(GetCRL({{{APN2, AP2}, {AP7, AP10}, {AP11, AP16}}})),
GetCRL({{AP0, AP2}, {AP8, AP10}, {AP11, AP12}}));
- EXPECT_TRUE(CRL.intersectWith(CRL) == CRL);
+ EXPECT_EQ(CRL.intersectWith(CRL), CRL);
}
} // anonymous namespace
More information about the llvm-commits
mailing list