Skip to content

Commit

Permalink
[APInt] Don't call getActiveBits() in ult/ugt(uint64_t) if its a sing…
Browse files Browse the repository at this point in the history
…le word.

The compiled code already needs to check single/multi word for the countLeadingZeros call inside of getActiveBits, but it isn't able to optimize out the leadingZeros call in the single word case that can't produce a value larger than 64.

This shrank the opt binary by about 5-6k on my local x86-64 build.




git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@300798 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
topperc committed Apr 19, 2017
1 parent ef51813 commit 25d6dbf
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions include/llvm/ADT/APInt.h
Original file line number Diff line number Diff line change
Expand Up @@ -1083,7 +1083,8 @@ class LLVM_NODISCARD APInt {
///
/// \returns true if *this < RHS when considered unsigned.
bool ult(uint64_t RHS) const {
return getActiveBits() > 64 ? false : getZExtValue() < RHS;
// Only need to check active bits if not a single word.
return (isSingleWord() || getActiveBits() <= 64) && getZExtValue() < RHS;
}

/// \brief Signed less than comparison
Expand Down Expand Up @@ -1151,7 +1152,8 @@ class LLVM_NODISCARD APInt {
///
/// \returns true if *this > RHS when considered unsigned.
bool ugt(uint64_t RHS) const {
return getActiveBits() > 64 ? true : getZExtValue() > RHS;
// Only need to check active bits if not a single word.
return (!isSingleWord() && getActiveBits() > 64) || getZExtValue() > RHS;
}

/// \brief Signed greather than comparison
Expand Down

0 comments on commit 25d6dbf

Please sign in to comment.