From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12037 invoked by alias); 21 Nov 2011 21:31:20 -0000 Received: (qmail 12028 invoked by uid 22791); 21 Nov 2011 21:31:20 -0000 X-SWARE-Spam-Status: No, hits=-2.9 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 21 Nov 2011 21:30:33 +0000 From: "burnus at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/51260] New: PARAMETER array with constructor initializer: Compile-time simplify single element access Date: Mon, 21 Nov 2011 22:01:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: fortran X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: burnus at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2011-11/txt/msg02152.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51260 Bug #: 51260 Summary: PARAMETER array with constructor initializer: Compile-time simplify single element access Classification: Unclassified Product: gcc Version: 4.7.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: normal Priority: P3 Component: fortran AssignedTo: unassigned@gcc.gnu.org ReportedBy: burnus@gcc.gnu.org Missed optimization in several ways for: integer, parameter:: is(10000)=(/(i,i=1,10000)/) print *,is(1) end The main issue is that "is(1)" is not simplified into the constant "1". Expected: * The front end should already optimize is(1) to "1" and should not generate the variable to store the parameter. * One should somehow tell the middle end that only a single element is needed for I/O. One currently has: _gfortran_transfer_integer_write (&dt_parm.0, &is[0], 4); which requires the whole object though only the first 4 bytes are needed (= &"1"). * The constructor should not be fully expanded, if one only needs a single element, i.e. using integer, parameter:: is(*)=(/(i,i=1,10000000)/) should be quick if one only needs the first element. In any case, no parameter array should be written if one can simplify it at front-end compilation time.