]> granicus.if.org Git - llvm/commitdiff
[ConstantRange] Implement getSignedMin/Max in a less complicated and faster way
authorCraig Topper <craig.topper@intel.com>
Fri, 16 Jun 2017 23:26:23 +0000 (23:26 +0000)
committerCraig Topper <craig.topper@intel.com>
Fri, 16 Jun 2017 23:26:23 +0000 (23:26 +0000)
Summary: As far as I can tell we should be able to implement these almost the same way we do unsigned, but using signed comparisons and checks for min signed value instead of min unsigned value.

Reviewers: pete, davide, sanjoy

Reviewed By: davide

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D33815

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@305607 91177308-0d34-0410-b5e6-96231b3b80d8

lib/IR/ConstantRange.cpp

index 21d1996ef85145d367b0a11530933d67cbd9a824..5f44af206355d7de6a4382351852c363a339af93 100644 (file)
@@ -284,27 +284,14 @@ APInt ConstantRange::getUnsignedMin() const {
 }
 
 APInt ConstantRange::getSignedMax() const {
-  if (!isWrappedSet()) {
-    APInt UpperMinusOne = getUpper() - 1;
-    if (getLower().sle(UpperMinusOne))
-      return UpperMinusOne;
-    return APInt::getSignedMaxValue(getBitWidth());
-  }
-  if (getLower().isNegative() == getUpper().isNegative())
+  if (isFullSet() || Lower.sgt(Upper))
     return APInt::getSignedMaxValue(getBitWidth());
   return getUpper() - 1;
 }
 
 APInt ConstantRange::getSignedMin() const {
-  if (!isWrappedSet()) {
-    if (getLower().sle(getUpper() - 1))
-      return getLower();
+  if (isFullSet() || (Lower.sgt(Upper) && !getUpper().isMinSignedValue()))
     return APInt::getSignedMinValue(getBitWidth());
-  }
-  if ((getUpper() - 1).slt(getLower())) {
-    if (!getUpper().isMinSignedValue())
-      return APInt::getSignedMinValue(getBitWidth());
-  }
   return getLower();
 }