public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Kito Cheng <kito.cheng@gmail.com>
To: juzhe.zhong@rivai.ai
Cc: gcc-patches@gcc.gnu.org, palmer@dabbelt.com
Subject: Re: [PATCH] RISC-V: Add probability model of each block to prevent endless loop of Phase 3
Date: Fri, 27 Jan 2023 03:16:48 +0800	[thread overview]
Message-ID: <CA+yXCZAuJQ35zC_HJUhmUMx_MGbX4OufRtPdq56TzEPpnVyLFQ@mail.gmail.com> (raw)
In-Reply-To: <20230109231720.155773-1-juzhe.zhong@rivai.ai>

[-- Attachment #1: Type: text/plain, Size: 3857 bytes --]

committed, thanks.

On Tue, Jan 10, 2023 at 7:17 AM <juzhe.zhong@rivai.ai> wrote:

> From: Ju-Zhe Zhong <juzhe.zhong@rivai.ai>
>
> Notice that the PASS is just simpily pick the probability >= 50%
> to do the backward fusion which will create endless loop on Phase 3.
>
> Adding this probability to fix this bug.
> gcc/ChangeLog:
>
>         * config/riscv/riscv-vsetvl.cc
> (vector_infos_manager::vector_infos_manager): Add probability.
>         (vector_infos_manager::dump): Ditto.
>         (pass_vsetvl::compute_probabilities): Ditto.
>         * config/riscv/riscv-vsetvl.h (struct vector_block_info): Ditto.
>
> ---
>  gcc/config/riscv/riscv-vsetvl.cc | 39 ++++++++++++++++++++++++++++++++
>  gcc/config/riscv/riscv-vsetvl.h  |  3 +++
>  2 files changed, 42 insertions(+)
>
> diff --git a/gcc/config/riscv/riscv-vsetvl.cc
> b/gcc/config/riscv/riscv-vsetvl.cc
> index 0f12d4ddb23..7d8c3a32aaa 100644
> --- a/gcc/config/riscv/riscv-vsetvl.cc
> +++ b/gcc/config/riscv/riscv-vsetvl.cc
> @@ -1465,6 +1465,7 @@ vector_infos_manager::vector_infos_manager ()
>           vector_block_infos[bb->index ()].reaching_out = vector_insn_info
> ();
>           for (insn_info *insn : bb->real_insns ())
>             vector_insn_infos[insn->uid ()].parse_insn (insn);
> +         vector_block_infos[bb->index ()].probability =
> profile_probability ();
>         }
>      }
>  }
> @@ -1642,6 +1643,8 @@ vector_infos_manager::dump (FILE *file) const
>         }
>        fprintf (file, "<FOOTER>=");
>        vector_block_infos[cfg_bb->index].reaching_out.dump (file);
> +      fprintf (file, "<Probability>=");
> +      vector_block_infos[cfg_bb->index].probability.dump (file);
>        fprintf (file, "\n\n");
>      }
>
> @@ -1764,6 +1767,7 @@ private:
>
>    void init (void);
>    void done (void);
> +  void compute_probabilities (void);
>
>  public:
>    pass_vsetvl (gcc::context *ctxt) : rtl_opt_pass (pass_data_vsetvl,
> ctxt) {}
> @@ -2629,6 +2633,41 @@ pass_vsetvl::done (void)
>    m_vector_manager = nullptr;
>  }
>
> +/* Compute probability for each block.  */
> +void
> +pass_vsetvl::compute_probabilities (void)
> +{
> +  /* Don't compute it in -O0 since we don't need it.  */
> +  if (!optimize)
> +    return;
> +  edge e;
> +  edge_iterator ei;
> +
> +  for (const bb_info *bb : crtl->ssa->bbs ())
> +    {
> +      basic_block cfg_bb = bb->cfg_bb ();
> +      auto &curr_prob
> +       = m_vector_manager->vector_block_infos[cfg_bb->index].probability;
> +      if (ENTRY_BLOCK_PTR_FOR_FN (cfun) == cfg_bb)
> +       curr_prob = profile_probability::always ();
> +      gcc_assert (curr_prob.initialized_p ());
> +      FOR_EACH_EDGE (e, ei, cfg_bb->succs)
> +       {
> +         auto &new_prob
> +           =
> m_vector_manager->vector_block_infos[e->dest->index].probability;
> +         if (!new_prob.initialized_p ())
> +           new_prob = curr_prob * e->probability;
> +         else if (new_prob == profile_probability::always ())
> +           continue;
> +         else
> +           new_prob += curr_prob * e->probability;
> +       }
> +    }
> +  auto &exit_block
> +    = m_vector_manager->vector_block_infos[EXIT_BLOCK_PTR_FOR_FN
> (cfun)->index];
> +  exit_block.probability = profile_probability::always ();
> +}
> +
>  /* Lazy vsetvl insertion for optimize > 0. */
>  void
>  pass_vsetvl::lazy_vsetvl (void)
> diff --git a/gcc/config/riscv/riscv-vsetvl.h
> b/gcc/config/riscv/riscv-vsetvl.h
> index 563ad3084ed..fb3ebb9db79 100644
> --- a/gcc/config/riscv/riscv-vsetvl.h
> +++ b/gcc/config/riscv/riscv-vsetvl.h
> @@ -291,6 +291,9 @@ struct vector_block_info
>    /* The reaching_out vector insn_info of the block.  */
>    vector_insn_info reaching_out;
>
> +  /* The static execute probability of the demand info.  */
> +  profile_probability probability;
> +
>    vector_block_info () = default;
>  };
>
> --
> 2.36.1
>
>

      reply	other threads:[~2023-01-26 19:17 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-09 23:17 juzhe.zhong
2023-01-26 19:16 ` Kito Cheng [this message]

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=CA+yXCZAuJQ35zC_HJUhmUMx_MGbX4OufRtPdq56TzEPpnVyLFQ@mail.gmail.com \
    --to=kito.cheng@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=juzhe.zhong@rivai.ai \
    --cc=palmer@dabbelt.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).