[llvm-bugs] [Bug 25729] clang 300x slower to compile recursive constexpr template vs. gcc
via llvm-bugs
llvm-bugs at lists.llvm.org
Thu Dec 3 14:20:02 PST 2015
https://llvm.org/bugs/show_bug.cgi?id=25729
Richard Smith <richard-llvm at metafoo.co.uk> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution|--- |DUPLICATE
--- Comment #2 from Richard Smith <richard-llvm at metafoo.co.uk> ---
The code is obviously exponential-time in Index:
template <unsigned Index>
constexpr unsigned crc32 (char const * str) {
unsigned const a = crc32 <Index - 1> (str) >> 8;
unsigned const b = crc32 <Index - 1> (str) ^ str [Index - 1];
return a ^ crc_table [b & 0x000000FF];
}
Don't compute crc32<Index - 1>(str) twice, compute it once and reuse the
result.
I don't know why people expect to get asymptotic performance improvements by
slapping 'constexpr' on their functions, and I'm not convinced GCC's
memoization is doing anyone any favours here -- if we or GCC choose to evaluate
the initializer at runtime (as we are permitted to do), it will also be
extremely slow (in a -O0 build at least), due to the use of a ridiculous
exponential-time algorithm.
*** This bug has been marked as a duplicate of bug 12850 ***
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20151203/6a198031/attachment.html>
More information about the llvm-bugs
mailing list