public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Sandiford <richard.sandiford@arm.com>
To: David Malcolm <dmalcolm@redhat.com>
Cc: <gcc-patches@gcc.gnu.org>
Subject: Re: Add a loop versioning pass
Date: Wed, 28 Nov 2018 14:16:00 -0000	[thread overview]
Message-ID: <87sgzli8ya.fsf@arm.com> (raw)
In-Reply-To: <1540479702.14521.304.camel@redhat.com> (David Malcolm's message	of "Thu, 25 Oct 2018 11:01:42 -0400")

David Malcolm <dmalcolm@redhat.com> writes:
> On Wed, 2018-10-24 at 14:05 +0100, Richard Sandiford wrote:
>> This patch adds a pass that versions loops with variable index
>> strides
>> for the case in which the stride is 1.  E.g.:
>> 
>>     for (int i = 0; i < n; ++i)
>>       x[i * stride] = ...;
>> 
>> becomes:
>> 
>>     if (stepx == 1)
>>       for (int i = 0; i < n; ++i)
>>         x[i] = ...;
>>     else
>>       for (int i = 0; i < n; ++i)
>>         x[i * stride] = ...;
>> 
>> This is useful for both vector code and scalar code, and in some
>> cases
>> can enable further optimisations like loop interchange or pattern
>> recognition.
>> 
>> The pass gives a 7.6% improvement on Cortex-A72 for 554.roms_r at -O3
>> and a 2.4% improvement for 465.tonto.  I haven't found any SPEC tests
>> that regress.
>> 
>> Sizewise, there's a 10% increase in .text for both 554.roms_r and
>> 465.tonto.  That's obviously a lot, but in tonto's case it's because
>> the whole program is written using assumed-shape arrays and pointers,
>> so a large number of functions really do benefit from versioning.
>> roms likewise makes heavy use of assumed-shape arrays, and that
>> improvement in performance IMO justifies the code growth.
>> 
>> The next biggest .text increase is 4.5% for 548.exchange2_r.  I did
>> see
>> a small (0.4%) speed improvement there, but although both 3-iteration 
>> runs
>> produced stable results, that might still be noise.  There was a
>> slightly
>> larger (non-noise) improvement for a 256-bit SVE model.
>> 
>> 481.wrf and 521.wrf_r .text grew by 2.8% and 2.5% respectively, but
>> without any noticeable improvement in performance.  No other test
>> grew
>> by more than 2%.
>> 
>> Although the main SPEC beneficiaries are all Fortran tests, the
>> benchmarks we use for SVE also include some C and C++ tests that
>> benefit.
>> 
>> Using -frepack-arrays gives the same benefits in many Fortran cases.
>> The problem is that using that option inappropriately can force a
>> full
>> array copy for arguments that the function only reads once, and so it
>> isn't really something we can turn on by default.  The new pass is
>> supposed to give most of the benefits of -frepack-arrays without
>> the risk of unnecessary repacking.
>> 
>> The patch therefore enables the pass by default at -O3.
>> 
>> Tested on aarch64-linux-gnu and x86_64-linux-gnu.  OK to install?
>> 
>> Richard
>> 
>
> [...snip...]
>
>> +/* Run the pass and return a set of TODO_* flags.  */
>> +
>> +unsigned int
>> +loop_versioning::run ()
>> +{
>> +  gcc_assert (scev_initialized_p ());
>> +
>> +  if (!analyze_blocks ()
>> +      || !prune_conditions ()
>> +      || !make_versioning_decisions ()
>> +      || !implement_versioning_decisions ())
>> +    return 0;
>> +
>> +  return TODO_update_ssa;
>> +}
>> +
>> +/* Loop versioningting pass.  */
>
> (typo)

Huh, no idea how I even got there.

>> +
>> +namespace {
>
> Could the whole file be within this anonymous namespace, rather than
> just the opt_pass subclass?  (hiding class loop_versioning, so that the
> optimizer knows that the only thing visible outside the TU is
> make_pass_loop_versioning).  This can be a pain to debug, but you can
> always comment out the anon namespace locally when debugging.

Yeah, I prefer that style too, so that the TU only exports public
interfaces.  I'd got the impression from earlier threads that this
was frowned on for GCC and so I was deliberately avoiding it, but if
it's OK then great.

Thanks,
Richard

  reply	other threads:[~2018-11-28 14:16 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-24 13:41 Richard Sandiford
2018-10-25 14:16 ` Richard Biener
2018-10-25 16:03   ` Richard Sandiford
2018-10-26 14:49   ` Richard Biener
2018-10-25 16:16 ` David Malcolm
2018-11-28 14:16   ` Richard Sandiford [this message]
2018-10-30 10:55 Richard Biener
2018-11-09 10:46 ` Kyrill Tkachov
2018-11-28 16:48 ` Richard Sandiford
2018-11-29 11:31   ` Martin Jambor
2018-12-03 13:16   ` Richard Biener
2018-12-06 13:19     ` Richard Sandiford
2018-12-12 12:06       ` Richard Biener
2018-12-12 18:43         ` Richard Sandiford
2018-12-13 16:08           ` Richard Biener
2018-12-14 16:18             ` Richard Sandiford
2018-12-15 10:27               ` Richard Biener

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87sgzli8ya.fsf@arm.com \
    --to=richard.sandiford@arm.com \
    --cc=dmalcolm@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).