public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jean Christophe Beyler <jean.christophe.beyler@gmail.com>
To: Zdenek Dvorak <rakdver@kam.mff.cuni.cz>
Cc: gcc@gcc.gnu.org
Subject: Re: Turning off unrolling to certain loops
Date: Wed, 14 Oct 2009 18:56:00 -0000	[thread overview]
Message-ID: <c568a2600910141129i75b2fa2bre4aff548ed376905@mail.gmail.com> (raw)
In-Reply-To: <c568a2600910080922n7f5496bfged5d9473ca04200b@mail.gmail.com>

Ok, I've actually gone a different route. Instead of waiting for the
middle end to perform this, I've directly modified the parser stage to
unroll the loop directly there.

Basically, I take the parser of the for and modify how it adds the
various statements. Telling it to, instead of doing in the
c_finish_loop :

  if (body)
    add_stmt (body);
  if (clab)
    add_stmt (build1 (LABEL_EXPR, void_type_node, clab));
  if (incr)
    add_stmt (incr);
...

I tell it to add multiple copies of body and incr and the at the end
add in the loop the rest of it. I've also added support to remove
further unrolling to these modified loops and will be handling the
"No-unroll" pragma. I then let the rest of the optimization passes,
fuse the incrementations together if possible,  etc.

The initial results are quite good and seem to work and produce good code.

Currently, there are two possibilities :

- If the loop is not in the form we want, for example:

for (;i<n;)
{
    ...
}

Do we still unroll even though we have to trust the user that the
number of unrolling will not break the semantics ?

To handle this, I am adding warnings that will appear if the loop is
anything but :

for (i=C1; i < C2; i ++)
{
...
}

Later on, once this is thoroughly tested, I will allow :

for (i=C1; fct (i, C2); i = fct2 (i))


where fct is any comparison function with only i and C2,
         fct2 is a incrementation/decrementation calculation using i.


Any comments ? Concerns ? Questions ?
Thanks in advance,
Jc

On Thu, Oct 8, 2009 at 12:22 PM, Jean Christophe Beyler
<jean.christophe.beyler@gmail.com> wrote:
> Hi,
>
>> such an epilogue is needed when the # of iterations is not known in the
>> compile time; it should be fairly easy to modify the unrolling not to
>> emit it when it is not necessary,
>
> Agreed, that is why I was surprised to see this in my simple example.
> It seems to me that the whole unrolling process has been made to, on
> purpose, have this epilogue in place.
>
> In the case where the unrolling would be perfect (ie. there would be
> no epilogue), the calculation of the max bound of the unrolled version
> is always done to have this epilogue (if you have 4 iterations and ask
> to unroll twice, it will actually change the max bound to 3,
> therefore, having one iteration of the unrolled version and 2
> iterations of the original...). I am currently looking at the code of
> tree_transform_and_unroll_loop to figure out how to change this and
> not have an epilogue in my cases.
>
> Jc
>

  reply	other threads:[~2009-10-14 18:29 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-05 20:46 Jean Christophe Beyler
2009-10-06  6:54 ` Zdenek Dvorak
2009-10-06 13:34   ` Jean Christophe Beyler
     [not found]     ` <20091006135624.GA18714@kam.mff.cuni.cz>
     [not found]       ` <c568a2600910060756m96adf86mb1507c6717fdfdb6@mail.gmail.com>
     [not found]         ` <20091006150918.GA19277@kam.mff.cuni.cz>
     [not found]           ` <c568a2600910060828l24ec5ecct926eb2624a1d2157@mail.gmail.com>
2009-10-08 16:18             ` Jean Christophe Beyler
2009-10-08 16:23               ` Zdenek Dvorak
2009-10-08 18:52                 ` Jean Christophe Beyler
2009-10-14 18:56                   ` Jean Christophe Beyler [this message]
2009-10-15  0:45                     ` Zdenek Dvorak
2009-10-15 10:00                     ` Bingfeng Mei
2009-10-15 14:41                       ` Zdenek Dvorak
2009-10-15 15:56                         ` Jean Christophe Beyler
2009-10-15 16:27                           ` Bingfeng Mei
2009-10-15 17:16                             ` Jean Christophe Beyler
2009-10-16 12:17                               ` Bingfeng Mei
2009-10-16 13:51                                 ` Jean Christophe Beyler

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=c568a2600910141129i75b2fa2bre4aff548ed376905@mail.gmail.com \
    --to=jean.christophe.beyler@gmail.com \
    --cc=gcc@gcc.gnu.org \
    --cc=rakdver@kam.mff.cuni.cz \
    /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).