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.
This commit is contained in:
parent
7ae4d1dfb8
commit
acc10c7931
2 changed files with 42 additions and 0 deletions
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue