From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16303 invoked by alias); 23 Feb 2014 18:46:37 -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 16275 invoked by uid 48); 23 Feb 2014 18:46:33 -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: Sun, 23 Feb 2014 18:46: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: attachments.isobsolete attachments.created 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: 2014-02/txt/msg02411.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57742 Marc Glisse changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #30981|0 |1 is obsolete| | Attachment #31003|0 |1 is obsolete| | --- Comment #14 from Marc Glisse --- Created attachment 32204 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=32204&action=edit New patch This seems to work. It also handles the fortran example from comment #3. With a comment before the new function and a testcase, it will be good to go to gcc-patches. Side note: at -O3, if I provide an inline version of operator new (see PR 59894), it handles std::vector(n). However, I had to provide a simple one (call malloc, if null throw). The one in libsupc++ is way too complicated (2 calls to malloc), and if I refactor it slightly so "malloc" only appears once, I end up with the following. The edge probabilities are strange (malloc fails in 95% of cases?), but mostly we have a PHI node with a single argument which hides the fact that the variables are the same. It is far from the first time I notice this, is there a real reason to keep those unary PHIs, or should we optimize them more aggressively? p_24 = mallocD.1405 (sz_20); if (p_24 == 0B) goto ; else goto ; ;; succ: 7 [95.5%] (TRUE_VALUE,EXECUTABLE) ;; 11 [4.5%] (FALSE_VALUE,EXECUTABLE) ;; basic block 11, loop depth 0, count 0, freq 349, maybe hot ;; prev block 10, next block 12, flags: (NEW, REACHABLE) ;; pred: 10 [4.5%] (FALSE_VALUE,EXECUTABLE) # PT = { D.16587 } (escaped heap) # ALIGN = 8, MISALIGN = 0 # p_41 = PHI # .MEM_42 = VDEF <.MEM_34> MEM[(struct _Vector_baseD.14156 *)p_2(D)]._M_implD.15030._M_startD.15032 = p_41; # PT = { D.16587 } (escaped heap) # ALIGN = 4, MISALIGN = 0 _19 = p_41 + sz_20; # .MEM_44 = VDEF <.MEM_42> MEM[(struct _Vector_baseD.14156 *)p_2(D)]._M_implD.15030._M_end_of_storageD.15034 = _19; # .MEM_8 = VDEF <.MEM_44> # USE = anything # CLB = anything memsetD.1000 (p_41, 0, sz_20);