On Sat, Aug 29, 2026 at 11:19 AM Aldy Hernandez <[email protected]> wrote: > > On Fri, Aug 28, 2026 at 03:45:14PM +0200, Richard Biener wrote: > > 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). > > My bad, I think I was overthinking this. The PHI bookkeeping was for > a case where the prevailing edge jumps back into the copied region. > Trunk doesn't handle this currently, so there's no regression in not > bending over backwards to handle this. > > However, ordinary paths commonly thread back into themselves, and > those must keep working — refusing an exit that reenters the path > regresses various tests. See current patch. > > Ughh, clearly I don't know what I'm doing here. > > How about this version?
LGTM. Richard. > > Aldy
