diff options
author | Nikita Popov <nikita.ppv@gmail.com> | 2019-03-27 19:12:09 +0000 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2019-03-27 19:12:09 +0000 |
commit | 7b4e9a1c7a24ea6b6892dc66ea6c62d3396df066 (patch) | |
tree | f4f2628cba96d93d046e941c2fe3d2abed239809 /llvm/lib/IR/ConstantRange.cpp | |
parent | b7e213808c12967dbf9286d9d566a88a23cd20c3 (diff) | |
download | bcm5719-llvm-7b4e9a1c7a24ea6b6892dc66ea6c62d3396df066.tar.gz bcm5719-llvm-7b4e9a1c7a24ea6b6892dc66ea6c62d3396df066.zip |
[ConstantRange] Add isWrappedSet() and isUpperSignWrapped()
Split off from D59749. This adds isWrappedSet() and
isUpperSignWrapped() set with the same behavior as isSignWrappedSet()
and isUpperWrapped() for the respectively other domain.
The methods isWrappedSet() and isSignWrappedSet() will not consider
ranges of the form [X, Max] == [X, 0) and [X, SignedMax] == [X, SignedMin)
to be wrapping, while isUpperWrapped() and isUpperSignWrapped() will.
Also replace the checks in getUnsignedMin() and friends with method
calls that implement the same logic.
llvm-svn: 357112
Diffstat (limited to 'llvm/lib/IR/ConstantRange.cpp')
-rw-r--r-- | llvm/lib/IR/ConstantRange.cpp | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/llvm/lib/IR/ConstantRange.cpp b/llvm/lib/IR/ConstantRange.cpp index 896a870bf90..eda31f73473 100644 --- a/llvm/lib/IR/ConstantRange.cpp +++ b/llvm/lib/IR/ConstantRange.cpp @@ -344,6 +344,10 @@ bool ConstantRange::isEmptySet() const { return Lower == Upper && Lower.isMinValue(); } +bool ConstantRange::isWrappedSet() const { + return Lower.ugt(Upper) && !Upper.isNullValue(); +} + bool ConstantRange::isUpperWrapped() const { return Lower.ugt(Upper); } @@ -352,6 +356,10 @@ bool ConstantRange::isSignWrappedSet() const { return Lower.sgt(Upper) && !Upper.isMinSignedValue(); } +bool ConstantRange::isUpperSignWrapped() const { + return Lower.sgt(Upper); +} + APInt ConstantRange::getSetSize() const { if (isFullSet()) return APInt::getOneBitSet(getBitWidth()+1, getBitWidth()); @@ -388,19 +396,19 @@ APInt ConstantRange::getUnsignedMax() const { } APInt ConstantRange::getUnsignedMin() const { - if (isFullSet() || (isUpperWrapped() && !getUpper().isNullValue())) + if (isFullSet() || isWrappedSet()) return APInt::getMinValue(getBitWidth()); return getLower(); } APInt ConstantRange::getSignedMax() const { - if (isFullSet() || Lower.sgt(Upper)) + if (isFullSet() || isUpperSignWrapped()) return APInt::getSignedMaxValue(getBitWidth()); return getUpper() - 1; } APInt ConstantRange::getSignedMin() const { - if (isFullSet() || (Lower.sgt(Upper) && !getUpper().isMinSignedValue())) + if (isFullSet() || isSignWrappedSet()) return APInt::getSignedMinValue(getBitWidth()); return getLower(); } |