From: Craig Topper Date: Fri, 16 Jun 2017 23:26:23 +0000 (+0000) Subject: [ConstantRange] Implement getSignedMin/Max in a less complicated and faster way X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3cea3b1894d77b6cd61eef6b3ea1dbbccbe62994;p=llvm [ConstantRange] Implement getSignedMin/Max in a less complicated and faster way 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 --- diff --git a/lib/IR/ConstantRange.cpp b/lib/IR/ConstantRange.cpp index 21d1996ef85..5f44af20635 100644 --- a/lib/IR/ConstantRange.cpp +++ b/lib/IR/ConstantRange.cpp @@ -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(); }