> -----Original Message-----
> From: Robin Dapp <[email protected]>
> Sent: 09 November 2026 21:53
> To: Tamar Christina <[email protected]>; Robin Dapp
> <[email protected]>; Richard Biener <[email protected]>
> Cc: [email protected]
> Subject: Re: [PATCH 2/3] vect: Add index-based early-break type/kind.
> 
> > The second vfirst won't be redundant. It'll be removed by CSE in RTL.
> > That's how it works for Adv. SIMD as well.  Both the compare and the
> > extract code redo the same computation using addhn, and the one in
> > the exit is removed because it's the exact same one as in the loop.
> >
> > So as long as your RTL reflects that the operations are the same (
> > which they should be as they operate on the same inputs and len) then
> > the second vfirst should be removed leaving you with the optimal case
> > no?
> 
> Right, I guess with a bit of combine magic and CSE we could turn
> 
>  idx = vfirst
>  idx = idx != -1
>  branch
>  idx = vfirst
>  ...
> 
> into the optimal sequence.
> 
> So yea, I think I'll just go ahead with it, I'll be busy with the
> peeling issue still anyway and getting something in is my main priority.
> All we need is a proper new IFN for it which is not called IFN_COMPRESS.
> IFN_ANY_ACTIVE? IFN_...?
> 

IFN_ANY_ACTIVE works for me. 

> I suppose your idea is for this new IFN to abstract away what every
> target does and keep the rest mostly the same?
> 

Yeah,  The early break code will keep getting more complicated and I'm
hoping unless we really need to, not to have different paths through
the vectorizer.  Maintaining the UNMASKED, COND and COND_LEN paths
is getting trickier already since it's hard to test the fully separate paths.

My hope is by not splitting unless we need to, the code is easier to maintain
and test.

> Or would the discriminator be IFN_... + vec_cbranch availability?  The
> live-operation changes would be smaller, just that we'd still need the
> bit of can_vec_var_idx etc. plumbing (as we'd materialize the index from
> the mask on the fly so to say).
> 

Sure, Adv. SIMD doesn't have a native operation for EXTRACT_FIRST_ACTIVE
either and so it emulates it.   The reason I didn't put this in the vectorizer
itself was because the method to obtain the lane index is optimized to
operations that are efficient in the target. i.e. using the fact that lanes are
-1 and 0 and using ADDHN to compress etc.

But I guess you want to open encode it based on a returned index.

> (That said, I still don't find the previous approach too bad, all things
> considered, as it wouldn't rely on CSE and combine and if we query the
> insn's "preferred" value at 0 we could also clearly distinguish: If -1
> and no vec_cbranch is supported -> index based, else mask based.)

Sure, but it's something that would need to keep happening everywhere
this is used in the future.   But if you and Richard want it sure go for it, I
won't object anymore.

Cheers,
Tamar

> 
> --
> Regards
>  Robin

Reply via email to