http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57999
Bug ID: 57999 Summary: Missed constant propagation into trampolines Product: gcc Version: 4.8.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: alexey.tourbin at gmail dot com Created attachment 30562 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=30562&action=edit mergesort.c The attached source file is a simplistic mergesort implementation (which actually works, except for the deliberate assertion failure). Its basic structure is as follows. static inline void msort(void *b, size_t n, const size_t s, int (*cmp)(), void *t) { auto void msort_rec(char *b, size_t n); void msort_rec(char *b, size_t n) { /* Copying will be inlined */ assert(__builtin_constant_p(s)); ... /* Recursively sort a1 and a2 */ msort_rec(b1, n1); msort_rec(b2, n2); ... /* Merge */ ... if (cmp(b1, b2) <= 0) { n1--; memcpy(tmp, b1, s); b1 += s; ... } msort_rec(b, n); } When the size of the element (size_t s) is a compile-time constant, the resulting code would benefit greatly from inlining per-element memcpy() calls. However, gcc fails to propagate the constant size into the trampoline - the assertion actually fails, and otherwise the resulting code is roughly 2 times slower.