[llvm] Add ConstantRangeList::unionWith() and ::intersectWith() (PR #96547)

Jan Voung via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 25 10:20:52 PDT 2024


================
@@ -81,6 +81,97 @@ void ConstantRangeList::insert(const ConstantRange &NewRange) {
   }
 }
 
+ConstantRangeList
+ConstantRangeList::unionWith(const ConstantRangeList &CRL) const {
+  assert(getBitWidth() == CRL.getBitWidth() &&
+         "ConstantRangeList bitwidths don't agree!");
+  // Handle common cases.
+  if (empty())
+    return CRL;
+  if (CRL.empty())
+    return *this;
+
+  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
----------------
jvoung wrote:

nit: might not need to mention the "If ... cannot contain a new ...", since it's elaborated below where it happens.

For above, could emphasize that ""PreviousRange" tracks the *lowest* unioned range *that is being processed*..." ?

https://github.com/llvm/llvm-project/pull/96547


More information about the llvm-commits mailing list