summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
authorJustin Lebar <jlebar@google.com>2016-07-17 18:19:19 +0000
committerJustin Lebar <jlebar@google.com>2016-07-17 18:19:19 +0000
commitf2d0066af751cf097a17e970e825475cb06be5bf (patch)
tree0610aa109d566b71d42175f7230f5dbb5771ad06 /llvm
parentb17269da754bfe8fba0e9342a4460a893f7c1259 (diff)
downloadbcm5719-llvm-f2d0066af751cf097a17e970e825475cb06be5bf.tar.gz
bcm5719-llvm-f2d0066af751cf097a17e970e825475cb06be5bf.zip
Use a faster implementation of maxUIntN.
Summary: On x86-64 with clang 3.8, before: mov edx, 1 mov cl, dil shl rdx, cl cmp rdi, 64 mov rax, -1 cmovne rax, rdx ret after: mov ecx, 64 sub ecx, edi mov rax, -1 shr rax, cl ret Reviewers: rnk Subscribers: dylanmckay, mkuper, llvm-commits Differential Revision: https://reviews.llvm.org/D22440 llvm-svn: 275718
Diffstat (limited to 'llvm')
-rw-r--r--llvm/include/llvm/Support/MathExtras.h9
1 files changed, 5 insertions, 4 deletions
diff --git a/llvm/include/llvm/Support/MathExtras.h b/llvm/include/llvm/Support/MathExtras.h
index b60732a9b34..e9930f68d7c 100644
--- a/llvm/include/llvm/Support/MathExtras.h
+++ b/llvm/include/llvm/Support/MathExtras.h
@@ -316,10 +316,11 @@ inline bool isShiftedUInt(uint64_t x) {
inline uint64_t maxUIntN(uint64_t N) {
assert(N > 0 && N <= 64 && "integer width out of range");
- // uint64_t(1) << 64 is undefined behavior.
- if (N == 64)
- return std::numeric_limits<uint64_t>::max();
- return (UINT64_C(1) << N) - 1;
+ // uint64_t(1) << 64 is undefined behavior, so we can't do
+ // (uint64_t(1) << N) - 1
+ // without checking first that N != 64. But this works and doesn't have a
+ // branch.
+ return UINT64_MAX >> (64 - N);
}
/// Gets the minimum value for a N-bit signed integer.
OpenPOWER on IntegriCloud