From patchwork Thu Feb 28 20:06:12 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 224170 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 083A42C02C3 for ; Fri, 1 Mar 2013 07:06:29 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1362686790; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:Date:From:To:Cc:Subject:Message-ID:Reply-To: MIME-Version:Content-Type:Content-Disposition:User-Agent: Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:Sender:Delivered-To; bh=5Nc3FZfMFqFt0QIMgKd+ tN6OoUM=; b=baAYHAwBAlbqsIqB+GJ2BR8NF7zV344Zn6XCpIky/nEbfup8uRuE Wja9ero8ZYGepMLFhKDA2gsIQm2tdynJNB+xqQX+9HbHvCzK5JS+vXlADN1W9uae oBGo+WcT3sV7FjlGeH/KpdDNnOUzZsVNdgcnLb4Mnb0N7ha7I46M6cg= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Received:Received:Date:From:To:Cc:Subject:Message-ID:Reply-To:MIME-Version:Content-Type:Content-Disposition:User-Agent:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=OMW2gaQn220CzJFeNQSuZq3UPKbEV5j5vt5SYUQXc9mcogVfDENA0f2ZxZ8HD/ AZq1dXCVAhDfE7vhjfx4e++017QvmybHUfe78X1sPYy1DdWn9uMczVHGPEKWrINj 07afbVYod1uyhjHFTuDULxDsbrZDLZ26y097E65B55/Bk=; Received: (qmail 19348 invoked by alias); 28 Feb 2013 20:06:24 -0000 Received: (qmail 19335 invoked by uid 22791); 28 Feb 2013 20:06:23 -0000 X-SWARE-Spam-Status: No, hits=-6.6 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, KHOP_SPAMHAUS_DROP, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, RP_MATCHES_RCVD, SPF_HELO_PASS, TW_TM X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 28 Feb 2013 20:06:16 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r1SK6FsD008213 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 28 Feb 2013 15:06:15 -0500 Received: from zalov.cz (vpn1-4-4.ams2.redhat.com [10.36.4.4]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r1SK6Dwk026806 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 28 Feb 2013 15:06:15 -0500 Received: from zalov.cz (localhost [127.0.0.1]) by zalov.cz (8.14.5/8.14.5) with ESMTP id r1SK6DfP025004; Thu, 28 Feb 2013 21:06:13 +0100 Received: (from jakub@localhost) by zalov.cz (8.14.5/8.14.5/Submit) id r1SK6C28025003; Thu, 28 Feb 2013 21:06:12 +0100 Date: Thu, 28 Feb 2013 21:06:12 +0100 From: Jakub Jelinek To: Richard Biener , Diego Novillo Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix a slp leak caused by vec.h conversion (PR middle-end/56461) Message-ID: <20130228200612.GX12913@tucnak.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Hi! This is small, but quite common memory leak in slp vectorization. vec_alloc (vec_defs, number_of_vects); on vl_ptr-ish vec *vec_defs; first calls new on the vec (i.e. allocates sizeof (void *) bytes), and then actually creates vector pointed to by that. Later on we copy the content of what it points to, but don't actually free the void * sized allocation. Fixed by changing the vector to be actually vec > *, which also simplifies the callers. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2013-02-28 Jakub Jelinek PR middle-end/56461 * tree-vectorizer.h (vect_get_slp_defs): Change 3rd argument type to vec > *. * tree-vect-slp.c (vect_get_slp_defs): Likewise. Change vec_defs to be vec instead of vec *, set vec_defs to vNULL and call vec_defs.create (number_of_vects), adjust other uses of vec_defs. * tree-vect-stmts.c (vect_get_vec_defs, vectorizable_call, vectorizable_condition): Adjust vect_get_slp_defs callers. Jakub --- gcc/tree-vectorizer.h.jj 2013-02-05 16:45:40.000000000 +0100 +++ gcc/tree-vectorizer.h 2013-02-28 14:17:45.276135327 +0100 @@ -978,7 +978,7 @@ extern bool vect_analyze_slp (loop_vec_i extern bool vect_make_slp_decision (loop_vec_info); extern void vect_detect_hybrid_slp (loop_vec_info); extern void vect_get_slp_defs (vec , slp_tree, - vec *, int); + vec > *, int); extern LOC find_bb_location (basic_block); extern bb_vec_info vect_slp_analyze_bb (basic_block); --- gcc/tree-vect-slp.c.jj 2013-01-31 18:28:54.000000000 +0100 +++ gcc/tree-vect-slp.c 2013-02-28 14:18:48.339791016 +0100 @@ -2614,14 +2614,14 @@ vect_get_slp_vect_defs (slp_tree slp_nod void vect_get_slp_defs (vec ops, slp_tree slp_node, - vec *vec_oprnds, int reduc_index) + vec > *vec_oprnds, int reduc_index) { gimple first_stmt; int number_of_vects = 0, i; unsigned int child_index = 0; HOST_WIDE_INT lhs_size_unit, rhs_size_unit; slp_tree child = NULL; - vec *vec_defs; + vec vec_defs; tree oprnd; bool vectorized_defs; @@ -2676,19 +2676,20 @@ vect_get_slp_defs (vec ops, slp_tr } /* Allocate memory for vectorized defs. */ - vec_alloc (vec_defs, number_of_vects); + vec_defs = vNULL; + vec_defs.create (number_of_vects); /* For reduction defs we call vect_get_constant_vectors (), since we are looking for initial loop invariant values. */ if (vectorized_defs && reduc_index == -1) /* The defs are already vectorized. */ - vect_get_slp_vect_defs (child, vec_defs); + vect_get_slp_vect_defs (child, &vec_defs); else /* Build vectors from scalar defs. */ - vect_get_constant_vectors (oprnd, slp_node, vec_defs, i, + vect_get_constant_vectors (oprnd, slp_node, &vec_defs, i, number_of_vects, reduc_index); - vec_oprnds->quick_push ((slp_void_p) vec_defs); + vec_oprnds->quick_push (vec_defs); /* For reductions, we only need initial values. */ if (reduc_index != -1) --- gcc/tree-vect-stmts.c.jj 2013-02-26 10:58:16.000000000 +0100 +++ gcc/tree-vect-stmts.c 2013-02-28 14:23:38.181910467 +0100 @@ -1583,7 +1583,7 @@ vect_get_vec_defs (tree op0, tree op1, g int nops = (op1 == NULL_TREE) ? 1 : 2; vec ops; ops.create (nops); - vec vec_defs; + vec > vec_defs; vec_defs.create (nops); ops.quick_push (op0); @@ -1592,9 +1592,9 @@ vect_get_vec_defs (tree op0, tree op1, g vect_get_slp_defs (ops, slp_node, &vec_defs, reduc_index); - *vec_oprnds0 = *((vec *) vec_defs[0]); + *vec_oprnds0 = vec_defs[0]; if (op1) - *vec_oprnds1 = *((vec *) vec_defs[1]); + *vec_oprnds1 = vec_defs[1]; ops.release (); vec_defs.release (); @@ -1882,14 +1882,14 @@ vectorizable_call (gimple stmt, gimple_s if (slp_node) { - vec vec_defs; + vec > vec_defs; vec_defs.create (nargs); vec vec_oprnds0; for (i = 0; i < nargs; i++) vargs.quick_push (gimple_call_arg (stmt, i)); vect_get_slp_defs (vargs, slp_node, &vec_defs, -1); - vec_oprnds0 = *((vec *) vec_defs[0]); + vec_oprnds0 = vec_defs[0]; /* Arguments are ready. Create the new vector stmt. */ FOR_EACH_VEC_ELT (vec_oprnds0, i, vec_oprnd0) @@ -1897,7 +1897,7 @@ vectorizable_call (gimple stmt, gimple_s size_t k; for (k = 0; k < nargs; k++) { - vec vec_oprndsk = *((vec *) vec_defs[k]); + vec vec_oprndsk = vec_defs[k]; vargs[k] = vec_oprndsk[i]; } new_stmt = gimple_build_call_vec (fndecl, vargs); @@ -1909,7 +1909,7 @@ vectorizable_call (gimple stmt, gimple_s for (i = 0; i < nargs; i++) { - vec vec_oprndsi = *((vec *) vec_defs[i]); + vec vec_oprndsi = vec_defs[i]; vec_oprndsi.release (); } vec_defs.release (); @@ -1958,14 +1958,14 @@ vectorizable_call (gimple stmt, gimple_s if (slp_node) { - vec vec_defs; + vec > vec_defs; vec_defs.create (nargs); vec vec_oprnds0; for (i = 0; i < nargs; i++) vargs.quick_push (gimple_call_arg (stmt, i)); vect_get_slp_defs (vargs, slp_node, &vec_defs, -1); - vec_oprnds0 = *((vec *) vec_defs[0]); + vec_oprnds0 = vec_defs[0]; /* Arguments are ready. Create the new vector stmt. */ for (i = 0; vec_oprnds0.iterate (i, &vec_oprnd0); i += 2) @@ -1974,7 +1974,7 @@ vectorizable_call (gimple stmt, gimple_s vargs.truncate (0); for (k = 0; k < nargs; k++) { - vec vec_oprndsk = *((vec *) vec_defs[k]); + vec vec_oprndsk = vec_defs[k]; vargs.quick_push (vec_oprndsk[i]); vargs.quick_push (vec_oprndsk[i + 1]); } @@ -1987,7 +1987,7 @@ vectorizable_call (gimple stmt, gimple_s for (i = 0; i < nargs; i++) { - vec vec_oprndsi = *((vec *) vec_defs[i]); + vec vec_oprndsi = vec_defs[i]; vec_oprndsi.release (); } vec_defs.release (); @@ -5392,7 +5392,7 @@ vectorizable_condition (gimple stmt, gim { vec ops; ops.create (4); - vec vec_defs; + vec > vec_defs; vec_defs.create (4); ops.safe_push (TREE_OPERAND (cond_expr, 0)); @@ -5400,10 +5400,10 @@ vectorizable_condition (gimple stmt, gim ops.safe_push (then_clause); ops.safe_push (else_clause); vect_get_slp_defs (ops, slp_node, &vec_defs, -1); - vec_oprnds3 = *((vec *) vec_defs.pop ()); - vec_oprnds2 = *((vec *) vec_defs.pop ()); - vec_oprnds1 = *((vec *) vec_defs.pop ()); - vec_oprnds0 = *((vec *) vec_defs.pop ()); + vec_oprnds3 = vec_defs.pop (); + vec_oprnds2 = vec_defs.pop (); + vec_oprnds1 = vec_defs.pop (); + vec_oprnds0 = vec_defs.pop (); ops.release (); vec_defs.release ();