From patchwork Sun Sep 25 10:14:39 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 116270 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 7BA4AB6F76 for ; Sun, 25 Sep 2011 20:13:48 +1000 (EST) Received: (qmail 30000 invoked by alias); 25 Sep 2011 10:13:45 -0000 Received: (qmail 29991 invoked by uid 22791); 25 Sep 2011 10:13:44 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL,BAYES_00,TW_TM X-Spam-Check-By: sourceware.org Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 25 Sep 2011 10:13:24 +0000 Received: from nat-dem.mentorg.com ([195.212.93.2] helo=eu2-mail.mgc.mentorg.com) by relay1.mentorg.com with esmtp id 1R7li5-0005L3-HB from Tom_deVries@mentor.com ; Sun, 25 Sep 2011 03:13:21 -0700 Received: from [127.0.0.1] ([172.16.63.104]) by eu2-mail.mgc.mentorg.com with Microsoft SMTPSVC(6.0.3790.4675); Sun, 25 Sep 2011 12:13:20 +0200 Message-ID: <4E7EFF0F.4060503@mentor.com> Date: Sun, 25 Sep 2011 12:14:39 +0200 From: Tom de Vries User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.21) Gecko/20110831 Lightning/1.0b2 Thunderbird/3.1.13 MIME-Version: 1.0 To: Richard Guenther CC: Eric Botcazou , gcc-patches@gcc.gnu.org, Tom de Vries , Richard Guenther , Zdenek Dvorak Subject: Re: [PATCH PR43513, 1/3] Replace vla with array - Implementation. References: <4E2FED87.8020300@codesourcery.com> <4E319A5E.3060208@codesourcery.com> <4E33B110.8070708@codesourcery.com> <201109241729.26112.ebotcazou@adacore.com> In-Reply-To: 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 On 09/25/2011 10:57 AM, Richard Guenther wrote: > On Sat, Sep 24, 2011 at 5:29 PM, Eric Botcazou wrote: >>> This is an updated version of the patch. I have 2 new patches and an >>> updated testcase which I will sent out individually. >>> >>> Patch set was bootstrapped and reg-tested on x86_64. >>> >>> Ok for trunk? >>> >>> Thanks, >>> - Tom >>> >>> 2011-07-30 Tom de Vries >>> >>> PR middle-end/43513 >>> * Makefile.in (tree-ssa-ccp.o): Add $(PARAMS_H) to rule. >>> * tree-ssa-ccp.c (params.h): Include. >>> (fold_builtin_alloca_for_var): New function. >>> (ccp_fold_stmt): Use fold_builtin_alloca_for_var. >> >> We have detected another fallout on some Ada code: the transformation replaces >> a call to __builtin_alloca with &var, i.e. it introduces an aliased variable, >> which invalidates the points-to information of some subsequent call, fooling >> DSE into thinking that it can eliminate a live store. > > Ugh, yeah. I suppose PTA assigned a HEAP var as pointed-to object for the > original pointer, even if the transformed stmt > > orig_ptr_1 = &a; > > has the points-to information preserved for orig_ptr_1 further propagation of > &a will make accesses through orig_ptr_1 have different alias properties. > > What should work in this special case of a singleton points-to set of orig_ptr_1 > (might want to check that) is, do > > SET_DECL_PT_UID (decl-of-a, DECL_UID (pointed-to orig_ptr_1)); > > The brute force approach is not acceptable (it'll wreck IPA points-to info). > > A helper like pt_solution_singleton_p (struct pt_solution *pt, unsigned *uid) > whould be nice to have for this. > > Note that we don't have points-to information computed during the first > CCP pass, so the above should be conditional on SSA_NAME_PTR_INFO > being present and not ! ->anything (but then assert that we actually do have > a singleton, or fail the folding). > I tried to implement the approach you describe above in attached patch. Currently testing on x86_64. Thanks, - Tom > Richard. > >> The brute force approach >> >> Index: tree-ssa-ccp.c >> =================================================================== >> --- tree-ssa-ccp.c (revision 179038) >> +++ tree-ssa-ccp.c (working copy) >> @@ -2014,7 +2014,10 @@ do_ssa_ccp (void) >> ccp_initialize (); >> ssa_propagate (ccp_visit_stmt, ccp_visit_phi_node); >> if (ccp_finalize ()) >> - return (TODO_cleanup_cfg | TODO_update_ssa | TODO_remove_unused_locals); >> + return (TODO_cleanup_cfg >> + | TODO_update_ssa >> + | TODO_rebuild_alias >> + | TODO_remove_unused_locals); >> else >> return 0; >> } >> >> works, but we might want to be move clever. Thoughts? >> >> -- >> Eric Botcazou >> Index: gcc/tree-ssa-ccp.c =================================================================== --- gcc/tree-ssa-ccp.c (revision 179043) +++ gcc/tree-ssa-ccp.c (working copy) @@ -1729,6 +1729,17 @@ fold_builtin_alloca_for_var (gimple stmt array_type = build_array_type_nelts (elem_type, n_elem); var = create_tmp_var (array_type, NULL); DECL_ALIGN (var) = align; + { + struct ptr_info_def *pi = SSA_NAME_PTR_INFO (lhs); + if (pi != NULL && !pi->pt.anything) + { + bool singleton_p; + unsigned uid; + singleton_p = pt_solution_singleton_p (&pi->pt, &uid); + gcc_assert (singleton_p); + SET_DECL_PT_UID (var, uid); + } + } /* Fold alloca to the address of the array. */ return fold_convert (TREE_TYPE (lhs), build_fold_addr_expr (var)); Index: gcc/tree-ssa-alias.h =================================================================== --- gcc/tree-ssa-alias.h (revision 179043) +++ gcc/tree-ssa-alias.h (working copy) @@ -126,6 +126,7 @@ extern void dump_alias_stats (FILE *); /* In tree-ssa-structalias.c */ extern unsigned int compute_may_aliases (void); extern bool pt_solution_empty_p (struct pt_solution *); +extern bool pt_solution_singleton_p (struct pt_solution *, unsigned *); extern bool pt_solution_includes_global (struct pt_solution *); extern bool pt_solution_includes (struct pt_solution *, const_tree); extern bool pt_solutions_intersect (struct pt_solution *, struct pt_solution *); Index: gcc/tree-ssa-structalias.c =================================================================== --- gcc/tree-ssa-structalias.c (revision 179043) +++ gcc/tree-ssa-structalias.c (working copy) @@ -5978,6 +5978,21 @@ pt_solution_empty_p (struct pt_solution return true; } +/* Return true if the points-to solution *PT only point to a single var, and + return the var uid in *UID. */ + +bool +pt_solution_singleton_p (struct pt_solution *pt, unsigned *uid) +{ + if (pt->anything || pt->nonlocal || pt->escaped || pt->ipa_escaped + || pt->null || pt->vars == NULL + || !bitmap_single_bit_set_p (pt->vars)) + return false; + + *uid = bitmap_first_set_bit (pt->vars); + return true; +} + /* Return true if the points-to solution *PT includes global memory. */ bool