Change APInt comparison with uint64_t.

Summary:
This patch changes the way APInt is compared with a value of type uint64_t.
Before the uint64_t value was truncated to the size of APInt before comparison.
Now the comparison takes into account full 64-bit precision.

Test Plan: Unit tests added. No regressions. Self-hosted check-all done as well.

Reviewers: chandlerc, dexonsmith

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D10655

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241204 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Pawel Bylica
2015-07-01 22:56:43 +00:00
parent 3c76e5f588
commit c098b6e6e2
2 changed files with 140 additions and 5 deletions

View File

@@ -1038,7 +1038,9 @@ public:
/// the validity of the less-than relationship.
///
/// \returns true if *this < RHS when considered unsigned.
bool ult(uint64_t RHS) const { return ult(APInt(getBitWidth(), RHS)); }
bool ult(uint64_t RHS) const {
return getActiveBits() > 64 ? false : getZExtValue() < RHS;
}
/// \brief Signed less than comparison
///
@@ -1054,7 +1056,9 @@ public:
/// the validity of the less-than relationship.
///
/// \returns true if *this < RHS when considered signed.
bool slt(uint64_t RHS) const { return slt(APInt(getBitWidth(), RHS)); }
bool slt(int64_t RHS) const {
return getMinSignedBits() > 64 ? isNegative() : getSExtValue() < RHS;
}
/// \brief Unsigned less or equal comparison
///
@@ -1102,7 +1106,9 @@ public:
/// the validity of the greater-than relationship.
///
/// \returns true if *this > RHS when considered unsigned.
bool ugt(uint64_t RHS) const { return ugt(APInt(getBitWidth(), RHS)); }
bool ugt(uint64_t RHS) const {
return getActiveBits() > 64 ? true : getZExtValue() > RHS;
}
/// \brief Signed greather than comparison
///
@@ -1118,7 +1124,9 @@ public:
/// the validity of the greater-than relationship.
///
/// \returns true if *this > RHS when considered signed.
bool sgt(uint64_t RHS) const { return sgt(APInt(getBitWidth(), RHS)); }
bool sgt(int64_t RHS) const {
return getMinSignedBits() > 64 ? !isNegative() : getSExtValue() > RHS;
}
/// \brief Unsigned greater or equal comparison
///
@@ -1150,7 +1158,7 @@ public:
/// the validity of the greater-or-equal relationship.
///
/// \returns true if *this >= RHS when considered signed.
bool sge(uint64_t RHS) const { return !slt(RHS); }
bool sge(int64_t RHS) const { return !slt(RHS); }
/// This operation tests if there are any pairs of corresponding bits
/// between this APInt and RHS that are both set.