On Thu, Dec 30, 2021 at 04:08:25AM -0600, Segher Boessenkool wrote:
> > The following simple patch makes sure we call can_get_prologue even after
> > the last former iteration when vec is already empty and only break from
> > the loop afterwards (and only if the updating of pro done because of
> > !can_get_prologue didn't push anything into vec again).
During the development of the above patch I've noticed that in many cases
we call can_get_prologue often on the same pro again and again and again,
we can have many basic blocks pushed into vec and if most of those don't
require pro updates, i.e.
basic_block bb = vec.pop ();
if (!can_dup_for_shrink_wrapping (bb, pro, max_grow_size))
while (!dominated_by_p (CDI_DOMINATORS, bb, pro))
isn't true, then pro is can_get_prologue checked for each bb in the vec.
The following simple patch just remembers which bb we've verified already
and verifies again only when pro changes. Most of the patch is just
reindentation.
2022-01-04 Jakub Jelinek <jakub@redhat.com>
PR rtl-optimization/103860
* shrink-wrap.c (try_shrink_wrapping): Don't call can_get_prologue
uselessly for blocks for which it has been called already.
unsigned max_grow_size = get_uncond_jump_length ();
max_grow_size *= param_max_grow_copy_bb_insns;
+ basic_block checked_pro = NULL;
+
while (pro != entry)
{
- while (pro != entry && !can_get_prologue (pro, prologue_clobbered))
+ if (pro != checked_pro)
{
- pro = get_immediate_dominator (CDI_DOMINATORS, pro);
+ while (pro != entry && !can_get_prologue (pro, prologue_clobbered))
+ {
+ pro = get_immediate_dominator (CDI_DOMINATORS, pro);
- if (bitmap_set_bit (bb_with, pro->index))
- vec.quick_push (pro);
+ if (bitmap_set_bit (bb_with, pro->index))
+ vec.quick_push (pro);
+ }
+ checked_pro = pro;
}
if (vec.is_empty ())