> -----Original Message----- > From: Richard Biener <rguent...@suse.de> > Sent: Thursday, July 13, 2023 12:49 PM > To: Tamar Christina <tamar.christ...@arm.com> > Cc: gcc-patches@gcc.gnu.org; nd <n...@arm.com>; j...@ventanamicro.com > Subject: Re: [PATCH 8/19]middle-end: updated niters analysis to handle > multiple exits. > > On Wed, 28 Jun 2023, Tamar Christina wrote: > > > Hi All, > > > > For early break vectorization we have to update niters analysis to > > record and analyze all exits of the loop, and so all conds. > > > > The niters of the loop is still determined by the main/natural exit of > > the loop as this is the O(n) bounds. For now we don't do much with > > the secondary conds, but their assumptions can be used to generate > versioning checks later. > > > > Bootstrapped Regtested on aarch64-none-linux-gnu and no issues. > > > > Ok for master? > > I probably confused vec_init_exit_info in the previous patch - that said, I'm > missing a clear function that determines the natural exit of the original (if- > converted) scalar loop. As vec_init_exit_info seems to (re-)compute that I'll > comment on it here.
Ah was wondering if you'd seen it 😊 > > + /* The main IV is to be determined by the block that's the first > reachable > + block from the latch. We cannot rely on the order the loop analysis > + returns and we don't have any SCEV analysis on the loop. */ > + auto_vec <edge> workset; workset.safe_push (loop_latch_edge (loop)); > + hash_set <edge> visited; > + > + while (!workset.is_empty ()) > + { > + edge e = workset.pop (); > + if (visited.contains (e)) > + continue; > + > + bool found_p = false; > + for (edge ex : e->src->succs) > + { > + if (exits.contains (ex)) > + { > + found_p = true; > + e = ex; > + break; > + } > + } > + > + if (found_p) > + { > + loop->vec_loop_iv = e; > + for (edge ex : exits) > + if (e != ex) > + loop->vec_loop_alt_exits.safe_push (ex); > + return; > + } > + else > + { > + for (edge ex : e->src->preds) > + workset.safe_insert (0, ex); > + } > + visited.add (e); > + } > > So this greedily follows edges from the latch and takes the first exit. Why's > that better than simply choosing the first? > > I'd have done > > auto_vec<edge> exits = get_loop_exit_edges (loop); for (e : exits) > { > if (vect_get_loop_niters (...)) > { > if no assumptions use that edge, if assumptions continue > searching, maybe ther's an edge w/o assumptions > } > } > use (first) exit with assumptions > > we probably want to know 'may_be_zero' as well and prefer an edge without > that. So eventually call number_of_iterations_exit_assumptions > directly and look for the best niter_desc and pass that to > vect_get_loop_niters > (or re-do the work). > > As said for "copying" the exit to the loop copies use the block mapping. > The issue is with the scalar loops, where we have no SCEV data and also no SSA mapping data (from what I can tell, the map was cleared in ifcvt itself). So for this to work with SCEV, we'd have to start analyzing the loop coming out of LOOP_VINFO_SCALAR_LOOP as well unless I'm missing something? Regards, Tamar