Hello world, the attached patch potentially saves some space in the object file by simplifying access to individual elements of a parameter array, which means that the original parameter may not be needed any more.
Regression-tested. OK for trunk? Regards Thomas 2018-03-25 Thomas Koenig <tkoe...@gcc.gnu.org> PR fortran/51260 * resolve.c (resolve_variable): Simplify cases where access to a parameter array results in a single constant. 2018-03-25 Thomas Koenig <tkoe...@gcc.gnu.org> PR fortran/51260 * gfortran.dg/parameter_array_element_3.f90: New test.
Index: resolve.c =================================================================== --- resolve.c (Revision 258501) +++ resolve.c (Arbeitskopie) @@ -5577,6 +5577,11 @@ resolve_procedure: if (t && flag_coarray == GFC_FCOARRAY_LIB && gfc_is_coindexed (e)) add_caf_get_intrinsic (e); + /* Simplify cases where access to a parameter array results in a + single constant. */ + if (e->rank == 0 && sym->as && sym->attr.flavor == FL_PARAMETER) + gfc_simplify_expr (e, 1); + return t; }
! { dg-do compile } ! PR 51260 - an unneeded parameter found its way into the ! assembly code. Original test case by Tobias Burnus. module x contains subroutine foo(i) integer, intent(in) :: i end subroutine foo end module x program main use x integer, parameter:: unneeded_parameter (10000)=(/(i,i=1,10000)/) call foo(unneeded_parameter (1)) print *,unneeded_parameter (1) end program ! { dg-final { scan-assembler-times "unneeded_parameter" 0 } }