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: unassig...@gcc.gnu.org ReportedBy: bur...@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.