public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Ulrich Drepper <drepper.fsp@gmail.com>
To: Xionghu Luo <luoxhu@linux.ibm.com>
Cc: Richard Biener <richard.guenther@gmail.com>,
	 Segher Boessenkool <segher@kernel.crashing.org>,
	Bill Schmidt <wschmidt@linux.ibm.com>,
	linkw@gcc.gnu.org,  GCC Patches <gcc-patches@gcc.gnu.org>,
	Jan Hubicka <hubicka@ucw.cz>,  David Edelsohn <dje.gcc@gmail.com>
Subject: Re: [RFC] Don't move cold code out of loop by checking bb count
Date: Tue, 10 Aug 2021 06:25:54 +0200	[thread overview]
Message-ID: <CAOPLpQdiuETKvQYHP+G0toncwiZ1GY8wo-SvGtgRyKnvtE45tA@mail.gmail.com> (raw)
In-Reply-To: <e9cc0874-b066-5eaf-6334-e7c8492a22a5@linux.ibm.com>

On Tue, Aug 10, 2021 at 4:03 AM Xionghu Luo via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
> For this case, theorotically I think the master GCC will optimize it to:
>
>   invariant;
>   for (;;)
>     if (unlikely_cond)
>       for (;;)
>          ;
>
> 'invariant' is moved out of outer loop, but with the patch, it will get:
>
>   for (;;)
>     if (unlikely_cond)
>       {
>         invariant;
>         for (;;)
>            ;
>       }
>
> 'invariant' is *cold* for outer loop, but it is still *hot* for inner loop,
> so hoist it out of inner loop, this is exactly what we want, right?

Is relying on absolute numbers really what you want?  If the
'unlikely_cond' condition depends on the iteration count of the outer
loop the probability of it being true in each individual iteration can
be low (at least that's how I use unlikely) but the overall
probability of needing the code is higher 1 - (1 - p)^n  if 'p' is the
probability of 'unlikely_cond' and 'n' is the number of iterations.
Assuming complete independence of the loop iterations, otherwise it's
rather an upper limit.

At the very least I'd generate code like this:

  first = true;
  for (;;)
    if (unlikely_cond)
      {
        if (first)
          {
            invariant;
            first = false;
          }
        for (;;)
           ;
      }

If it's worth hoisting the code the the extra test and flag should be
small in cost in comparison.

If 'unlikely_cond' does not in any way depend on the loop iteration
then I think your code generation is fine.

  reply	other threads:[~2021-08-10  4:26 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-02  5:05 Xiong Hu Luo
2021-08-06 12:15 ` Richard Biener
2021-08-10  2:03   ` Xionghu Luo
2021-08-10  4:25     ` Ulrich Drepper [this message]
2021-08-19  5:51       ` [PATCH v2] " Xionghu Luo
2021-08-26 11:33     ` [RFC] " Richard Biener
2021-09-09  1:55       ` Xionghu Luo
2021-09-22  9:14         ` Richard Biener
2021-09-23  2:13           ` Xionghu Luo
2021-09-23  2:16             ` Xionghu Luo
2021-09-24  6:29           ` Xionghu Luo
2021-09-28 12:09             ` Richard Biener
2021-10-09  3:44               ` Xionghu Luo
2021-10-15  8:11                 ` Richard Biener
2021-10-18  4:29                   ` Xionghu Luo
2021-10-19  1:47                     ` [PATCH v5 2/2] " Xionghu Luo
2021-10-26 13:20                     ` [RFC] " Richard Biener
2021-10-27  2:40                       ` Xionghu Luo
2021-10-29 11:48                         ` Richard Biener
2021-11-03  6:49                           ` Xionghu Luo
2021-11-03 13:29                           ` Xionghu Luo
2021-11-04 13:00                             ` Richard Biener
2021-11-10  3:08                               ` [PATCH v7 2/2] " Xionghu Luo
2021-11-24  5:15                                 ` Ping: " Xionghu Luo
2021-11-24  7:35                                   ` Richard Biener
2021-12-01 10:09                                 ` Richard Biener
2021-12-06  5:09                                   ` [PATCH v8 " Xionghu Luo
2021-12-06  5:26                                     ` Xionghu Luo
2021-12-07 12:17                                       ` Richard Biener
2021-12-08  6:32                                         ` Xionghu Luo
2021-12-20  7:29                                           ` Richard Biener
2021-12-21  3:59                                             ` Xionghu Luo
2021-10-27 12:54                 ` [RFC] " Jan Hubicka
2021-10-28  1:49                   ` Xionghu Luo

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=CAOPLpQdiuETKvQYHP+G0toncwiZ1GY8wo-SvGtgRyKnvtE45tA@mail.gmail.com \
    --to=drepper.fsp@gmail.com \
    --cc=dje.gcc@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=hubicka@ucw.cz \
    --cc=linkw@gcc.gnu.org \
    --cc=luoxhu@linux.ibm.com \
    --cc=richard.guenther@gmail.com \
    --cc=segher@kernel.crashing.org \
    --cc=wschmidt@linux.ibm.com \
    /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).