Consider the following program fragment: char *p; int i; for (i=0; i<10; i++) { p = malloc(20); foo(p,i); free(p); } } The loop could be simplified into p = malloc(20); for (i=0; i<10; i++) foo(p,i); free(p); This would reduce the overhead for memory allocation considerably. A more challenging case is to change for (i=0; i<10; i++) { p = malloc(2*i+2); foo(p,i); free(p); } into p = malloc(20); for (i=0; i<10; i++) foo(p,i); free(p); because the amount of memory allocated has an upper bound. This is probably not a big win for straight C code. For languages which generate temporary arrays at runtime, such as Fortran, it could mean a significant reduction in memory management overhead.
I would think this is much more easily done in the frontend itself, which has a higher level representation so that it is much easier to hoist and reuse allocations.
(In reply to comment #1) > I would think this is much more easily done in the frontend itself, which has a > higher level representation so that it is much easier to hoist and reuse > allocations. Not really true anymore. Confirmed, related to PR 19831.
I am working on this one (well, the first testcase kind).
you know stack one
Any work being done on this?
Just thought to see if this has been fixed in the meantime; it's not optimized with current trunk.