Tested with gcc-4.2-20070131, with -O3 on i386. Gcc correctly writes the constants directly into the variable called "out", but it still stores its temporary result on the stack, from where it will never be read anymore.
gcc-4.1.1 DOES seem to eliminate these arrays, at least in the given example. Don't know if that qualifies as regression though... gcc-4.3-20070202 behaves the same as gcc-4.2-20070131. void test(int * out) { for (int j=0; j<4; ++j) { int tmp[4]; for (int i=0; i<4; ++i) tmp[i] = i; for (int i=0; i<4; ++i) out[i] = tmp[i]; } } -- Summary: Local arrays not eliminated by optimization Product: gcc Version: 4.2.0 Status: UNCONFIRMED Severity: enhancement Priority: P3 Component: rtl-optimization AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: stefaan dot deroeck at gmail dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30697