This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Use pointer sized array indices.
- From: Janne Blomqvist <blomqvist dot janne at gmail dot com>
- To: Thomas Koenig <tkoenig at netcologne dot de>
- Cc: Fortran List <fortran at gcc dot gnu dot org>, GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Tue, 30 Jan 2018 18:26:33 +0200
- Subject: Re: [PATCH] Use pointer sized array indices.
- Authentication-results: sourceware.org; auth=none
- References: <1514564021-3546-1-git-send-email-blomqvist.janne@gmail.com> <412d8a25-af22-d34c-5d6a-944c5c4c6ea4@netcologne.de> <CAO9iq9EOUGT9MBa6HrvzNsDiy_Z3zi4SLyeSJSd_8AHV9dFugg@mail.gmail.com> <CAO9iq9EWFCVRnK5od92o58F_6P_gfNkdcBQAPomJG=B_Kt317w@mail.gmail.com>
PING**2
On Wed, Jan 17, 2018 at 8:02 PM, Janne Blomqvist
<blomqvist.janne@gmail.com> wrote:
> PING
>
> On Fri, Dec 29, 2017 at 8:28 PM, Janne Blomqvist
> <blomqvist.janne@gmail.com> wrote:
>> On Fri, Dec 29, 2017 at 7:17 PM, Thomas Koenig <tkoenig@netcologne.de> wrote:
>>> Hi Janne,
>>>
>>>> Using pointer sized variables (e.g. size_t / ptrdiff_t) when the
>>>> variables are used as array indices allows accessing larger arrays,
>>>> and can be a slight performance improvement due to no need for sign or
>>>> zero extending, or masking.
>>>
>>>
>>> Unless I have missed something, all the examples are for cases where
>>> the array is of maximum size GFC_MAX_DIMENSIONS.
>>
>> Many, but not all.
>>
>>> This is why they
>>> were left as int in the first place (because it is unlikely we will have
>>> arrays of more than 2^31-1 dimensions soon :-).
>>>
>>> Do you really think this change is necessary? If not, I'd rather avoid
>>> such a change.
>>
>> I'm not planning on supporting > 2**31-1 dimensions, no. :)
>>
>> But even if we know that the maximum value is always going to be
>> smaller, by using pointer-sized variables the compiler can generate
>> slightly more efficient code.
>>
>> See e.g. https://godbolt.org/g/oAvw5L ; in the functions with a loop,
>> the ones which use pointer-sized indices have shorter preambles as
>> well as loop bodies. And for the simple functions that just index an
>> array, by using pointer-sized indices there is no need to zero the
>> upper half of the registers.
>>
>> I mean, it's not a huge improvement, but it might be a tiny one in some cases.
>>
>> Also, by moving the induction variable from the beginning of the
>> function into the loop header, it makes it easier for both readers and
>> the compiler to see the scope of the variable.
>>
>> --
>> Janne Blomqvist
>
>
>
> --
> Janne Blomqvist
--
Janne Blomqvist