>> I don't see how it makes sense to specify the value for an empty mask
>> with _LEN but not with _MASK.  Can we instead add an optional value-at-zero
>> argument (to both) that we'd somehow validate with predicates like we
>> validate the BIAS for LEN?
>
> I honestly don't like re-defining INDEX_FIRST_ACTIVE to return -1.
> I haven't looked at the patch in detail yet but I think doing so is likely why
> All the changes in live operations were needed, because now you have to
> actually deal with the -1.

The idea is that the scalar branch after COND_LEN_INDEX_FIRST_ACTIVE is 
the only consumer of -1 (this is all vec_num == 1 for now) and every 
live out just sees the "mismatch index" (!= -1).  That way, we can just 
reuse the index for both the latch as well as the live values.  We don't 
have an "extract first active" so we would need to implement this as
  idx = COND_LEN_INDEX_FIRST_ACTIVE + VEC_EXTRACT (idx)
again.  In the end, it would just be one additional vfirst outside of 
the loop (and one live-out vector mask), so not too bad.

> I so I think adding the parameter makes it hard because as I mentioned before
> For non-masked targets like Adv. SIMD this ends up using operations undefined
> at zero.  And if RVV then only implements -1 as value-at-zero it means we 
> still
> need to define two paths in the vectorizer.

To play devil's advocate :)  Doesn't Adv SIMD's implementation depend on 
clz which has exactly this ambiguity of being unspecified for an empty 
input and thus a separate param?

> I really don't like that.  My suggestion before was to make a new 
> IFN_VEC_COMPRESS
> or something that returns a boolean and leave *_INDEX_FIRST_ACTIVE alone.  
> This
> means we don't have to split the UNCOND/COND/LEN paths.

>> > +  gimple_cond_set_condition (cond_stmt, index_based_p ? GE_EXPR :
>> NE_EXPR,  new_temp, cst);

> My preference would really be to have an IFN that does not enforce an 
> exact
> return value, just so we can make a boolean out of it.  I think the patch 
> shrinks
> significantly with that as it's only a local decision.

Yeah, I see where you're coming from (and understand that we want to 
modify the existing structure as little as possible).  The few changes 
in vectorizable_live... are for the "index" handling (but not because of 
the -1 in particular except for the hunk you quoted).

If we absolutely not want to bifurcate here (i.e. introduce an index 
type/kind), I guess I can adapt at the cost of a popcount in the loop, a 
redundant vfirst in the (cold) exit block and a live mask like:

  bla = IFN_OTHER_NAME # would defer to COND_LEN_COUNT_ACTIVE for RVV
  branch bla
  # exit
  bla = COND_LEN_INDEX_FIRST_ACTIVE # vfirst
  live_bla = VEC_EXTRACT (..., bla);

That's still ok, although not as nice as with one vfirst.  And at some 
point, of course, I'd like to optimize this to one.  But the popcount 
solution would still be better than what we have now, so I'd take it.

-- 
Regards
 Robin

Reply via email to