public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <richard.guenther@gmail.com>
To: Alexandre Oliva <oliva@adacore.com>, Jakub Jelinek <jakub@redhat.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: move unreachable user labels to entry point
Date: Tue, 13 Jul 2021 09:56:41 +0200	[thread overview]
Message-ID: <CAFiYyc3=L=fzqw2s=WeP82fvXRjvWNNOcM37B4EPmbh1a878OA@mail.gmail.com> (raw)
In-Reply-To: <orim1eucvv.fsf@lxoliva.fsfla.org>

On Tue, Jul 13, 2021 at 5:11 AM Alexandre Oliva <oliva@adacore.com> wrote:
>
>
> pr42739.C, complicated by some extra wrappers and cleanups from a
> feature I'm working on, got me very confused because a user label
> ended up in a cleanup introduced by my pass, where it couldn't
> possibly have been initially.
>
> The current logic may move such an unreachable user label multiple
> times, if it ends up in blocks that get removed one after the other.
> Since it doesn't really matter where it lands (save for omp
> constraints), I propose we move it once and for all to a stable, final
> location, that we currently use only as a last resort: the entry
> point.
>
> Regstrapped on x86_64-linux-gnu.  Ok to install?
>
>
> for  gcc/ChangeLog
>
>         * tree-cfg.c (remove_bb): When preserving an unreachable user
>         label, use the entry block as the preferred choice for its
>         surviving location, rather than as a last resort.
> ---
>  gcc/tree-cfg.c |   18 +++++-------------
>  1 file changed, 5 insertions(+), 13 deletions(-)
>
> diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c
> index 1f0f4a2c6eb2c..f6f005f10a9f5 100644
> --- a/gcc/tree-cfg.c
> +++ b/gcc/tree-cfg.c
> @@ -2300,13 +2300,11 @@ remove_bb (basic_block bb)
>                   FORCED_LABEL (gimple_label_label (label_stmt)) = 1;
>                 }
>
> -             new_bb = bb->prev_bb;
> -             /* Don't move any labels into ENTRY block.  */
> -             if (new_bb == ENTRY_BLOCK_PTR_FOR_FN (cfun))
> -               {
> -                 new_bb = single_succ (new_bb);
> -                 gcc_assert (new_bb != bb);
> -               }
> +             /* We have to move the unreachable label somewhere.
> +                Moving it to the entry block makes sure it's moved at
> +                most once, and avoids messing with anonymous landing
> +                pad labels.  */
> +             new_bb = single_succ (ENTRY_BLOCK_PTR_FOR_FN (cfun));
>               if ((unsigned) bb->index < bb_to_omp_idx.length ()
>                   && ((unsigned) new_bb->index >= bb_to_omp_idx.length ()
>                       || (bb_to_omp_idx[bb->index]
> @@ -2316,7 +2314,6 @@ remove_bb (basic_block bb)
>                      into the right OMP region.  */

The comment above says

                  /* During cfg pass make sure to put orphaned labels
                     into the right OMP region.  */

and the full guard is

              if ((unsigned) bb->index < bb_to_omp_idx.length ()
                  && ((unsigned) new_bb->index >= bb_to_omp_idx.length ()
                      || (bb_to_omp_idx[bb->index]
                          != bb_to_omp_idx[new_bb->index])))

The <em>right</em> OMP region suggests something wrt correctness
(though the original choice of bb->prev_bb doesn't put the initial new_bb
in an semantic relation to the original block).

So I wonder what the code was for an whether we still need it.
The ENTRY_BLOCK successor can be in some OMP region I guess
but we're still falling back to a "mismatched" OMP region in case
it was.  Then we could also insert on the ENTRY_BLOCK single successor
edge...

That said, the patch doesn't look incorrect - it just tweaks heuristics - but
the OMP code looks odd.

Richard.

>                   unsigned int i;
>                   int idx;
> -                 new_bb = NULL;
>                   FOR_EACH_VEC_ELT (bb_to_omp_idx, i, idx)
>                     if (i >= NUM_FIXED_BLOCKS
>                         && idx == bb_to_omp_idx[bb->index]
> @@ -2325,11 +2322,6 @@ remove_bb (basic_block bb)
>                         new_bb = BASIC_BLOCK_FOR_FN (cfun, i);
>                         break;
>                       }
> -                 if (new_bb == NULL)
> -                   {
> -                     new_bb = single_succ (ENTRY_BLOCK_PTR_FOR_FN (cfun));
> -                     gcc_assert (new_bb != bb);
> -                   }
>                 }
>               new_gsi = gsi_after_labels (new_bb);
>               gsi_remove (&i, false);
>
> --
> Alexandre Oliva, happy hacker                https://FSFLA.org/blogs/lxo/
>    Free Software Activist                       GNU Toolchain Engineer
> Disinformation flourishes because many people care deeply about injustice
> but very few check the facts.  Ask me about <https://stallmansupport.org>

  reply	other threads:[~2021-07-13  7:56 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-13  3:11 Alexandre Oliva
2021-07-13  7:56 ` Richard Biener [this message]
2021-07-13  8:52   ` Jakub Jelinek
2021-07-13  9:24     ` Richard Biener
2021-08-17 11:20   ` Alexandre Oliva

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='CAFiYyc3=L=fzqw2s=WeP82fvXRjvWNNOcM37B4EPmbh1a878OA@mail.gmail.com' \
    --to=richard.guenther@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@redhat.com \
    --cc=oliva@adacore.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).