This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug tree-optimization/19831] Missing DSE/malloc/free optimization
- From: "rguenther at suse dot de" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 29 Oct 2013 12:14:08 +0000
- Subject: [Bug tree-optimization/19831] Missing DSE/malloc/free optimization
- Auto-submitted: auto-generated
- References: <bug-19831-4 at http dot gcc dot gnu dot org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19831
--- Comment #18 from rguenther at suse dot de <rguenther at suse dot de> ---
On Fri, 25 Oct 2013, glisse at gcc dot gnu.org wrote:
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19831
>
> --- Comment #17 from Marc Glisse <glisse at gcc dot gnu.org> ---
> void f (double * __restrict a) {
> int * __restrict p = (int*) __builtin_malloc (sizeof (int));
> *p = 42;
> __builtin_free (p);
> ++*a; // Breaks the optimization!
> }
>
> Normally, gcc now manages to remove unused malloc+write+free sequences.
> However, it seems that completely unrelated operations, even after free, can
> prevent this optimization (it is the detection that *p=42 is dead that fails).
> That limits the effect in real-world code...
>
> (funny that if I remove the line with free(p), gcc does manage to optimize)
That's just DCE doing more than it is designed to do in some very
rare corner cases.
Look why DSE doesn't do its job instead.