<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<div class="moz-cite-prefix">On 11/6/20 8:49 AM, Roger Ferrer Ibáñez wrote:<br>
</div>
<blockquote type="cite" cite="mid:CAGeEQ1j8zkCNYgmOCS6T5wJ538MOsA3kmNtuH+Ff6f7x+2KVfA@mail.gmail.com">
<div dir="ltr">
<div dir="ltr">
<div>Hi Sjoerd,<br>
</div>
<div><br>
</div>
</div>
<div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0px 0px 0px
0.8ex;border-left:1px solid
rgb(204,204,204);padding-left:1ex">
<div dir="ltr"><br>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
Trying to remember how everything fits together here, but could get.active.lane.mask not create the %mask of the VP intrinsics? Or in other words, in the vectoriser, who's producing the %mask and %evl that is consumed by the VP intrinsics?</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
</div>
</blockquote>
<div>
<div dir="ltr">
<div>I'm not sure what would be the best way here. I think about the Loop Vectorizer. I imagine at some point we can teach LV to emit VPred for the widening. VPred IR needs two additional operands, as you mentioned, %evl and %mask.<br>
</div>
<div><br>
</div>
<div>One option is make %evl the max-vector-length of the type being operated and %mask (that is the "outer block mask" in this context) be get.active.lane.mask. This maps well for SVE and MVE not so much for VE and RISC-V (I don't think it is incorrect but
it is not an efficient thing to do). Perhaps VE and RISC-V can work in this scenario if at some point they replace the %evl with something like "%n - %base" operands of get.active.lane.mask, and %mask (the outer block mask) is replaced with a splat of "i1
1".<br>
</div>
</div>
</div>
</div>
</div>
</blockquote>
Basically, we would extend TTI to let the targets choose how to use the %mask and %evl operands in the VP intrinsics. So, an 'fadd' would turn into an 'llvm.vp.fadd' for all predicating targets. However, whether get.active.lane.mask() is used for %mask or whether
tail predication is done with a (splat i1 1) for the mask and setting %evl would be target dependent.<br>
<br>
<blockquote type="cite" cite="mid:CAGeEQ1j8zkCNYgmOCS6T5wJ538MOsA3kmNtuH+Ff6f7x+2KVfA@mail.gmail.com">
<div dir="ltr">
<div class="gmail_quote">
<div>
<div dir="ltr">
<div>Another option here is make "%n - %base" be the %evl (or at least an operand of some target hook because "computing" the %evl is target-specific, targets without evl could compute the identity here) and %mask (the outer block mask) be a splat of "i1 1".
This maps well VE and RISC-V but makes life harder for AVX-512, SVE and MVE (in general any target where TargetTransformInfo::hasActiveVectorLength returns false). Those targets could replace the %evl with the max-vector-length of the operated type and then
use get.active.lane.mask(0, %evl) as the outer block mask. My understanding is that Simon used this approach in
<a href="https://reviews.llvm.org/D78203" moz-do-not-send="true">https://reviews.llvm.org/D78203</a> but in a more general setting, that would be independent of what Loop Vectorizer does.</div>
</div>
</div>
</div>
</div>
</blockquote>
<br>
For VE, we set %evl = min(max_vector_width, %n - %base) .. that's the same idiom that the non-LLVM NEC compilers are emitting for tail predication.<br>
Basically, the LV flow could look something like this:<br>
<br>
<br>
<font size="+1"><tt> ; Call the target hook to let the target select %mask and %evl params for the loop header</tt><tt><br>
</tt></font><font size="+1"><tt><font size="+1"><tt> %evl, %mask <- IRBuilder.createIterationPredicate(%i, %n, TTI)</tt><tt><br>
<br>
; Some examples:<br>
</tt></font></tt><tt> ; RISC-V V & VE(*):<br>
; </tt></font><font size="+1"><tt><font size="+1"><tt>%mask = (splat i1 1)</tt><tt><br>
</tt></font> ; %evl = min(256, %n - %i)</tt><tt><br>
</tt><tt> ; MVE/SVE :<br>
; %mask = get.active.lane.mask(%i, %n)<br>
; %evl = call @llvm.vscale()</tt><tt><br>
</tt><tt> ; AVX:<br>
; %mask = icmp (%i + (seq <8 x i32> 0,1,2,.,)), %n,<br>
; %evl = i32 8</tt><tt><br>
</tt><tt><br>
</tt><tt> ; Configure the Vector Predication builder to use those</tt><tt><br>
</tt><tt> VPBuilder</tt><tt><br>
</tt><tt> .setExplicitVectorLength(%evl)</tt><tt><br>
</tt><tt> .setMask(%mask);</tt><tt><br>
</tt><tt><br>
</tt><tt> ; Start buildling vector-predicated instructions</tt><tt><br>
</tt><tt> VPBuilder.createFadd(%x, %y) ; --> call @llvm.vp.fadd(%x, %y, %mask, %evl)</tt></font><br>
<br>
<blockquote type="cite" cite="mid:CAGeEQ1j8zkCNYgmOCS6T5wJ538MOsA3kmNtuH+Ff6f7x+2KVfA@mail.gmail.com">
<div dir="ltr">
<div class="gmail_quote">
<div>
<div dir="ltr">
<div><br>
</div>
<div>Looks to me the second option makes a more effective use of vpred and D78203 shows that we can always soften vpred into a shape that is reasonable for lowering in targets without active vector length.<br>
</div>
</div>
</div>
</div>
</div>
</blockquote>
The whole point about VP is to make sure there is one set of vector-predicated instructions/intrinsics that everybody is using while giving people the freedom to use these as it fits their targets. We can then concentrate on optimizing VP intrinsic code and
all targets benefit.<br>
<br>
- Simon<br>
<br>
*: VE's packed mode (512 x 32bit elements) is a use case for a non-trivial setting of %mask and %evl at the same time (%evl for packs of two 32bit elements (ie %evl must be even for 32bit lanes), %mask for masking out inside packages).<br>
<br>
<br>
<blockquote type="cite" cite="mid:CAGeEQ1j8zkCNYgmOCS6T5wJ538MOsA3kmNtuH+Ff6f7x+2KVfA@mail.gmail.com">
<div dir="ltr">
<div class="gmail_quote">
<div>
<div dir="ltr">
<div></div>
<div><br>
</div>
<div>Thoughts?<br>
</div>
<div><br>
</div>
<div>Kind regards,</div>
</div>
</div>
</div>
-- <br>
<div dir="ltr" class="gmail_signature">Roger Ferrer Ibáñez<br>
</div>
</div>
</blockquote>
<br>
</body>
</html>