public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: [patch, fortran] Simplify constants which come from parameter arrays
@ 2018-03-28 15:53 Dominique d'Humières
  2018-03-31 11:57 ` Thomas König
  0 siblings, 1 reply; 8+ messages in thread
From: Dominique d'Humières @ 2018-03-28 15:53 UTC (permalink / raw)
  To: Thomas Koenig; +Cc: gfortran, gcc-patches

Hi Thomas,

If I am not mistaken, the patch causes:

FAIL: gfortran.dg/pr71935.f90   -O  (test for excess errors)
FAIL: gfortran.dg/substr_6.f90   -O0  execution test
FAIL: gfortran.dg/substr_6.f90   -O1  execution test
FAIL: gfortran.dg/substr_6.f90   -O2  execution test
FAIL: gfortran.dg/substr_6.f90   -O3 -fomit-frame-pointer -funroll-loops -fpeel-loops -ftracer -finline-functions  execution test
FAIL: gfortran.dg/substr_6.f90   -O3 -g  execution test
FAIL: gfortran.dg/substr_6.f90   -Os  execution test

For gfortran.dg/pr71935.f90 I get two additional errors on top of the expected warnings:

/opt/gcc/_clean/gcc/testsuite/gfortran.dg/pr71935.f90:5:21:

    print *, sizeof(z(3))      ! { dg-warning "is out of bounds" }
                     1
Warning: Array reference at (1) is out of bounds (3 > 2) in dimension 1
/opt/gcc/_clean/gcc/testsuite/gfortran.dg/pr71935.f90:5:21:

    print *, sizeof(z(3))      ! { dg-warning "is out of bounds" }
                     1
Error: Index in dimension 1 is out of bounds at (1)
/opt/gcc/_clean/gcc/testsuite/gfortran.dg/pr71935.f90:6:23:

    print *, c_sizeof(z(3))    ! { dg-warning "is out of bounds" }
                       1
Warning: Array reference at (1) is out of bounds (3 > 2) in dimension 1
/opt/gcc/_clean/gcc/testsuite/gfortran.dg/pr71935.f90:6:23:

    print *, c_sizeof(z(3))    ! { dg-warning "is out of bounds" }
                       1
Error: Index in dimension 1 is out of bounds at (1)

For gfortran.dg/substr_6.f90, I reach STOP 1 when running the executable.

TIA

Dominique


^ permalink raw reply	[flat|nested] 8+ messages in thread
* [patch, fortran] Simplify constants which come from parameter arrays
@ 2018-03-25 10:46 Thomas König
  0 siblings, 0 replies; 8+ messages in thread
From: Thomas König @ 2018-03-25 10:46 UTC (permalink / raw)
  To: fortran, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 615 bytes --]

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  <tkoenig@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  <tkoenig@gcc.gnu.org>

         PR fortran/51260
         * gfortran.dg/parameter_array_element_3.f90: New test.

[-- Attachment #2: p2.diff --]
[-- Type: text/x-patch, Size: 506 bytes --]

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;
 }
 

[-- Attachment #3: parameter_array_element_3.f90 --]
[-- Type: text/x-fortran, Size: 466 bytes --]

! { 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 } }

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2018-04-09 21:17 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-28 15:53 [patch, fortran] Simplify constants which come from parameter arrays Dominique d'Humières
2018-03-31 11:57 ` Thomas König
2018-04-03 15:22   ` Dominique d'Humières
2018-04-03 21:20     ` Thomas König
2018-04-09 20:26       ` Thomas König
2018-04-09 20:26         ` Steve Kargl
2018-04-09 21:17           ` Thomas König
  -- strict thread matches above, loose matches on Subject: below --
2018-03-25 10:46 Thomas König

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).