http://llvm.org/bugs/show_bug.cgi?id=15552
Bug ID: 15552
Summary: Poor constexpr performance vs gcc
Product: clang
Version: 3.2
Hardware: PC
OS: Linux
Status: NEW
Severity: enhancement
Priority: P
Component: C++11
Assignee: [email protected]
Reporter: [email protected]
CC: [email protected], [email protected]
Classification: Unclassified
The following code (fibbonacci sequence at compile time) takes serveral minutes
to compile, as opposed to less than 0.1s with gcc.
Also both clang and gcc take less than 0.1s to compile the equivalent written
with templates.
I'm not familiar enough with clang internals to be sure, but I guess template
instanciation has a better cache size/strategy than constexpr recursion. Maybe
the cache in place for templates could be reused for constexpr?
To test, compile both codes bellow with
clang++ -std=c++11 -fconstexpr-depth=65536
_______________
// very, very long computation with clang but not gcc
typedef unsigned long long ul;
constexpr ul fib(ul n) { return n < 2 ? n : fib(n-2) + fib(n-1); }
static_assert(fib(93) == 12200160415121876738ul, "bad result");
_______________
// fast with both clang and gcc
typedef unsigned long long ul;
template<ul n> struct fib {
static const ul value = fib<n-2>::value + fib<n-1>::value;
};
template<> struct fib<1> {
static const ul value = 1;
};
template<> struct fib<0> {
static const ul value = 0;
};
static_assert(fib<93>::value == 12200160415121876738ul, "bad result");
--
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs