diff options
author | Nikita Popov <nikita.ppv@gmail.com> | 2019-04-07 17:52:40 +0000 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2019-04-07 17:52:40 +0000 |
commit | bad648a23e15829a7210cd194e3d3f3ea13a91f8 (patch) | |
tree | d67aa77ea4dd1694dffb934fd47d82bd04445b20 /llvm/lib/IR/ConstantRange.cpp | |
parent | 3db93ac5d6d05b809da1f99379f8fb4a8c27fd0a (diff) | |
download | bcm5719-llvm-bad648a23e15829a7210cd194e3d3f3ea13a91f8.tar.gz bcm5719-llvm-bad648a23e15829a7210cd194e3d3f3ea13a91f8.zip |
[ConstantRange] Add isAllNegative() and isAllNonNegative() methods
Add isAllNegative() and isAllNonNegative() methods to ConstantRange,
which determine whether all values in the constant range are
negative/non-negative.
This is useful for replacing KnownBits isNegative() and isNonNegative()
calls when changing code to use constant ranges.
Differential Revision: https://reviews.llvm.org/D60264
llvm-svn: 357871
Diffstat (limited to 'llvm/lib/IR/ConstantRange.cpp')
-rw-r--r-- | llvm/lib/IR/ConstantRange.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/llvm/lib/IR/ConstantRange.cpp b/llvm/lib/IR/ConstantRange.cpp index f07ec9d5a3f..d048b8c2ed5 100644 --- a/llvm/lib/IR/ConstantRange.cpp +++ b/llvm/lib/IR/ConstantRange.cpp @@ -389,6 +389,21 @@ ConstantRange::isSizeLargerThan(uint64_t MaxSize) const { return (Upper - Lower).ugt(MaxSize); } +bool ConstantRange::isAllNegative() const { + // Empty set is all negative, full set is not. + if (isEmptySet()) + return true; + if (isFullSet()) + return false; + + return !isUpperSignWrapped() && !Upper.isStrictlyPositive(); +} + +bool ConstantRange::isAllNonNegative() const { + // Empty and full set are automatically treated correctly. + return !isSignWrappedSet() && Lower.isNonNegative(); +} + APInt ConstantRange::getUnsignedMax() const { if (isFullSet() || isUpperWrapped()) return APInt::getMaxValue(getBitWidth()); |