[llvm-bugs] [Bug 39353] New: Exorbitant compile times

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Oct 19 04:14:41 PDT 2018


https://bugs.llvm.org/show_bug.cgi?id=39353

            Bug ID: 39353
           Summary: Exorbitant compile times
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: lumosimann at gmail.com
                CC: dgregor at apple.com, llvm-bugs at lists.llvm.org

I was just experimenting a bit and realized that cache might miss some cache
opportunities:

```
#include <iostream>
#include <tuple>
#include <type_traits>

template <size_t I0, size_t... I>
struct Recursion {
    using type = std::tuple<
        typename Recursion<I0 - 1, I - 1, I - 1, I - 1, I - 1>::type...>;
};
template <size_t... I>
struct Recursion<0, I...> {
    using type = std::integral_constant<int, 0>;
};

template <std::size_t I, typename T>
struct SomeWrapper {
    using type = std::tuple_element_t<0, T>;
};

template <size_t I>
using ComplexType = typename Recursion<I, I, I, I, I>::type;

struct SimpleType {
    using type = int;
};

template <typename T>
struct Concept : std::bool_constant<std::tuple_size_v<typename T::type> != 4> {
};

template <typename T>
std::enable_if_t<Concept<T>::value, int> g(T) {
    return 3;
}
template <typename T>
std::enable_if_t<!Concept<T>::value, int> g(T) {
    return 3;
}

template <std::size_t... Is>
int f(std::index_sequence<Is...>) {
    return (... + g(SomeWrapper<Is, ComplexType<9>>{}));
}

int main() {
    std::cout << f(std::make_index_sequence<200>()) << std::endl;
    return 0;
}
```

Compilation time for this code scales linearly with Clang (linear in terms
ofthe number in `make_index_sequence`), but remains constant for gcc. 

The whole thing is just setting up a huge type that is used in SFiNAE for
evaluating g. It looks like Concept<T> is not cached during consecutive calls
to g.

-- 
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/20181019/74807aa5/attachment-0001.html>


More information about the llvm-bugs mailing list