Skip to content

Commit

Permalink
[APInt] Optimize APInt creation from uint64_t
Browse files Browse the repository at this point in the history
Summary:
This patch moves the clearUnusedBits calls into the two different initialization paths for APInt from a uint64_t. This allows the compiler to better optimize the clearing of the unused bits for the single word case. And it puts the clearing for the multi word case into the initSlowCase function to save code. In the common case of initializing with 0 this allows the clearing to be completely optimized out for the single word case.

On my local x86 build this is showing a ~45kb reduction in the size of the opt binary.

Reviewers: RKSimon, hans, majnemer, davide, MatzeB

Reviewed By: hans

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D30486

llvm-svn: 296677
  • Loading branch information
topperc committed Mar 1, 2017
1 parent d9e4464 commit f78a6f0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
7 changes: 4 additions & 3 deletions llvm/include/llvm/ADT/APInt.h
Expand Up @@ -240,11 +240,12 @@ class LLVM_NODISCARD APInt {
APInt(unsigned numBits, uint64_t val, bool isSigned = false)
: BitWidth(numBits), VAL(0) {
assert(BitWidth && "bitwidth too small");
if (isSingleWord())
if (isSingleWord()) {
VAL = val;
else
clearUnusedBits();
} else {
initSlowCase(val, isSigned);
clearUnusedBits();
}
}

/// \brief Construct an APInt of numBits width, initialized as bigVal[].
Expand Down
1 change: 1 addition & 0 deletions llvm/lib/Support/APInt.cpp
Expand Up @@ -81,6 +81,7 @@ void APInt::initSlowCase(uint64_t val, bool isSigned) {
if (isSigned && int64_t(val) < 0)
for (unsigned i = 1; i < getNumWords(); ++i)
pVal[i] = -1ULL;
clearUnusedBits();
}

void APInt::initSlowCase(const APInt& that) {
Expand Down

0 comments on commit f78a6f0

Please sign in to comment.