Thanks Richard. Seems that this patch's approach is ok to trunk? Maybe the only thing we should do is to wait Kewen's testing feedback, am I right ? Thanks. juzhe.zhong@rivai.ai From: Richard Sandiford Date: 2023-05-31 17:01 To: Richard Biener via Gcc-patches CC: Richard Biener; juzhe.zhong\@rivai.ai; linkw Subject: Re: [PATCH] VECT: Change flow of decrement IV Richard Biener via Gcc-patches writes: > On Wed, 31 May 2023, Richard Sandiford wrote: > >> Richard Biener writes: >> > On Wed, 31 May 2023, juzhe.zhong@rivai.ai wrote: >> > >> >> Hi?all. I have posted my several investigations: >> >> https://gcc.gnu.org/pipermail/gcc-patches/2023-May/620101.html >> >> https://gcc.gnu.org/pipermail/gcc-patches/2023-May/620105.html >> >> https://gcc.gnu.org/pipermail/gcc-patches/2023-May/620108.html >> >> >> >> Turns out when "niters is a constant value and vf is a constant value" >> >> This patch can allow SCEV/IVOPTS optimize a lot for RVV too (Take tesecase from IBM's testsuite for example) and I think this patch can fix IBM's cunroll issue. >> >> Even though it will produce a 'mv' instruction in some ohter cases for RVV, I think Gain > Pain overal. >> >> >> >> Actually, for current flow: >> >> >> >> step = MIN () >> >> ... >> >> remain = remain - step. >> >> >> >> I don't know how difficult to extend SCEV/IVOPTS to fix this issue. >> >> So, could you make a decision for this patch? >> >> >> >> I wonder whether we should apply the approach of this patch (the codes can be refined after well reviewed) or >> >> we should extend SCEV/IVOPTS ? >> > >> > I don't think we can do anything in SCEV for this which means we'd >> > need to special-case this in niter analysis, in IVOPTs and any other >> > passes that might be affected (and not fixed by handling it in niter >> > analysis). While improving niter analysis would be good (the user >> > could write this pattern as well) I do not have time to try >> > implementing that (I have no idea how ugly or robust it is going to be). >> > >> > So I think we should patch this up in the vectorizer itself like with >> > your patch. I'm going to wait for Richards input though since he >> > seems to disagree. >> >> I think my main disagreement is that the IV phi can be analysed >> as a SCEV with sufficient work (realising that the MIN result is >> always VF when the latch is executed). That SCEV might be useful >> ?as is? for things like IVOPTS, without specific work in those passes. >> (Although perhaps not too useful, since most other IVs will be upcounting.) > > I think we'd need another API for SCEV there then, > analyze_scalar_evolution_for_latch () so we can disregard the > value on the exit edges then. That means we'd still need to touch > all users and decide whether it's safe to use that or not. I'd expect the phi for the IV with the constant step to have the same value as the phi for the IV with a MIN step. I realise that the phi isn't the thing that matters for niters, but I'd expect IVOPTS to consider both the phi and the adjusted value to be candidates. Only the phi can be a candidate with the MIN step, but it feels like it should still be a candidate, even with current interfaces. You know this stuff much better than I do though, so I^m almost certainly oversimplifying/overlooking things. Like I say, I don't object to the vectoriser change, so please don't go down a rabbit hole on my account. :) Thanks, Richard