[PATCH] Implement malloc/free hoisting from loops (PR21046 and friends)

Xinliang David Li davidxl@google.com
Tue May 11 04:30:00 GMT 2010


On Mon, May 10, 2010 at 8:21 PM, Mark Mitchell <mark@codesourcery.com> wrote:
> Richard Guenther wrote:
>
>> This adds the ability to hoist/sink malloc/free pairs out of loops in
>> case the size of the allocation is loop-invariant.  This helps
>> in cases where the Fortran frontend inserts array temporary allocations
>> inside loops (which happens to cost around 4% performance in 465.tonto).
>
> Nice idea.  I don't have a comment on the patch, but the optimization
> itself would certainly seem beneficial to some programs.
>
> I never quite understand the optimization rules for built-ins in GCC.
> When we know that we are dealing with BUILT_IN_MALLOC, are we allowed to
> assume that the user has not overridden malloc with their own definition
> which has side-effects other than the usual ones?
>

Things can get wrong when user provided malloc gets inlined into
caller functions by cross module inlining. Another area that can get
wrong when user provides malloc definition, some other internal
supporting functions may also get exposed to the user level (e.g.
tuning APIs). Such functions have hidden dependency with malloc
routine which may not be modelled properly by the compiler.

David


> --
> Mark Mitchell
> CodeSourcery
> mark@codesourcery.com
> (650) 331-3385 x713
>



More information about the Gcc-patches mailing list