On Fri, Aug 28, 2026 at 8:35 AM Aldy Hernandez <[email protected]> wrote:
>
> On Wed, Aug 26, 2026 at 04:13:46PM +0200, Richard Biener wrote:
>
> > So I think we should maybe adjust copy_bbs then, for example
> > either by providing a hook to post-process new_bbs[] after
> > copying but before redirecting edges, or by more tailored, specify
> > a BB as exit implicitly by the exit edge that should prevail.  I'll
> > note that copy_bbs
> > is a bit generic here, we have a SEME region.
> >
> > That said, adding a "prevailing_exit" argument, and if set,
> > have edges outgoing from prevailing_exit->src copy that are
> > not going to prevailing_exit->dest removed rather than redirected
> > would be sound?
>
> OMG, you just _had_ to make it more complicated :).  I knew there was
> a reason I'd never touched that code in all these years.
>
> How about the attached?

Hmm.  So I was somehow expecting that changing

      FOR_EACH_EDGE (e, ei, new_bb->succs)
        {
          if (!(e->dest->flags & BB_DUPLICATED))
            continue;
          redirect_edge_and_branch_force (e, get_bb_copy (e->dest));
        }

to

     FOR_EACH_EDGE (e, ei, new_bb->succs)
        {
          if (prevailing_exit && bb == prevailing_exit->src &&
prevailing_exit->dest != e->dest)
           {
             remove_edge (e);
             continue;
           }
          if (!(e->dest->flags & BB_DUPLICATED))
            continue;
          redirect_edge_and_branch_force (e, get_bb_copy (e->dest));
        }

would have been enough?  That is, prevailing_exit->dest should of course
not be in the set of duplicated blocks.  Meaning I don't understand

+               /* ...but be careful with kept edges into the copied region,
+                  because their destinations are the originals (marked
+                  BB_DUPLICATED) so edge creation skipped growing their PHI
+                  arguments.  Any other such edge eventually has its PHI
+                  bookkeeping done by whatever redirects or removes it.  Since
+                  a kept edge is neither redirected nor removed, nothing
+                  will ever grow its destination's arguments.  Keep track of
+                  it to grow them at the end of this function.  */
+               if (e->dest->flags & BB_DUPLICATED)
+                 kept.safe_push (e);

this would mean you call this with an exit that isn't an exit which makes
it an awkward interface (and then sorry for misleading if this is what you
actuall need).

An interface change for eliding arbitrary edges would be via a hook
I guess.  But then why do you need sth special for the edge?  You
keep it duplicated but not redirected, so your in-region "exit" you'll
have to redirect yourself even after this change?  It will branch to
the original block at the moment.

Richard.

>
> Aldy

Reply via email to