This is an archive of the discontinued LLVM Phabricator instance.

Use a faster implementation of maxUIntN.
ClosedPublic

Authored by jlebar on Jul 16 2016, 3:17 PM.

Details

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

Diff Detail

Repository
rL LLVM

Event Timeline

jlebar updated this revision to Diff 64232.Jul 16 2016, 3:17 PM
jlebar retitled this revision from to Use a faster implementation of maxUIntN..
jlebar updated this object.
jlebar added a reviewer: rnk.
jlebar added subscribers: llvm-commits, mkuper, dylanmckay.
majnemer accepted this revision.Jul 16 2016, 6:13 PM
majnemer added a reviewer: majnemer.
majnemer added a subscriber: majnemer.

LGTM with nits.

include/llvm/Support/MathExtras.h
323 ↗(On Diff #64232)

~UINT64_C(0) could be written as UINT_MAX

This revision is now accepted and ready to land.Jul 16 2016, 6:13 PM
jlebar updated this revision to Diff 64240.Jul 16 2016, 11:09 PM
jlebar marked an inline comment as done.
jlebar edited edge metadata.

Use UINT64_MAX.

include/llvm/Support/MathExtras.h
323 ↗(On Diff #64232)

Oh. That is better.

Thank you for the review!

This revision was automatically updated to reflect the committed changes.
krasin added a subscriber: krasin.Jul 18 2016, 9:55 AM

FYI: this made UBSan bot unhappy: http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fast/builds/14727/steps/check-llvm%20ubsan/logs/stdio

[ RUN      ] MathExtras.minIntN
/mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm/include/llvm/Support/MathExtras.h:340:10: runtime error: negation of -9223372036854775808 cannot be represented in type 'long'; cast to an unsigned type to negate this value to itself
    #0 0x4fb9e3 in llvm::minIntN(long) /mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm/include/llvm/Support/MathExtras.h:340:10

this made UBSan bot unhappy

FYI I think it was probably the patch I checked in to add tests for minIntN, D22443. Hooray for tests.