From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7930 invoked by alias); 15 Oct 2013 14:11:35 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 7889 invoked by uid 48); 15 Oct 2013 14:11:32 -0000 From: "glisse at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/57742] memset(malloc(n),0,n) -> calloc(n,1) Date: Tue, 15 Oct 2013 14:11:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 4.9.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: enhancement X-Bugzilla-Who: glisse at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2013-10/txt/msg00916.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57742 --- Comment #10 from Marc Glisse --- (In reply to Richard Biener from comment #9) > (In reply to Marc Glisse from comment #7) > > Also, for this testcase: > > void* f(int n,double*d){ > > int* p=__builtin_malloc(n); > > ++*d; > > __builtin_memset(p,0,n); > > return p; > > } > > I actually get a callback for the store in *d, which gcc believes might > > alias :-( > > Yeah well, either because of pass placement or because of points-to > analysis being not context sensitive. forwprop is run 4 times, it would be really unlucky if all 4 were badly placed. I am surprised that in FRE/PRE stmt_may_clobber_ref_p_1 returns false for p and q in the following code (while called from forwprop in the above testcase it returns true). The main difference I can see is that the SSA_NAME_PTR_INFO of p has vars_contains_global=1 when I test my code and 0 when I test the following in FRE. int g(int*a,int n,double*q){ int*p=__builtin_malloc(n); p[2]=3; *q=5.; return p[2]; } > Exact pattern matching of the CFG involved might be the easiest, plus > manually implementing walk_aliased_vdefs by simply walking the use-def > chain of the virtual operands from the memset operation to the malloc That was also my conclusion, and it is a bit disappointing, since the transformation shouldn't mind if for instance there is an unrelated loop between malloc and memset. Better than nothing I guess :-/ > and checking stmt_may_clobber_ref_p_1 on the ao_ref_init_from_ptr_and_size > ref. Well, that won't help since stmt_may_clobber_ref_p_1 doesn't notice that unrelated stores are unrelated, I first need to work on that.