diff --git a/include/llvm/IR/ConstantRange.h b/include/llvm/IR/ConstantRange.h index c6d76827f4f..6a50a8801f8 100644 --- a/include/llvm/IR/ConstantRange.h +++ b/include/llvm/IR/ConstantRange.h @@ -169,6 +169,9 @@ public: /// Compare set size of this range with the range CR. bool isSizeStrictlySmallerThan(const ConstantRange &CR) const; + // Compare set size of this range with Value. + bool isSizeLargerThan(uint64_t MaxSize) const; + /// Return the largest unsigned value contained in the ConstantRange. APInt getUnsignedMax() const; diff --git a/lib/IR/ConstantRange.cpp b/lib/IR/ConstantRange.cpp index cb703f6efc6..aeb1257754f 100644 --- a/lib/IR/ConstantRange.cpp +++ b/lib/IR/ConstantRange.cpp @@ -260,6 +260,17 @@ ConstantRange::isSizeStrictlySmallerThan(const ConstantRange &Other) const { return (Upper - Lower).ult(Other.Upper - Other.Lower); } +bool +ConstantRange::isSizeLargerThan(uint64_t MaxSize) const { + assert(MaxSize && "MaxSize can't be 0."); + // If this a full set, we need special handling to avoid needing an extra bit + // to represent the size. + if (isFullSet()) + return APInt::getMaxValue(getBitWidth()).ugt(MaxSize - 1); + + return (Upper - Lower).ugt(MaxSize); +} + APInt ConstantRange::getUnsignedMax() const { if (isFullSet() || isWrappedSet()) return APInt::getMaxValue(getBitWidth()); diff --git a/lib/Transforms/Utils/SimplifyCFG.cpp b/lib/Transforms/Utils/SimplifyCFG.cpp index 7a3e8b9ae91..b44bc74d655 100644 --- a/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/lib/Transforms/Utils/SimplifyCFG.cpp @@ -596,7 +596,7 @@ private: Span = Span.inverse(); // If there are a ton of values, we don't want to make a ginormous switch. - if (Span.getSetSize().ugt(8) || Span.isEmptySet()) { + if (Span.isSizeLargerThan(8) || Span.isEmptySet()) { return false; }