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>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] [PR105455] Set edge probabilities when hardening conditionals
Date: Thu, 12 May 2022 09:40:53 +0200	[thread overview]
Message-ID: <CAFiYyc18rnHCC=jTqadOsUOxt3DVZxhMZS2CSuF6ZU-o2-fkPw@mail.gmail.com> (raw)
In-Reply-To: <ormtfniktt.fsf@lxoliva.fsfla.org>

On Thu, May 12, 2022 at 3:48 AM Alexandre Oliva via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
>
> When turning unconditional edges into conditional, as in
> gimple-harden-conditionals.cc:insert_check_and_trap, the newly-created
> edge's probability comes out uninitialized, while the previously
> unconditional edge's probability is presumably
> profile_probability::always.
>
> Mixing initialized and uninitialized probabilities before expand
> breaks predict.cc:force_edge_cold: the initialized probability may end
> up copied to a REG_BR_PROB note in a conditional branch insn, but if
> force_edge_cold is called on that edge, it will find another edge with
> uninitialized probability and assume the note is absent.  Later on,
> rtl_verify_edges complains that the note does not match the
> probability modified by force_edge_cold in the edge.
>
> This patch sets probabilities for edges affected by hardening of
> conditionals, both the newly-created edges to trap blocks and the
> previously-unconditional edges, so that the former are considered
> never taken, while the latter are confirmed as always taken.
>
> Regstrapped on x86_64-linux-gnu.  Ok to install?

OK.

>
> for  gcc/ChangeLog
>
>         PR rtl-optimization/105455
>         * gimple-harden-conditionals.cc (insert_check_and_trap): Set
>         probabilities for newly-conditional edges.
>
> for  gcc/testsuite/ChangeLog
>
>         PR rtl-optimization/105455
>         * gcc.dg/pr105455.c: New.
> ---
>  gcc/gimple-harden-conditionals.cc |    2 ++
>  gcc/testsuite/gcc.dg/pr105455.c   |   17 +++++++++++++++++
>  2 files changed, 19 insertions(+)
>  create mode 100644 gcc/testsuite/gcc.dg/pr105455.c
>
> diff --git a/gcc/gimple-harden-conditionals.cc b/gcc/gimple-harden-conditionals.cc
> index 28c4810f0a78e..240d0e5acd87a 100644
> --- a/gcc/gimple-harden-conditionals.cc
> +++ b/gcc/gimple-harden-conditionals.cc
> @@ -254,8 +254,10 @@ insert_check_and_trap (location_t loc, gimple_stmt_iterator *gsip,
>       equality.  */
>    single_succ_edge (chk)->flags &= ~EDGE_FALLTHRU;
>    single_succ_edge (chk)->flags |= neg_true_false_flag;
> +  single_succ_edge (chk)->probability = profile_probability::always ();
>    edge e = make_edge (chk, trp, true_false_flag);
>    e->goto_locus = loc;
> +  e->probability = profile_probability::never ();
>
>    if (dom_info_available_p (CDI_DOMINATORS))
>      set_immediate_dominator (CDI_DOMINATORS, trp, chk);
> diff --git a/gcc/testsuite/gcc.dg/pr105455.c b/gcc/testsuite/gcc.dg/pr105455.c
> new file mode 100644
> index 0000000000000..81e9154baa1c3
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/pr105455.c
> @@ -0,0 +1,17 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O1 -fharden-conditional-branches -funroll-loops --param max-loop-header-insns=1" } */
> +
> +__attribute__ ((cold)) void
> +bar (void);
> +
> +void
> +foo (int x)
> +{
> +  if (x)
> +    {
> +      int i;
> +
> +      for (i = 0; i < 101; ++i)
> +        bar ();
> +    }
> +}
>
>
> --
> 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:[~2022-05-12  7:41 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-12  1:46 Alexandre Oliva
2022-05-12  7:40 ` Richard Biener [this message]
2022-05-13  6:03   ` Alexandre Oliva
2022-05-13  6:13     ` Richard Biener

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='CAFiYyc18rnHCC=jTqadOsUOxt3DVZxhMZS2CSuF6ZU-o2-fkPw@mail.gmail.com' \
    --to=richard.guenther@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --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).