https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91901
Richard Biener <rguenth at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |missed-optimization Status|UNCONFIRMED |NEW Last reconfirmed| |2019-09-26 Summary|constexpr stack array not |unchanged stack array not |optimized away |optimized away in favor off | |constant pool entry Ever confirmed|0 |1 --- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> --- The compiler doesn't know that printf doesn't modify the data you pass it to so it cannot elide the automatic variable. The .rodata is just to optimize the local initializer. While we could tell the compiler I believe we don't have a late pass eliding the local aggregate for the constant pool entry either, thus confirmed. C testcase with the compiler knowing 'a' isn't modified: int __attribute__((pure)) foo (const int *); int bar() { int a[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 }; return foo (a); } even better if it worked for smaller initializers that are inlined as well (that necessarily would involve not inlining it during gimplification).