[llvm] Add ConstantRangeList::subtract(ConstantRange) (PR #97093)
Jan Voung via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 28 12:28:44 PDT 2024
================
@@ -81,6 +81,65 @@ void ConstantRangeList::insert(const ConstantRange &NewRange) {
}
}
+void ConstantRangeList::subtract(const ConstantRange &SubRange) {
+ if (SubRange.isEmptySet())
+ return;
+ assert(!SubRange.isFullSet() && "Do not support full set");
+ assert(SubRange.getLower().slt(SubRange.getUpper()));
+ assert(getBitWidth() == SubRange.getBitWidth());
+ // Handle common cases.
+ if (empty() || Ranges.back().getUpper().sle(SubRange.getLower())) {
+ return;
+ }
+ if (SubRange.getUpper().sle(Ranges.front().getLower())) {
+ return;
+ }
+
+ SmallVector<ConstantRange, 2> Result;
+ auto AppendRange = [&Result](APInt Start, APInt End) {
+ if (Start.slt(End))
----------------
jvoung wrote:
might be helpful to have brief comment "append new range if not empty" (was initially less clear why the slt check)
https://github.com/llvm/llvm-project/pull/97093
More information about the llvm-commits
mailing list