From patchwork Wed Aug 27 20:59:55 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 383567 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 843C91400A0 for ; Thu, 28 Aug 2014 07:00:14 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:content-type; q= dns; s=default; b=YC7kOEdx/UUDdd91EqHTkiN3TyhBJF1K2Q+3zwJUbmZYyZ phjib+A57ix6J4MstJ3cZLuSVrRb7DD8t99Q5GD73vJXSMY6SFjGFpm1kHfM1VOz PY0UF1xyjwt+zwDsgTe0NCkloSI2WVrhTBpxeMdKhw/9maCrIgm66b/Bn7zvo= 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 :message-id:date:from:mime-version:to:subject:content-type; s= default; bh=zyBEj+TbgI5fn54qoVKQJrv0L4U=; b=HTEvc61pGD9NMMSdmCHY 65x59qlVN0wfD+EE+8y4nV82Bm9rnvo3uGHUwarb6buRzYUESgjthtYhU3hSkJHy fqHxeJZc5tDvuWO4KJUWaNJeRJXw1g54WSYC8XsOTpf0QKp91sxu+msdFD/6DE6f aewS/s0+TOuJ0Ug4dLmqEPk= Received: (qmail 32687 invoked by alias); 27 Aug 2014 21:00:04 -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 32551 invoked by uid 89); 27 Aug 2014 21:00:00 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=0.3 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, SUBJ_OBFU_PUNCT_FEW, SUBJ_OBFU_PUNCT_MANY autolearn=no version=3.3.2 X-Spam-User: qpsmtpd, 2 recipients X-HELO: mx02.qsc.de Received: from mx02.qsc.de (HELO mx02.qsc.de) (213.148.130.14) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Wed, 27 Aug 2014 20:59:59 +0000 Received: from tux.net-b.de (port-92-194-32-4.dynamic.qsc.de [92.194.32.4]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx02.qsc.de (Postfix) with ESMTPSA id B398027692; Wed, 27 Aug 2014 22:59:55 +0200 (CEST) Message-ID: <53FE46CB.6030505@net-b.de> Date: Wed, 27 Aug 2014 22:59:55 +0200 From: Tobias Burnus User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.7.0 MIME-Version: 1.0 To: gcc-patches , gfortran , Thomas Koenig Subject: [Patch, Fortran] CAF dep (1/3): PR62278 - improve dependency.c's gfc_check_dependency's check (missed-optimization) The current gfc_check_dependency check always looked at the pointer attribute - and assumed the worst, if either the LHS or the RHS was true. Thus, it claimed that "a" and "b" alias for the following definition: integer, pointer :: p; integer :: a. However, as "a" has no target (or pointer) attribute, that's not possible. Additionally, "class(t) :: a" has internally the "pointer" attribute (but CLASS_DATA(sym)->attr.class_pointer == 0), however, in the Fortran sense, "a" is not a pointer and cannot alias. I do not have a good example for the test case, except for a similar one as above using "a[i] = p" and looking at the dump; but that requires patch 3/3 of this series. Build and regtested on x86-64-gnu-linux. (I do get a failure for gfortran.dg/graphite/pr42393.f90, but only with -O1 -fgraphite-identity and also without the patch.) OK for the trunk? Tobias 2014-08-27 Tobias Burnus PR fortran/62278 * dependency.c (gfc_check_dependency): Allow for optimizations in the pointer-alias check. diff --git a/gcc/fortran/dependency.c b/gcc/fortran/dependency.c index c18482a..1cdd141 100644 --- a/gcc/fortran/dependency.c +++ b/gcc/fortran/dependency.c @@ -1269,8 +1269,9 @@ gfc_check_dependency (gfc_expr *expr1, gfc_expr *expr2, bool identical) /* The interesting cases are when the symbols don't match. */ if (expr1->symtree->n.sym != expr2->symtree->n.sym) { + symbol_attribute attr1, attr2; gfc_typespec *ts1 = &expr1->symtree->n.sym->ts; - gfc_typespec *ts2 = &expr2->symtree->n.sym->ts; + gfc_typespec *ts2 = &expr2->symtree->n.sym->ts; /* Return 1 if expr1 and expr2 are equivalenced arrays. */ if (gfc_are_equivalenced_arrays (expr1, expr2)) @@ -1284,9 +1285,13 @@ gfc_check_dependency (gfc_expr *expr1, gfc_expr *expr2, bool identical) return 0; } - /* If either variable is a pointer, assume the worst. */ - /* TODO: -fassume-no-pointer-aliasing */ - if (gfc_is_data_pointer (expr1) || gfc_is_data_pointer (expr2)) + /* We have to also include target-target as ptr%comp is not a + pointer but it still alias with "dt%comp" for "ptr => dt". As + subcomponents and array access to pointers retains the target + attribute, that's sufficient. */ + attr1 = gfc_expr_attr (expr1); + attr2 = gfc_expr_attr (expr2); + if ((attr1.pointer || attr1.target) && (attr2.pointer || attr2.target)) { if (check_data_pointer_types (expr1, expr2) && check_data_pointer_types (expr2, expr1))