From 7b4e9a1c7a24ea6b6892dc66ea6c62d3396df066 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Wed, 27 Mar 2019 19:12:09 +0000 Subject: [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 --- llvm/lib/IR/ConstantRange.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'llvm/lib/IR/ConstantRange.cpp') 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(); } -- cgit v1.2.3