[PATCH] D30486: [APInt] Optimize APInt creation from uint64_t
Craig Topper via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 28 23:51:11 PST 2017
craig.topper created this revision.
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.
https://reviews.llvm.org/D30486
Files:
include/llvm/ADT/APInt.h
lib/Support/APInt.cpp
Index: lib/Support/APInt.cpp
===================================================================
--- lib/Support/APInt.cpp
+++ lib/Support/APInt.cpp
@@ -81,6 +81,7 @@
if (isSigned && int64_t(val) < 0)
for (unsigned i = 1; i < getNumWords(); ++i)
pVal[i] = -1ULL;
+ clearUnusedBits();
}
void APInt::initSlowCase(const APInt& that) {
Index: include/llvm/ADT/APInt.h
===================================================================
--- include/llvm/ADT/APInt.h
+++ include/llvm/ADT/APInt.h
@@ -240,11 +240,11 @@
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[].
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D30486.90125.patch
Type: text/x-patch
Size: 941 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170301/1d4a8dfa/attachment.bin>
More information about the llvm-commits
mailing list