[PATCH] D34471: [Inliner] Boost inlining of an indirect call to always_inline function.
Chandler Carruth via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 22 14:35:54 PDT 2017
chandlerc added a comment.
FWIW, I'm not really a fan of this behavior in the inliner.
I know the test case that motivates this, and as was discussed previously I suspect using a template argument would be better. I think this is actually a general pattern we can recommend rather than using alway_inline for this:
__attribute__((always_inline)) inline void f(int, int) {
volatile int x;
x = 42; x = 42; x = 42; x = 42;
}
template <typename FunctionT, FunctionT *Function>
void g(int *a, int *b, int count) {
for (int i = 0; i < count; ++i)
Function(a[i], b[i]);
}
void h(int *a, int *b, int count) {
g<decltype(f), f>(a, b, count);
}
Even at `-O0` this doesn't allows the `always_inline` to have its effect: https://godbolt.org/g/S4HzTD
It also makes it explicit in the source code that the programmer *wants* code duplication. For something this powerful, that seems like the right general approach.
https://reviews.llvm.org/D34471
More information about the llvm-commits
mailing list