Replacing malloc with alloca.
Marc Glisse
marc.glisse@inria.fr
Mon Sep 14 16:39:00 GMT 2015
On Sun, 13 Sep 2015, Ajit Kumar Agarwal wrote:
> The replacement of malloc with alloca can be done on the following analysis.
>
> If the lifetime of an object does not stretch beyond the immediate scope. In such cases the malloc can be replaced with alloca.
> This increases the performance to a great extent.
>
> Inlining helps to a great extent the scope of lifetime of an object doesn't stretch the immediate scope of an object.
> And the scope of replacing malloc with alloca can be identified.
>
> I am wondering what phases of our optimization pipeline the malloc is replaced with alloca and what analysis is done to transform
> The malloc with alloca. This greatly increases the performance of the benchmarks? Is the analysis done through Escape Analysis?
>
> If yes, then what data structure is used for the abstract execution interpretation?
Did you try it? I don't think gcc ever replaces malloc with alloca. The
only optimization we do with malloc/free is removing it when it is
obviously unused. There are several PRs open about possible optimizations
(19831 for instance).
I posted a WIP patch a couple years ago to replace some malloc+free with
local arrays (fixed length) but never had time to finish it.
https://gcc.gnu.org/ml/gcc-patches/2013-11/msg03108.html
--
Marc Glisse
More information about the Gcc
mailing list