This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [Patch, Fortran] Simplify lbound
- From: "H.J. Lu" <hjl dot tools at gmail dot com>
- To: Thomas Koenig <tkoenig at netcologne dot de>
- Cc: Mikael Morin <mikael dot morin at sfr dot fr>, "fortran at gcc dot gnu dot org" <fortran at gcc dot gnu dot org>, gcc-patches <gcc-patches at gcc dot gnu dot org>
- Date: Sat, 2 May 2015 03:50:46 -0700
- Subject: Re: [Patch, Fortran] Simplify lbound
- Authentication-results: sourceware.org; auth=none
- References: <553B7BA4 dot 6040103 at netcologne dot de> <553BD925 dot 3050401 at sfr dot fr> <553E83B4 dot 8020005 at netcologne dot de>
On Mon, Apr 27, 2015 at 11:45 AM, Thomas Koenig <tkoenig@netcologne.de> wrote:
> Am 25.04.2015 um 20:12 schrieb Mikael Morin:
>
>> I've double-checked in the standard, and it seems it is not possible to
>> simplify after all:
>>
>> If ARRAY is a whole array and either ARRAY is an assumed-size
>> array of rank DIM or dimension DIM of ARRAY has nonzero extent,
>> LBOUND (ARRAY, DIM) has a value equal to the lower bound for
>> subscript DIM of ARRAY. Otherwise the result value is 1.
>>
>> We can't tell whether the array is zero-sized, so we can't tell the
>> lbound value.
>
> So it is only possible to simplify LBOUND if the lower bound is
> equal to one, both for assumed-shape and explicit-shape arrays...
> OK.
>
> The attached patch does that, including a test case which catches
> that particular case.
>
>> As you may want to simplify in the limited scope of the matmul inlining,
>> I'm giving comments about the patch (otherwise you can ignore them):
>> - No need to check for allocatable or pointer, it should be excluded by
>> as->type == AS_ASSUMED_SHAPE (but does no harm either).
>
> Actually, no. You can have assumed-shape allocatable or pointer
> dummy arguments which keep their original lbound; see the subroutine
> 'bar' in the test case.
>
>> - Please modify the early return condition:
>> if (as && (as->type == AS_DEFERRED || as->type == AS_ASSUMED_SHAPE
>> || as->type == AS_ASSUMED_RANK))
>> return NULL;
>> and let the existing code do the simplification work.
>
> That is not part of my patch.
>
>> Or drop the lbound simplification idea, and fetch the lbound "by hand"
>> at matmul inline time.
>
> I will probably do so as a future optimization, but I think that most
> people will see no reason for using different lower bounds, so it is
> OK for the time being to (slightly) pessimize this case.
>
> So... here is the new patch. OK for trunk?
>
> Thomas
>
> 2015-04-25 Thomas Koenig <tkoenig@gcc.gnu.org>
>
> PR fortran/37131
> * simplify.c (simplify_bound): Get constant lower bounds of one
> from array spec for assumed and explicit shape shape arrays if
> the lower bounds are indeed one.
>
> 2015-04-25 Thomas Koenig <tkoenig@gcc.gnu.org>
>
> PR fortran/37131
> * gfortran.dg/coarray_lib_this_image_2.f90: Adjust
> scan pattern.
> * gfortran.dg/bound_9.f90: New test case.
>
This caused:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65981
--
H.J.