Skip to content

Commit

Permalink
[APFloat] Removed APFloat constructor which initialized to either zer…
Browse files Browse the repository at this point in the history
…o/NaN but allowed you to arbitrarily set the category of the float.

The category which an APFloat belongs to should be dependent on the
actual value that the APFloat has, not be arbitrarily passed in by the
user. This will prevent inconsistency bugs where the category and the
actual value in APFloat differ.

I also fixed up all of the references to this constructor (which were
only in LLVM).

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@185095 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
gottesmm committed Jun 27, 2013
1 parent b7110cf commit 4da2ebe
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 20 deletions.
1 change: 0 additions & 1 deletion include/llvm/ADT/APFloat.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ class APFloat {
APFloat(const fltSemantics &); // Default construct to 0.0
APFloat(const fltSemantics &, StringRef);
APFloat(const fltSemantics &, integerPart);
APFloat(const fltSemantics &, fltCategory, bool negative);
APFloat(const fltSemantics &, uninitializedTag);
APFloat(const fltSemantics &, const APInt &);
explicit APFloat(double d);
Expand Down
20 changes: 5 additions & 15 deletions lib/Support/APFloat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -795,17 +795,6 @@ APFloat::APFloat(const fltSemantics &ourSemantics, uninitializedTag tag) {
initialize(&ourSemantics);
}

APFloat::APFloat(const fltSemantics &ourSemantics,
fltCategory ourCategory, bool negative) {
initialize(&ourSemantics);
category = ourCategory;
sign = negative;
if (isFiniteNonZero())
category = fcZero;
else if (ourCategory == fcNaN)
makeNaN();
}

APFloat::APFloat(const fltSemantics &ourSemantics, StringRef text) {
initialize(&ourSemantics);
convertFromString(text, rmNearestTiesToEven);
Expand Down Expand Up @@ -2406,8 +2395,8 @@ APFloat::roundSignificandWithExponent(const integerPart *decSigParts,
excessPrecision = calcSemantics.precision - semantics->precision;
truncatedBits = excessPrecision;

APFloat decSig(calcSemantics, fcZero, sign);
APFloat pow5(calcSemantics, fcZero, false);
APFloat decSig = APFloat::getZero(calcSemantics, sign);
APFloat pow5(calcSemantics);

sigStatus = decSig.convertFromUnsignedParts(decSigParts, sigPartCount,
rmNearestTiesToEven);
Expand Down Expand Up @@ -3388,15 +3377,16 @@ APFloat APFloat::getSmallest(const fltSemantics &Sem, bool Negative) {
}

APFloat APFloat::getSmallestNormalized(const fltSemantics &Sem, bool Negative) {
APFloat Val(Sem, fcNormal, Negative);
APFloat Val(Sem, uninitialized);

// We want (in interchange format):
// sign = {Negative}
// exponent = 0..0
// significand = 10..0

Val.exponent = Sem.minExponent;
Val.zeroSignificand();
Val.sign = Negative;
Val.exponent = Sem.minExponent;
Val.significandParts()[partCountForBits(Sem.precision)-1] |=
(((integerPart) 1) << ((Sem.precision - 1) % integerPartWidth));

Expand Down
8 changes: 4 additions & 4 deletions lib/Transforms/InstCombine/InstCombineCompares.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2888,7 +2888,7 @@ Instruction *InstCombiner::FoldFCmp_IntToFP_Cst(FCmpInst &I,
if (!LHSUnsigned) {
// If the RHS value is > SignedMax, fold the comparison. This handles +INF
// and large values.
APFloat SMax(RHS.getSemantics(), APFloat::fcZero, false);
APFloat SMax(RHS.getSemantics());
SMax.convertFromAPInt(APInt::getSignedMaxValue(IntWidth), true,
APFloat::rmNearestTiesToEven);
if (SMax.compare(RHS) == APFloat::cmpLessThan) { // smax < 13123.0
Expand All @@ -2900,7 +2900,7 @@ Instruction *InstCombiner::FoldFCmp_IntToFP_Cst(FCmpInst &I,
} else {
// If the RHS value is > UnsignedMax, fold the comparison. This handles
// +INF and large values.
APFloat UMax(RHS.getSemantics(), APFloat::fcZero, false);
APFloat UMax(RHS.getSemantics());
UMax.convertFromAPInt(APInt::getMaxValue(IntWidth), false,
APFloat::rmNearestTiesToEven);
if (UMax.compare(RHS) == APFloat::cmpLessThan) { // umax < 13123.0
Expand All @@ -2913,7 +2913,7 @@ Instruction *InstCombiner::FoldFCmp_IntToFP_Cst(FCmpInst &I,

if (!LHSUnsigned) {
// See if the RHS value is < SignedMin.
APFloat SMin(RHS.getSemantics(), APFloat::fcZero, false);
APFloat SMin(RHS.getSemantics());
SMin.convertFromAPInt(APInt::getSignedMinValue(IntWidth), true,
APFloat::rmNearestTiesToEven);
if (SMin.compare(RHS) == APFloat::cmpGreaterThan) { // smin > 12312.0
Expand All @@ -2924,7 +2924,7 @@ Instruction *InstCombiner::FoldFCmp_IntToFP_Cst(FCmpInst &I,
}
} else {
// See if the RHS value is < UnsignedMin.
APFloat SMin(RHS.getSemantics(), APFloat::fcZero, false);
APFloat SMin(RHS.getSemantics());
SMin.convertFromAPInt(APInt::getMinValue(IntWidth), true,
APFloat::rmNearestTiesToEven);
if (SMin.compare(RHS) == APFloat::cmpGreaterThan) { // umin > 12312.0
Expand Down

0 comments on commit 4da2ebe

Please sign in to comment.