[llvm] r300621 - [ConstantRange] Optimize APInt creation in getSignedMax/getSignedMin.
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 18 16:02:41 PDT 2017
Author: ctopper
Date: Tue Apr 18 18:02:39 2017
New Revision: 300621
URL: http://llvm.org/viewvc/llvm-project?rev=300621&view=rev
Log:
[ConstantRange] Optimize APInt creation in getSignedMax/getSignedMin.
We were creating an APInt at the top of these methods that isn't always returned. For ranges wider than 64-bits this results in an allocation and deallocation when its not used.
In getSignedMax we were creating Upper-1 to use in a compare and then creating it again for a return value. The compiler is unable to determine that these can be shared. So help it out and create the Upper-1 in a temporary that can be reused.
This provides a little compile time improvement.
Modified:
llvm/trunk/lib/IR/ConstantRange.cpp
Modified: llvm/trunk/lib/IR/ConstantRange.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/ConstantRange.cpp?rev=300621&r1=300620&r2=300621&view=diff
==============================================================================
--- llvm/trunk/lib/IR/ConstantRange.cpp (original)
+++ llvm/trunk/lib/IR/ConstantRange.cpp Tue Apr 18 18:02:39 2017
@@ -281,25 +281,25 @@ APInt ConstantRange::getUnsignedMin() co
APInt ConstantRange::getSignedMax() const {
APInt SignedMax(APInt::getSignedMaxValue(getBitWidth()));
if (!isWrappedSet()) {
- if (getLower().sle(getUpper() - 1))
- return getUpper() - 1;
- return SignedMax;
+ APInt UpperMinusOne = getUpper() - 1;
+ if (getLower().sle(UpperMinusOne))
+ return UpperMinusOne;
+ return APInt::getSignedMaxValue(getBitWidth());
}
if (getLower().isNegative() == getUpper().isNegative())
- return SignedMax;
+ return APInt::getSignedMaxValue(getBitWidth());
return getUpper() - 1;
}
APInt ConstantRange::getSignedMin() const {
- APInt SignedMin(APInt::getSignedMinValue(getBitWidth()));
if (!isWrappedSet()) {
if (getLower().sle(getUpper() - 1))
return getLower();
- return SignedMin;
+ return APInt::getSignedMinValue(getBitWidth());
}
if ((getUpper() - 1).slt(getLower())) {
- if (getUpper() != SignedMin)
- return SignedMin;
+ if (!getUpper().isMinSignedValue())
+ return APInt::getSignedMinValue(getBitWidth());
}
return getLower();
}
More information about the llvm-commits
mailing list