This is an archive of the discontinued LLVM Phabricator instance.

Add bitreverse LNT benchmark.
ClosedPublic

Authored by jtony on Jul 9 2017, 4:18 PM.

Details

Summary

This patch implements a performance regression test for bit reverse. The bit reverse algorithm on PPC was O(N) and had lots of dependency between contiguous instructions. We replace it with a faster O(lgN) algorithm in the following two patches:
https://reviews.llvm.org/D33572
https://reviews.llvm.org/D34908
This test case tests both the 32-bit and 64-bit bit reverse to ensure the new implementation is functionally correct and has a better performance.

For this specific benchmark, it is 3x faster with patches D33572 and D34908 (0.574s) than without them (1.919s).
[jtony@moose1 ~]$ time ./new.out
Sum1 = 0, Sum2 = feff800000800000
real 0m0.574s
user 0m0.574s
sys 0m0.000s
[jtony@moose1 ~]$ time ./old.out
Sum1 = 0, Sum2 = feff800000800000
real 0m1.919s
user 0m1.919s
sys 0m0.000s

This patch is requested by Hal Finkel.

Diff Detail

Repository
rL LLVM

Event Timeline

jtony created this revision.Jul 9 2017, 4:18 PM
jtony edited the summary of this revision. (Show Details)Jul 10 2017, 6:48 AM
nemanjai added inline comments.Jul 10 2017, 1:13 PM
SingleSource/Benchmarks/Misc/CMakeLists.txt
26 ↗(On Diff #105798)

I don't follow why the name is revertBits when what you're doing is reversing the bits.

SingleSource/Benchmarks/Misc/revertBits.c
12 ↗(On Diff #105798)

We had equivalently poor code gen for __builtin_bitreverse<N>. Don't we want this in the test case as well?

jtony updated this revision to Diff 105907.EditedJul 10 2017, 1:16 PM

(1) Also test builtin_bitreverse32 and builtin_bitreverse64.
(2) Add the missing newline at the end of the second printf.

jtony marked an inline comment as done.Jul 10 2017, 1:16 PM
jtony added inline comments.
SingleSource/Benchmarks/Misc/revertBits.c
12 ↗(On Diff #105798)

Yes, we want that too, it is added in the new patch.

jtony marked 2 inline comments as done.Jul 10 2017, 1:18 PM
jtony added a comment.Jul 24 2017, 1:09 PM

Kindly ping.

hfinkel added inline comments.Aug 5 2017, 1:57 PM
SingleSource/Benchmarks/Misc/revertBits.c
35 ↗(On Diff #105907)

Are you sure this doesn't signed overflow? Should we make this unsigned to avoid the possibility of UB.

37 ↗(On Diff #105907)

The test suite is used with compilers other than Clang. You should guard this with __has_builtin using the pattern detailed here: https://clang.llvm.org/docs/LanguageExtensions.html#feature-checking-macros (it's probably fine for the test to just exit 0 if we're on a compiler without the builtin)

jtony marked 2 inline comments as done.Aug 13 2017, 7:23 AM
jtony updated this revision to Diff 110901.Aug 13 2017, 6:19 PM

Address comments from Hal Finkel.

hfinkel added inline comments.Aug 14 2017, 10:34 AM
SingleSource/Benchmarks/Misc/revertBits.c
37 ↗(On Diff #110901)

You need to put:

#ifndef __has_builtin
#define __has_builtin(x) 0
#endif

before this (or else this won't work with compilers that don't support __has_builtin).

jtony updated this revision to Diff 111068.Aug 14 2017, 2:01 PM

Address one more new comment from Hal (add check for compilers that don't support __has_builtin)

jtony marked an inline comment as done.Aug 14 2017, 2:01 PM
hfinkel accepted this revision.Aug 15 2017, 8:53 PM

LGTM

This revision is now accepted and ready to land.Aug 15 2017, 8:53 PM
This revision was automatically updated to reflect the committed changes.