This is the mail archive of the
mailing list for the GCC project.
Re: Loop fusion.
- From: Richard Biener <richard dot guenther at gmail dot com>
- To: Toon Moene <toon at moene dot org>
- Cc: Steven Bosscher <stevenb dot gcc at gmail dot com>, gcc mailing list <gcc at gcc dot gnu dot org>
- Date: Thu, 23 Apr 2015 10:29:02 +0200
- Subject: Re: Loop fusion.
- Authentication-results: sourceware.org; auth=none
- References: <5537D377 dot 1000603 at moene dot org> <CABu31nOgBd8TPT35UmSsirCTuJoEFDQpwGqojcQuRiTvVnq+Tg at mail dot gmail dot com> <5537FEFB dot 5000704 at moene dot org>
On Wed, Apr 22, 2015 at 10:05 PM, Toon Moene <firstname.lastname@example.org> wrote:
> On 04/22/2015 09:10 PM, Steven Bosscher wrote:
>> On Wed, Apr 22, 2015 at 6:59 PM, Toon Moene wrote:
>>> Why is loop fusion important, especially in Fortran 90 and later programs
>>> Because without it, every array assignment is a single loop nest,
>>> from related, same-shape assignments.
>> Why is this a bad thing? When you're talking about single-node
>> machines, separate loops is probably faster if your arrays are large
>> enough: better cache locality and easier to vectorize.
>> Loop fusion is only a win if you iterate through the same array
>> variables. Writing such a pass is not so hard for the simple, most
>> common cases. The front end could do some of the rewriting from
>> F90-style array assignments to fused loops if it notices consecutive
>> array assignments/operations on the same variables.
> It could well be that my artificial example was not what my colleague
> measured ...
> Indeed, I thought about the front end doing this, but that would limit it to
> those that the front end could recognize; on the other hand, that might be
> the right limitation.
Generally loop fusion is a nice-to-have thing but as Steven points out
your example isn't particularly well-suited here. In fact loop distribution
(which performs fission) would undo such fusion.
But it also points to infrastructure we already have - loop distribution
can do the reverse transform so doing fusion there as well looks
natural (given you might fuse parts of a loop with parts of another
loop but keep parts separate as well - all based on data locality
analysis loop distribution performs).
But usually fusion requires some enablement transform(s) to make
the loop iteration spaces match.
Oh, and it's probably time to commit the patches I developed some
years ago to make loop distribution handle loop nests...
Oh, and I'm probably going to look into this and related transforms
(that enablement stuff) for GCC 6.
> Thanks !
> Toon Moene - e-mail: email@example.com - phone: +31 346 214290
> Saturnushof 14, 3738 XG Maartensdijk, The Netherlands
> At home: http://moene.org/~toon/; weather: http://moene.org/~hirlam/
> Progress of GNU Fortran: http://gcc.gnu.org/wiki/GFortran#news