From patchwork Tue Sep 22 06:58:02 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: 520839 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 CF6EF140134 for ; Tue, 22 Sep 2015 16:58:36 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=VvvtzoKy; 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:to :from:subject:cc:message-id:date:mime-version:content-type; q= dns; s=default; b=d45OXb8Dfdajh/jT6Fvf2yGUbWqb3P5owm6jNcwFGDmiFk UoCVHm+NKEmWBw3BmNHmcEAZIE9bXUcSqhyUUOpGtZ3CyJ122vxOjPVi1E20xCZR 64yYZ+LplsSk7jrajmI2cKFSSOCTGPv91XoaIwTKozaXY64kBMTa/I7Xd9l5s= 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:to :from:subject:cc:message-id:date:mime-version:content-type; s= default; bh=rlL43tVNs7CTQ0jLhFDVMULurxk=; b=VvvtzoKysM5fHL4MK2AI ZzAVDYgjKRk7eL4oJVYb2e5uVrMS9QtdHfe/CnUltBrWh/zmX5NVhAtVo/JvTCNi Fxq8NIgdlH7BMt46iFJfIT0tUXjK1xuZjcctH3PReK/nm4T8z0s+UU63SnGHpXiP CWX+lkAALn0/+RNe7GW2YzA= Received: (qmail 99613 invoked by alias); 22 Sep 2015 06:58:30 -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 99601 invoked by uid 89); 22 Sep 2015 06:58:29 -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, RP_MATCHES_RCVD, SPF_PASS 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; Tue, 22 Sep 2015 06:58:27 +0000 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38599) by fencepost.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1ZeHWz-0004l7-H2 for gcc-patches@gnu.org; Tue, 22 Sep 2015 02:58:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZeHWv-0006ul-Iz for gcc-patches@gnu.org; Tue, 22 Sep 2015 02:58:24 -0400 Received: from relay1.mentorg.com ([192.94.38.131]:40831) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZeHWv-0006tf-DW for gcc-patches@gnu.org; Tue, 22 Sep 2015 02:58:21 -0400 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 1ZeHWq-0003Ev-RJ from Tom_deVries@mentor.com ; Mon, 21 Sep 2015 23:58:17 -0700 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; Tue, 22 Sep 2015 07:58:15 +0100 To: Richard Biener From: Tom de Vries Subject: [PATCH][PR67666] Handle single restrict pointer in struct in create_variable_info_for_1 CC: "gcc-patches@gnu.org" Message-ID: <5600FBFA.2090300@mentor.com> Date: Tue, 22 Sep 2015 08:58:02 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Windows NT kernel [generic] [fuzzy] X-Received-From: 192.94.38.131 Hi, Consider this test-case: struct ps { int *__restrict__ p; }; void f (struct ps &__restrict__ ps1) { *(ps1.p) = 1; } Atm, the restrict on p has no effect. Now, say we add a field to the struct: struct ps { int *__restrict__ p; int a; }; Then the restrict on p does have the desired effect. This patch fixes the handling of structs with a single field in alias analysis. Bootstrapped and reg-tested on x86_64. OK for trunk? Thanks, - Tom Handle single restrict pointer in struct in create_variable_info_for_1 2015-09-22 Tom de Vries PR tree-optimization/67666 * tree-ssa-structalias.c (create_variable_info_for_1): Handle struct with single field non-conservative. * g++.dg/pr67666.C: New test. --- gcc/testsuite/g++.dg/pr67666.C | 17 +++++++++++++++++ gcc/tree-ssa-structalias.c | 25 ++++++++++++++++--------- 2 files changed, 33 insertions(+), 9 deletions(-) create mode 100644 gcc/testsuite/g++.dg/pr67666.C diff --git a/gcc/testsuite/g++.dg/pr67666.C b/gcc/testsuite/g++.dg/pr67666.C new file mode 100644 index 0000000..ad162f4 --- /dev/null +++ b/gcc/testsuite/g++.dg/pr67666.C @@ -0,0 +1,17 @@ +// { dg-do compile } +// { dg-options "-O2 -fdump-tree-ealias-all" } + +struct ps +{ + int *__restrict__ p; +}; + +void +f (struct ps &__restrict__ ps1) +{ + *(ps1.p) = 1; +} + +// { dg-final { scan-tree-dump-times "clique 1 base 1" 1 "ealias" } } +// { dg-final { scan-tree-dump-times "clique 1 base 2" 1 "ealias" } } +// { dg-final { scan-tree-dump-times "(?n)clique .* base .*" 2 "ealias" } } diff --git a/gcc/tree-ssa-structalias.c b/gcc/tree-ssa-structalias.c index b5b9d0a..94016b9 100644 --- a/gcc/tree-ssa-structalias.c +++ b/gcc/tree-ssa-structalias.c @@ -5675,7 +5675,7 @@ create_variable_info_for_1 (tree decl, const char *name) /* If we didn't end up collecting sub-variables create a full variable for the decl. */ - if (fieldstack.length () <= 1 + if (fieldstack.length () == 0 || fieldstack.length () > MAX_FIELDS_FOR_FIELD_SENSITIVE) { vi = new_var_info (decl, name); @@ -5694,19 +5694,26 @@ create_variable_info_for_1 (tree decl, const char *name) fieldstack.iterate (i, &fo); ++i, newvi = vi_next (newvi)) { - const char *newname = "NULL"; + const char *newname = NULL; char *tempname; if (dump_file) { - tempname - = xasprintf ("%s." HOST_WIDE_INT_PRINT_DEC - "+" HOST_WIDE_INT_PRINT_DEC, name, - fo->offset, fo->size); - newname = ggc_strdup (tempname); - free (tempname); + if (fieldstack.length () != 1) + { + tempname + = xasprintf ("%s." HOST_WIDE_INT_PRINT_DEC + "+" HOST_WIDE_INT_PRINT_DEC, name, + fo->offset, fo->size); + newname = ggc_strdup (tempname); + free (tempname); + } } - newvi->name = newname; + else + newname = "NULL"; + + if (newname) + newvi->name = newname; newvi->offset = fo->offset; newvi->size = fo->size; newvi->fullsize = vi->fullsize; -- 1.9.1