<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - Poor constexpr performance vs gcc"
   href="http://llvm.org/bugs/show_bug.cgi?id=15552">15552</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Poor constexpr performance vs gcc
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>3.2
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>C++11
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>antoinep92@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>dgregor@apple.com, llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>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");</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>