public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Kito Cheng <kito@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-5415] RISC-V: Add probability model of each block to prevent endless loop of Phase 3 Date: Thu, 26 Jan 2023 19:12:56 +0000 (GMT) [thread overview] Message-ID: <20230126191256.D7F8F3858C20@sourceware.org> (raw) https://gcc.gnu.org/g:acc10c793127d5683b19158fd89fd0d4f4fc9db0 commit r13-5415-gacc10c793127d5683b19158fd89fd0d4f4fc9db0 Author: Ju-Zhe Zhong <juzhe.zhong@rivai.ai> Date: Tue Jan 10 07:17:20 2023 +0800 RISC-V: Add probability model of each block to prevent endless loop of Phase 3 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. Diff: --- 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 2f9de9d2026..02bdfebbb58 100644 --- a/gcc/config/riscv/riscv-vsetvl.cc +++ b/gcc/config/riscv/riscv-vsetvl.cc @@ -1466,6 +1466,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 (); } } } @@ -1643,6 +1644,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"); } @@ -1765,6 +1768,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) {} @@ -2625,6 +2629,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 7b56802faec..ef1064e11bd 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; };
reply other threads:[~2023-01-26 19:12 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20230126191256.D7F8F3858C20@sourceware.org \ --to=kito@gcc.gnu.org \ --cc=gcc-cvs@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: linkBe 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).