aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Support
diff options
context:
space:
mode:
authorNick Lewycky <nicholas@mxc.ca>2009-07-18 06:34:42 +0000
committerNick Lewycky <nicholas@mxc.ca>2009-07-18 06:34:42 +0000
commit50695f139ae372c9949dfddce603c83f49377b99 (patch)
tree1e69e339c818903ac78cd8ed80335c25c1a5f5d7 /lib/Support
parentf32df06245b31a8c6d7336bb40ba0602b0bf2f8a (diff)
downloadexternal_llvm-50695f139ae372c9949dfddce603c83f49377b99.zip
external_llvm-50695f139ae372c9949dfddce603c83f49377b99.tar.gz
external_llvm-50695f139ae372c9949dfddce603c83f49377b99.tar.bz2
Replace intersectWith with maximalIntersectWith. The latter guarantees that
all values belonging to the intersection will belong to the resulting range. The former was inconsistent about that point (either way is fine, just pick one.) This is part of PR4545. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@76289 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support')
-rw-r--r--lib/Support/ConstantRange.cpp48
1 files changed, 5 insertions, 43 deletions
diff --git a/lib/Support/ConstantRange.cpp b/lib/Support/ConstantRange.cpp
index 4cb54bd..5f3d6f8 100644
--- a/lib/Support/ConstantRange.cpp
+++ b/lib/Support/ConstantRange.cpp
@@ -275,58 +275,20 @@ ConstantRange::intersect1Wrapped(const ConstantRange &LHS,
}
/// intersectWith - Return the range that results from the intersection of this
-/// range with another range.
-///
+/// range with another range. The resultant range is guaranteed to include all
+/// elements contained in both input ranges, and to have the smallest possible
+/// set size that does so. Because there may be two intersections with the
+/// same set size, A.intersectWith(B) might not be equal to B.intersectWith(A).
ConstantRange ConstantRange::intersectWith(const ConstantRange &CR) const {
assert(getBitWidth() == CR.getBitWidth() &&
"ConstantRange types don't agree!");
- // Handle common special cases
- if (isEmptySet() || CR.isFullSet())
- return *this;
- if (isFullSet() || CR.isEmptySet())
- return CR;
-
- if (!isWrappedSet()) {
- if (!CR.isWrappedSet()) {
- APInt L = APIntOps::umax(Lower, CR.Lower);
- APInt U = APIntOps::umin(Upper, CR.Upper);
-
- if (L.ult(U)) // If range isn't empty...
- return ConstantRange(L, U);
- else
- return ConstantRange(getBitWidth(), false);// Otherwise, empty set
- } else
- return intersect1Wrapped(CR, *this);
- } else { // We know "this" is wrapped...
- if (!CR.isWrappedSet())
- return intersect1Wrapped(*this, CR);
- else {
- // Both ranges are wrapped...
- APInt L = APIntOps::umax(Lower, CR.Lower);
- APInt U = APIntOps::umin(Upper, CR.Upper);
- return ConstantRange(L, U);
- }
- }
- return *this;
-}
-
-/// maximalIntersectWith - Return the range that results from the intersection
-/// of this range with another range. The resultant range is guaranteed to
-/// include all elements contained in both input ranges, and to have the
-/// smallest possible set size that does so. Because there may be two
-/// intersections with the same set size, A.maximalIntersectWith(B) might not
-/// be equal to B.maximalIntersect(A).
-ConstantRange
-ConstantRange::maximalIntersectWith(const ConstantRange &CR) const {
- assert(getBitWidth() == CR.getBitWidth() &&
- "ConstantRange types don't agree!");
// Handle common cases.
if ( isEmptySet() || CR.isFullSet()) return *this;
if (CR.isEmptySet() || isFullSet()) return CR;
if (!isWrappedSet() && CR.isWrappedSet())
- return CR.maximalIntersectWith(*this);
+ return CR.intersectWith(*this);
if (!isWrappedSet() && !CR.isWrappedSet()) {
if (Lower.ult(CR.Lower)) {