Implement unionWith.
authorNick Lewycky <nicholas@mxc.ca>
Fri, 2 Mar 2007 03:33:05 +0000 (03:33 +0000)
committerNick Lewycky <nicholas@mxc.ca>
Fri, 2 Mar 2007 03:33:05 +0000 (03:33 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34833 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Support/ConstantRange.cpp

index ce4a25325a40cd4017b11d3a27faea1d58f2ac9e..410c351890c79f060e0121c169f6ecdf4a87f14e 100644 (file)
@@ -194,9 +194,18 @@ ConstantRange ConstantRange::unionWith(const ConstantRange &CR) const {
   assert(getBitWidth() == CR.getBitWidth() && 
          "ConstantRange types don't agree!");
 
-  assert(0 && "Range union not implemented yet!");
+  if (   isFullSet() || CR.isEmptySet()) return *this;
+  if (CR.isFullSet() ||    isEmptySet()) return CR;
 
-  return *this;
+  APInt L = Lower, U = Upper;
+
+  if (!contains(CR.Lower))
+    L = APIntOps::umin(L, CR.Lower);
+
+  if (!contains(CR.Upper - 1))
+    U = APIntOps::umax(U, CR.Upper);
+
+  return ConstantRange(L, U);
 }
 
 /// zeroExtend - Return a new range in the specified integer type, which must