From patchwork Thu Nov 3 22:06:15 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 123515 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 C50C3B6F72 for ; Fri, 4 Nov 2011 09:06:41 +1100 (EST) Received: (qmail 3729 invoked by alias); 3 Nov 2011 22:06:35 -0000 Received: (qmail 3708 invoked by uid 22791); 3 Nov 2011 22:06:34 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE X-Spam-Check-By: sourceware.org Received: from mx02.qsc.de (HELO mx02.qsc.de) (213.148.130.14) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 03 Nov 2011 22:06:17 +0000 Received: from [192.168.178.22] (port-92-204-63-254.dynamic.qsc.de [92.204.63.254]) by mx02.qsc.de (Postfix) with ESMTP id E1D111E8D1; Thu, 3 Nov 2011 23:06:15 +0100 (CET) Message-ID: <4EB31057.90307@net-b.de> Date: Thu, 03 Nov 2011 23:06:15 +0100 From: Tobias Burnus User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:7.0.1) Gecko/20110929 Thunderbird/7.0.1 MIME-Version: 1.0 To: gcc patches , gfortran Subject: [Patch, Fortran] PR 50960 - Mark PARAMETER as TREE_READONLY 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 Dear all, gfortran stores PARAMETERS which are array or derived types as global static variable. This prevents the compiler from optimizing those parameters. Using TREE_READONLY, one can allow the compiler to make use of the values and do further optimizations. Build and regtested on x86_64-linux. OK for the trunk? Tobias 2011-11-03 Tobias Burnus PR fortran/50960 * trans-decl.c (gfc_finish_var_decl): Mark PARAMETER as TREE_READONLY. 2011-11-03 Tobias Burnus PR fortran/50960 * gfortran.dg/module_parameter_array_refs_2.f90: New. diff --git a/gcc/fortran/trans-decl.c b/gcc/fortran/trans-decl.c index b7460b7..b90b0ab 100644 --- a/gcc/fortran/trans-decl.c +++ b/gcc/fortran/trans-decl.c @@ -517,6 +517,10 @@ gfc_finish_var_decl (tree decl, gfc_symbol * sym) /* If it wasn't used we wouldn't be getting it. */ TREE_USED (decl) = 1; + if (sym->attr.flavor == FL_PARAMETER + && (sym->attr.dimension || sym->ts.type == BT_DERIVED)) + TREE_READONLY (decl) = 1; + /* Chain this decl to the pending declarations. Don't do pushdecl() because this would add them to the current scope rather than the function scope. */ --- /dev/null 2011-11-01 08:51:46.775606868 +0100 +++ gcc/gcc/testsuite/gfortran.dg/module_parameter_array_refs_2.f90 2011-11-03 21:59:20.000000000 +0100 @@ -0,0 +1,23 @@ +! { dg-do compile } +! { dg-options "-O" } +! { dg-final { scan-assembler-not "i_am_optimized_away" } } +! +! PR fortran/50960 +! +! PARAMETER arrays and derived types exists as static variables. +! Check that the their read-only nature is taken into account +! when optimizations are done. +! + +module m + integer, parameter :: PARA(*) = [1,2,3,4,5,6,7,8,9,10] +end module m + +subroutine test() +use m +integer :: i +i = 1 +if (para(i) /= 1) call i_am_optimized_away() +end + +! { dg-final { cleanup-modules "m" } }