From patchwork Wed Nov 4 14:24:58 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 539975 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]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 7DB8F1402D0 for ; Thu, 5 Nov 2015 01:25:38 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=aO4IrapJ; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :subject:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type; q=dns; s=default; b=KfabJvAayZA4hsqnO /iKA/yQw86wgNxz439EJe4PWqs0V8JiWsyEpQggJkx7dkDwf4lTVAThErMj3p0/b Ui2WKxpGo49SUbyPIbuqJAmUOY6nvEnKTDqGHeh0usu9m2RHtGmMxCicgUKPj1w3 po02qB8HYpxUr0ztikkbyi00Gw= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :subject:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type; s=default; bh=IwEw2SD6SnVVctesPPvp1na 7Xww=; b=aO4IrapJf0g/h1P4ZBtkbqJouYYbafO6gKykSGuZlZkG3N4csLiobFe FjVsbJGhVINysR4kzX9jTXMOjZRmsvgFlIlWXGFpKU9NFZDqUk7BXOplZfB3qWHd ipcsJ4M284QfygbkcyaxwtGlhS0KhkFsY8cUZKyOM/7DYi4uDfok= Received: (qmail 14507 invoked by alias); 4 Nov 2015 14:25:29 -0000 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 Received: (qmail 14492 invoked by uid 89); 4 Nov 2015 14:25:28 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL, BAYES_00, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: fencepost.gnu.org Received: from fencepost.gnu.org (HELO fencepost.gnu.org) (208.118.235.10) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Wed, 04 Nov 2015 14:25:26 +0000 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40565) by fencepost.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1Ztz08-0005c9-3S for gcc-patches@gnu.org; Wed, 04 Nov 2015 09:25:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ztz01-0004E2-1J for gcc-patches@gnu.org; Wed, 04 Nov 2015 09:25:23 -0500 Received: from relay1.mentorg.com ([192.94.38.131]:44216) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ztz00-0004Dx-PA for gcc-patches@gnu.org; Wed, 04 Nov 2015 09:25:16 -0500 Received: from nat-ies.mentorg.com ([192.94.31.2] helo=SVR-IES-FEM-02.mgc.mentorg.com) by relay1.mentorg.com with esmtp id 1Ztyzz-0001Bz-Q7 from Tom_deVries@mentor.com ; Wed, 04 Nov 2015 06:25:16 -0800 Received: from [127.0.0.1] (137.202.0.76) by SVR-IES-FEM-02.mgc.mentorg.com (137.202.0.106) with Microsoft SMTP Server id 14.3.224.2; Wed, 4 Nov 2015 14:25:13 +0000 Subject: [committed] Handle recursive restrict in function parameter To: Richard Biener References: <562E0CF5.8000606@mentor.com> <562E5381.5@mentor.com> <562F26E2.40906@mentor.com> <562F6D1A.4010001@mentor.com> <562F748D.5020507@mentor.com> <563653F5.9090302@mentor.com> <563657D0.1030203@mentor.com> <5638BAC4.3050106@mentor.com> <5638E453.3050007@mentor.com> CC: Richard Biener , "gcc-patches@gnu.org" From: Tom de Vries Message-ID: <563A153A.6060005@mentor.com> Date: Wed, 4 Nov 2015 15:24:58 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 In-Reply-To: X-detected-operating-system: by eggs.gnu.org: Windows NT kernel [generic] [fuzzy] X-Received-From: 192.94.38.131 On 04/11/15 10:28, Richard Biener wrote: >> I think I can postpone the creation of the heapvar till where you suggest in >> >create_variable_info_for_1, but I'd still need a means >> >to communicate the TREE_TYPE (field_type) from push_fields_onto_fieldstack to >> >create_variable_info_for_1. >> > >> >A simple implementation would be a new field: >> >... >> >@@ -5195,6 +5197,8 @@ struct fieldoff >> >unsigned may_have_pointers : 1; >> > >> >unsigned only_restrict_pointers : 1; >> >+ >> >+ tree restrict_pointed_type; >> >}; >> >... >> >Which AFAIU will change fieldoff size. > It's ok to change fieldoff size if there is a reason to;) > > Patch is ok along this line. Updated patch accordingly. Bootstrapped and reg-tested on x86_64. Committed to trunk as attached. Thanks, - Tom Handle recursive restrict in function parameter 2015-11-04 Tom de Vries PR tree-optimization/67742 * tree-ssa-structalias.c (struct fieldoff): Add restrict_pointed_type field. (push_fields_onto_fieldstack): Handle restrict_pointed_type field. (create_variable_info_for_1): Add and handle handle_param parameter. Add restrict handling. (create_variable_info_for): Call create_variable_info_for_1 with extra arg. (make_param_constraints): Drop restrict_name parameter. Ignore vi->only_restrict_pointers. (intra_create_variable_infos): Call create_variable_info_for_1 with extra arg. Remove restrict handling. Call make_param_constraints with one less arg. * gcc.dg/tree-ssa/restrict-7.c: New test. * gcc.dg/tree-ssa/restrict-8.c: New test. --- gcc/testsuite/gcc.dg/tree-ssa/restrict-7.c | 12 +++++ gcc/testsuite/gcc.dg/tree-ssa/restrict-8.c | 17 +++++++ gcc/tree-ssa-structalias.c | 78 +++++++++++++++++------------- 3 files changed, 74 insertions(+), 33 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/restrict-7.c create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/restrict-8.c diff --git a/gcc/testsuite/gcc.dg/tree-ssa/restrict-7.c b/gcc/testsuite/gcc.dg/tree-ssa/restrict-7.c new file mode 100644 index 0000000..f7a68c7 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/restrict-7.c @@ -0,0 +1,12 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-fre1" } */ + +int +f (int *__restrict__ *__restrict__ *__restrict__ a, int *b) +{ + *b = 1; + ***a = 2; + return *b; +} + +/* { dg-final { scan-tree-dump-times "return 1" 1 "fre1" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/restrict-8.c b/gcc/testsuite/gcc.dg/tree-ssa/restrict-8.c new file mode 100644 index 0000000..b0ab164 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/restrict-8.c @@ -0,0 +1,17 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-fre1" } */ + +struct s +{ + int *__restrict__ *__restrict__ pp; +}; + +int +f (struct s s, int *b) +{ + *b = 1; + **s.pp = 2; + return *b; +} + +/* { dg-final { scan-tree-dump-times "return 1" 1 "fre1" } } */ diff --git a/gcc/tree-ssa-structalias.c b/gcc/tree-ssa-structalias.c index 98b5f16..52a35f6 100644 --- a/gcc/tree-ssa-structalias.c +++ b/gcc/tree-ssa-structalias.c @@ -307,6 +307,7 @@ static varinfo_t first_or_preceding_vi_for_offset (varinfo_t, unsigned HOST_WIDE_INT); static varinfo_t lookup_vi_for_tree (tree); static inline bool type_can_have_subvars (const_tree); +static void make_param_constraints (varinfo_t); /* Pool of variable info structures. */ static object_allocator variable_info_pool @@ -393,7 +394,6 @@ new_var_info (tree t, const char *name, bool add_id) return ret; } - /* A map mapping call statements to per-stmt variables for uses and clobbers specific to the call. */ static hash_map *call_stmt_vars; @@ -5195,6 +5195,8 @@ struct fieldoff unsigned may_have_pointers : 1; unsigned only_restrict_pointers : 1; + + tree restrict_pointed_type; }; typedef struct fieldoff fieldoff_s; @@ -5340,7 +5342,8 @@ push_fields_onto_fieldstack (tree type, vec *fieldstack, if (!pair && offset + foff != 0) { - fieldoff_s e = {0, offset + foff, false, false, false, false}; + fieldoff_s e + = {0, offset + foff, false, false, false, false, NULL_TREE}; pair = fieldstack->safe_push (e); } @@ -5374,6 +5377,8 @@ push_fields_onto_fieldstack (tree type, vec *fieldstack, = (!has_unknown_size && POINTER_TYPE_P (field_type) && TYPE_RESTRICT (field_type)); + if (e.only_restrict_pointers) + e.restrict_pointed_type = TREE_TYPE (field_type); fieldstack->safe_push (e); } } @@ -5642,10 +5647,11 @@ check_for_overlaps (vec fieldstack) /* Create a varinfo structure for NAME and DECL, and add it to VARMAP. This will also create any varinfo structures necessary for fields - of DECL. */ + of DECL. DECL is a function parameter if HANDLE_PARAM is set. */ static varinfo_t -create_variable_info_for_1 (tree decl, const char *name, bool add_id) +create_variable_info_for_1 (tree decl, const char *name, bool add_id, + bool handle_param) { varinfo_t vi, newvi; tree decl_type = TREE_TYPE (decl); @@ -5721,6 +5727,20 @@ create_variable_info_for_1 (tree decl, const char *name, bool add_id) if (POINTER_TYPE_P (decl_type) && TYPE_RESTRICT (decl_type)) vi->only_restrict_pointers = 1; + if (vi->only_restrict_pointers + && !type_contains_placeholder_p (TREE_TYPE (decl_type)) + && handle_param) + { + varinfo_t rvi; + tree heapvar = build_fake_var_decl (TREE_TYPE (decl_type)); + DECL_EXTERNAL (heapvar) = 1; + rvi = create_variable_info_for_1 (heapvar, "PARM_NOALIAS", true, + true); + rvi->is_restrict_var = 1; + insert_vi_for_tree (heapvar, rvi); + make_constraint_from (vi, rvi->id); + make_param_constraints (rvi); + } fieldstack.release (); return vi; } @@ -5758,6 +5778,20 @@ create_variable_info_for_1 (tree decl, const char *name, bool add_id) newvi->fullsize = vi->fullsize; newvi->may_have_pointers = fo->may_have_pointers; newvi->only_restrict_pointers = fo->only_restrict_pointers; + if (handle_param + && newvi->only_restrict_pointers + && !type_contains_placeholder_p (fo->restrict_pointed_type)) + { + varinfo_t rvi; + tree heapvar = build_fake_var_decl (fo->restrict_pointed_type); + DECL_EXTERNAL (heapvar) = 1; + rvi = create_variable_info_for_1 (heapvar, "PARM_NOALIAS", true, + true); + rvi->is_restrict_var = 1; + insert_vi_for_tree (heapvar, rvi); + make_constraint_from (newvi, rvi->id); + make_param_constraints (rvi); + } if (i + 1 < fieldstack.length ()) { varinfo_t tem = new_var_info (decl, name, false); @@ -5772,7 +5806,7 @@ create_variable_info_for_1 (tree decl, const char *name, bool add_id) static unsigned int create_variable_info_for (tree decl, const char *name, bool add_id) { - varinfo_t vi = create_variable_info_for_1 (decl, name, add_id); + varinfo_t vi = create_variable_info_for_1 (decl, name, add_id, false); unsigned int id = vi->id; insert_vi_for_tree (decl, vi); @@ -5879,16 +5913,15 @@ debug_solution_for_var (unsigned int var) dump_solution_for_var (stderr, var); } -/* Register the constraints for function parameter related VI. Use RESTRICT_NAME - as the base name of created restrict vars. */ +/* Register the constraints for function parameter related VI. */ static void -make_param_constraints (varinfo_t vi, const char *restrict_name) +make_param_constraints (varinfo_t vi) { for (; vi; vi = vi_next (vi)) { if (vi->only_restrict_pointers) - make_constraint_from_global_restrict (vi, restrict_name, true); + ; else if (vi->may_have_pointers) make_constraint_from (vi, nonlocal_id); @@ -5910,32 +5943,11 @@ intra_create_variable_infos (struct function *fn) passed-by-reference argument. */ for (t = DECL_ARGUMENTS (fn->decl); t; t = DECL_CHAIN (t)) { - bool restrict_pointer_p = (POINTER_TYPE_P (TREE_TYPE (t)) - && TYPE_RESTRICT (TREE_TYPE (t))); - bool recursive_restrict_p - = (restrict_pointer_p - && !type_contains_placeholder_p (TREE_TYPE (TREE_TYPE (t)))); - varinfo_t p = create_variable_info_for_1 (t, alias_get_name (t), false); + varinfo_t p + = create_variable_info_for_1 (t, alias_get_name (t), false, true); insert_vi_for_tree (t, p); - /* For restrict qualified pointers build a representative for - the pointed-to object. Note that this ends up handling - out-of-bound references conservatively by aggregating them - in the first/last subfield of the object. */ - if (recursive_restrict_p) - { - varinfo_t vi; - tree heapvar = build_fake_var_decl (TREE_TYPE (TREE_TYPE (t))); - DECL_EXTERNAL (heapvar) = 1; - vi = create_variable_info_for_1 (heapvar, "PARM_NOALIAS", true); - vi->is_restrict_var = 1; - insert_vi_for_tree (heapvar, vi); - make_constraint_from (p, vi->id); - make_param_constraints (vi, "GLOBAL_RESTRICT"); - continue; - } - - make_param_constraints (p, "PARM_RESTRICT"); + make_param_constraints (p); } /* Add a constraint for a result decl that is passed by reference. */ -- 1.9.1