public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "aldyh at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug middle-end/102997] [12 Regression] 45% 454.calculix regression with LTO+PGO -march=native -Ofast on Zen since r12-4526-gd8edfadfc7a9795b65177a50ce44fd348858e844
Date: Mon, 08 Nov 2021 15:34:17 +0000	[thread overview]
Message-ID: <bug-102997-4-VlyRZ13ZKq@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-102997-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102997

--- Comment #27 from Aldy Hernandez <aldyh at gcc dot gnu.org> ---
(In reply to Richard Biener from comment #20)
> (In reply to hubicka from comment #19)

> > The testcase would be
> > 
> > void test ()
> > {
> >         int i;
> >         if (test())
> >           i=0;
> >         else
> >           i=100;
> >         for (;i<100 && bar ();i++)
> >                 do_work ();
> > }

Updated test that compiles:
int check();
int bar ();
void do_work ();

void test ()
{
  int i;
  if (check())
    i=0;
  else
    i=100;
  for (;i<100 && bar ();i++)
    do_work ();
}


> > 
> > Here I think we can thread else path to return w/o any issues with loop
> > nests even with -Os.
> 
> we fail this because
> 
>   // If we crossed a loop into an outer loop without crossing the
>   // latch, this is just an early exit from the loop.
>   if (loops_crossed == 1
>       && !crossed_latch
>       && flow_loop_nested_p (exit->dest->loop_father,
> exit->src->loop_father))
>     return false;
> 
> does not trigger (loops_crossed == 2), and we then run into
> 
> 
>   if (loops_crossed)
>     {
>       cancel_thread (&path, "Path crosses loops");
>       return true;
>     }
> 
> but the loops_crossed stuff is old and not from me, not sure what that's
> useful for.  We could "fix" the accounting with
> 
> diff --git a/gcc/tree-ssa-threadupdate.c b/gcc/tree-ssa-threadupdate.c
> index 8aac733ac25..52ec22e85e1 100644
> --- a/gcc/tree-ssa-threadupdate.c
> +++ b/gcc/tree-ssa-threadupdate.c
> @@ -2810,7 +2810,7 @@ jt_path_registry::cancel_invalid_paths
> (vec<jump_thread_edge *> &path)
>  
>    // If we crossed a loop into an outer loop without crossing the
>    // latch, this is just an early exit from the loop.
> -  if (loops_crossed == 1
> +  if (loops_crossed <= 2
>        && !crossed_latch
>        && flow_loop_nested_p (exit->dest->loop_father,
> exit->src->loop_father))
>      return false;

The above patch doesn't cause any difference in the generated code, at least
for -O2.  I also don't see any more paths registered:

$ grep Registering.jump a.c.*
a.c.126t.thread1:  [1] Registering jump thread: (2, 4) incoming edge;  (4, 8)
nocopy; 
a.c.126t.thread1:  [2] Registering jump thread: (3, 4) incoming edge;  (4, 7)
nocopy; 
a.c.192t.dom3:  [4] Registering jump thread: (6, 5) incoming edge;  (5, 4)
joiner (4, 7) normal; 

> 
> to also allow to thread through a loop path not crossing the latch but
> at least for the issue of "breaking loops" the loops_crossed stuff shouldn't
> be necessary.  It might still prevent us from doing such transforms when
> it involves peeling.

This loops crossing stuff is indeed quite old.  Are you suggesting this as
well?

-  if (loops_crossed)
-    {
-      cancel_thread (&path, "Path crosses loops");
-      return true;
-    }

Which, BTW doesn't change the behavior for this test, but I'm happy to test if
you think it's not necessary.

  parent reply	other threads:[~2021-11-08 15:34 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-29 10:05 [Bug middle-end/102997] New: 45% calculix regression with LTO+PGO -march=native -Ofast between ce4d1f632ff3f680550d3b186b60176022f41190 and 6fca1761a16c68740f875fc487b98b6bde8e9be7 on Zen hubicka at gcc dot gnu.org
2021-10-29 10:42 ` [Bug middle-end/102997] [12 Regression] 45% 454.calculix " rguenth at gcc dot gnu.org
2021-10-29 11:43   ` Jan Hubicka
2021-10-29 10:55 ` rguenth at gcc dot gnu.org
2021-10-29 11:00 ` rguenth at gcc dot gnu.org
2021-10-29 11:38 ` hubicka at kam dot mff.cuni.cz
2021-10-29 11:43 ` hubicka at kam dot mff.cuni.cz
2021-11-01 10:10 ` marxin at gcc dot gnu.org
2021-11-01 10:18 ` marxin at gcc dot gnu.org
2021-11-01 12:42 ` [Bug middle-end/102997] [12 Regression] 45% 454.calculix regression with LTO+PGO -march=native -Ofast on Zen since r12-4526-gd8edfadfc7a9795b65177a50ce44fd348858e844 marxin at gcc dot gnu.org
2021-11-01 15:05 ` aldyh at gcc dot gnu.org
2021-11-01 16:33 ` hubicka at kam dot mff.cuni.cz
2021-11-08  7:40 ` aldyh at gcc dot gnu.org
2021-11-08  7:43 ` aldyh at gcc dot gnu.org
2021-11-08  8:06 ` aldyh at gcc dot gnu.org
2021-11-08  8:24 ` marxin at gcc dot gnu.org
2021-11-08  8:25 ` rguenther at suse dot de
2021-11-08  8:33   ` Jan Hubicka
2021-11-08  8:33 ` hubicka at kam dot mff.cuni.cz
2021-11-08  8:34 ` aldyh at gcc dot gnu.org
2021-11-08  8:40 ` aldyh at gcc dot gnu.org
2021-11-08  8:51 ` hubicka at kam dot mff.cuni.cz
2021-11-08  9:50 ` rguenth at gcc dot gnu.org
2021-11-08 11:44 ` hubicka at kam dot mff.cuni.cz
2021-11-08 13:00 ` rguenther at suse dot de
2021-11-08 13:16 ` hubicka at kam dot mff.cuni.cz
2021-11-08 14:05 ` rguenther at suse dot de
2021-11-08 14:10 ` rguenth at gcc dot gnu.org
2021-11-08 14:19 ` rguenth at gcc dot gnu.org
2021-11-08 15:34 ` aldyh at gcc dot gnu.org [this message]
2021-11-09  7:26 ` rguenther at suse dot de
2021-11-12 13:42 ` marxin at gcc dot gnu.org
2021-11-12 13:56 ` rguenth at gcc dot gnu.org
2021-11-12 16:05 ` hubicka at kam dot mff.cuni.cz

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=bug-102997-4-VlyRZ13ZKq@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@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).