This is the mail archive of the
mailing list for the GCC project.
Re: Replacing malloc with alloca.
- From: Marc Glisse <marc dot glisse at inria dot fr>
- To: Ajit Kumar Agarwal <ajit dot kumar dot agarwal at xilinx dot com>
- Cc: "gcc at gcc dot gnu dot org" <gcc at gcc dot gnu dot org>
- Date: Mon, 14 Sep 2015 13:14:40 +0200 (CEST)
- Subject: Re: Replacing malloc with alloca.
- Authentication-results: sourceware.org; auth=none
- References: <37378DC5BCD0EE48BA4B082E0B55DFAA42990090 at XAP-PVEXMBX02 dot xlnx dot xilinx dot com>
- Reply-to: "gcc at gcc dot gnu dot org" <gcc at gcc dot gnu dot org>
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.