https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81445
Bug ID: 81445 Summary: Dynamic stack allocation not optimized into static allocation Product: gcc Version: 8.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: wilco at gcc dot gnu.org Target Milestone: --- Many compilers optimize small dynamic allocations into static allocation. This is more efficient as it allows multiple small dynamic allocations to be merged into a single static allocation. In some cases it may remove all dynamic allocations, avoiding the need for a frame pointer (which frees up an extra register on various targets in addition to reducing prolog/epilog overheads). Obviously allocations cannot be in a loop (including tail-recursion), and the total size should be limited to avoid increasing stack size by too much. void f(void*); void alloca (int x) { if (x < 100) f (__builtin_alloca (x)); f (__builtin_alloca (16)); }