> Currently we do this by generating the comparison and then applying 
> the loop
> length to its result through VCOND_MASK_LEN.  In outline, this looks like
>
>   cmp = values == zeroes;
>   exit_mask = .VCOND_MASK_LEN (cmp, all_ones, all_zeroes, len, bias);
>
> In the early break patch series I sent Robin raised the question whether this
> would work for them. My preference is to keep the LEN path similar to the 
> masked
> and unmasked targets and so not to diverge too much in terms of control flow
> handling.
>
> After having a very productive chat with Robin at the Cauldron I understand 
> that
> the issue RISC-V has is that the LEN masking today is done though 
> VCOND_MASK_LEN
> which is an operation the target must implement for the check to pass.

I'll recap here what we discussed on IRC:  What I didn't really make 
clear (neither at the Cauldron nor in my previous responses, in fact I 
only realized it myself clearly recently) is that for RVV no mask setter 
can zero tail elements (very unfortunate) and they always stay in an 
undefined state.  So the issue we had with VCOND_MASK_LEN we have here 
again, just moved to COND_LEN_VEC_CMP (which needs to set a mask for the 
vector comparison to read).

Now, for all imaginable cases, this works because obviously the loop 
will be length masked, otherwise we wouldn't emit COND_LEN...  But 
semantics-wise we leave the tail elements unspecified which, at least 
theoretically, opens up a possibility for wrong code.  To work around 
this and ensure mask tail elements are zeroed at the RTL level, we are 
forced to build a Pmode vector that holds the length and AND it with the 
mask.  This leads to unfortunately large vectors and inhibits proper 
vectorization by restricting the available optabs.

Tamar generously wrote the patch based on my incomplete information with 
the best intentions but I'm afraid we need to diverge in terms of 
codegen.  Tamar, I have a local patch on top of your many others that 
uses a scalar compare after the IFN_COND_LEN_OTHER_NAME we discussed.  
I'll post it once it's ready, hopefully soon.  IMHO nothing in the LEN 
department should block your other patches in any way.

Again, thank you for the extra work and sorry for the wrong lead.

-- 
Regards
 Robin

Reply via email to