[LLVMbugs] [Bug 12750] New: clang is really bad at compiling OS X's / FreeBSD's memchr()
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Sun May 6 22:25:22 PDT 2012
http://llvm.org/bugs/show_bug.cgi?id=12750
Bug #: 12750
Summary: clang is really bad at compiling OS X's / FreeBSD's
memchr()
Product: clang
Version: trunk
Platform: PC
OS/Version: All
Status: NEW
Severity: enhancement
Priority: P
Component: LLVM Codegen
AssignedTo: unassignedclangbugs at nondot.org
ReportedBy: nicolasweber at gmx.de
CC: llvmbugs at cs.uiuc.edu
Classification: Unclassified
Created attachment 8500
--> http://llvm.org/bugs/attachment.cgi?id=8500
repro
The attached program contains a memchr() benchmark that tests two memchr()
implementations:
void* stupid_memchr(const void* s_in, int c, size_t n) {
const unsigned char* s = (const unsigned char*)s_in;
for (int i = 0; i < n; ++i)
if (s[i] == c)
return (void*)(s + i);
return NULL;
}
// FreeBSD,
// http://opensource.apple.com/source/Libc/Libc-763.12/string/memchr-fbsd.c
void *
bsd_memchr(const void *s, int c, size_t n)
{
if (n != 0) {
const unsigned char *p = (const unsigned char*)s;
do {
if (*p++ == (unsigned char)c)
return ((void *)(p - 1));
} while (--n != 0);
}
return (NULL);
}
If I compile this program with gcc 4.2, the output is (for these 2 functions
and the system memchr(), my system is OS X):
tests-MacBook-Pro-2:src test$ gcc chr_bench.cc -o chr_bench -O2
tests-MacBook-Pro-2:src test$ ./chr_bench
stupid_memchr: 391.0us
bsd_memchr: 394.0us
memchr: 563.0us
If do the same thing with clang:
tests-MacBook-Pro-2:src test$ third_party/llvm-build/Release+Asserts/bin/clang
chr_bench.cc -o chr_bench -O2
tests-MacBook-Pro-2:src test$ ./chr_bench
stupid_memchr: 375.0us
bsd_memchr: 554.0us
memchr: 552.0us
tests-MacBook-Pro-2:src test$ third_party/llvm-build/Release+Asserts/bin/clang
--version
clang version 3.2 (trunk 155352)
Target: x86_64-apple-darwin11.3.0
Thread model: posix
Note that bsd_memchr() becomes much much slower. Notice that the run time now
matches my the runtime of my system's memchr(), which was probably built by
clang.
(See also rdar 11393714)
--
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
More information about the llvm-bugs
mailing list