Skip to content
This repository has been archived by the owner on Apr 23, 2020. It is now read-only.

Commit

Permalink
[APInt] No need for a copy when taking min/max of an APInt.
Browse files Browse the repository at this point in the history
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@260827 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
d0k committed Feb 13, 2016
1 parent 34ae7b5 commit 0262597
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions include/llvm/ADT/APInt.h
Expand Up @@ -1744,16 +1744,24 @@ inline raw_ostream &operator<<(raw_ostream &OS, const APInt &I) {
namespace APIntOps {

/// \brief Determine the smaller of two APInts considered to be signed.
inline APInt smin(const APInt &A, const APInt &B) { return A.slt(B) ? A : B; }
inline const APInt &smin(const APInt &A, const APInt &B) {
return A.slt(B) ? A : B;
}

/// \brief Determine the larger of two APInts considered to be signed.
inline APInt smax(const APInt &A, const APInt &B) { return A.sgt(B) ? A : B; }
inline const APInt &smax(const APInt &A, const APInt &B) {
return A.sgt(B) ? A : B;
}

/// \brief Determine the smaller of two APInts considered to be signed.
inline APInt umin(const APInt &A, const APInt &B) { return A.ult(B) ? A : B; }
inline const APInt &umin(const APInt &A, const APInt &B) {
return A.ult(B) ? A : B;
}

/// \brief Determine the larger of two APInts considered to be unsigned.
inline APInt umax(const APInt &A, const APInt &B) { return A.ugt(B) ? A : B; }
inline const APInt &umax(const APInt &A, const APInt &B) {
return A.ugt(B) ? A : B;
}

/// \brief Check if the specified APInt has a N-bits unsigned integer value.
inline bool isIntN(unsigned N, const APInt &APIVal) { return APIVal.isIntN(N); }
Expand Down

0 comments on commit 0262597

Please sign in to comment.