[llvm] Add ConstantRangeList::unionWith() and ::intersectWith() (PR #96547)
Arthur Eubanks via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 24 14:45:11 PDT 2024
================
@@ -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");
----------------
aeubanks wrote:
these asserts should probably go into wherever we're adding a ConstantRange to a ConstantRangeList, rather than sprinkled throughout various other methods. then we can assume that this invariant holds for existing ConstantRangeLists and don't need extra asserts
https://github.com/llvm/llvm-project/pull/96547
More information about the llvm-commits
mailing list