<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<blockquote class="quotableTextTraining" style="border-color: rgb(200, 200, 200); border-left: 3px solid rgb(200, 200, 200); padding-left: 1ex; margin-left: 0.8ex; color: rgb(102, 102, 102);">
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<blockquote cite="mid:DB6PR0801MB1990BDF9B4D2C59E24BE607AFCED0@DB6PR0801MB1990.eurprd08.prod.outlook.com" type="cite">
<div style="color: rgb(0, 0, 0); font-size: 12pt; font-family: Calibri, Arial, Helvetica, sans-serif;">
<br>
</div>
<div style="color:black;font-size:12pt;font-family:Calibri,Arial,Helvetica,sans-serif">
<font size="+1"><tt>; RISC-V V & VE(*):<br>
; </tt></font><font size="+1"><tt><font size="+1"><tt>%mask = <font size="+1">
<tt>get.active.lane.mask(%i, %i)</tt></font></tt><tt><br>
</tt></font> ; %evl = min(256, %n - %i)</tt></font></div>
<div style="color:black;font-size:12pt;font-family:Calibri,Arial,Helvetica,sans-serif">
<font size="+1"><tt><font size="+1"><tt> ; MVE/SVE/AVX :<br>
; %mask = get.active.lane.mask(%i, %n)<br>
; %evl = call @llvm.vscale()</tt><tt><br>
</tt></font></tt></font></div>
</blockquote>
For VE, we want to do as much predication as possible through %evl and as little as possible with %mask. This has performance implications on VE and RISC-V - VE does not generate a mask from %evl but %evl is directly mapped to hardware, passing the all-true
mask is free.<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
So for VE, the %evl does all the predication and there is no reason to have anything other than a (splat i1 1) %mask here.</div>
</blockquote>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Okay, got it. One way to look at this is that (splat i1 1) is just a special case of
<font size="+1"><tt><font size="+1"><tt><font size="+1"><tt>get.active.lane.mask<span style="font-family: calibri, arial, helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgba(0, 0, 0, 0);">, for example get.mask(%i, 0) can trivially
be expanded/lowered to a (splat i1 1). This is not terribly important, but shows that get.active.lane.mask could be used for all targets I think; we don't need many cases. And kind of similarly, vscale can be a no-op or do something.<br>
</span></tt></font></tt></font></tt></font></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<font size="+1"><tt><font size="+1"><tt><font size="+1"><tt><span style="font-family: calibri, arial, helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgba(0, 0, 0, 0);"><br>
</span></tt></font></tt></font></tt></font></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<font size="+1"><tt><font size="+1"><tt><font size="+1"><tt><span style="font-family: calibri, arial, helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgba(0, 0, 0, 0);">Cheers,</span></tt></font></tt></font></tt></font></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<font size="+1"><tt><font size="+1"><tt><font size="+1"><tt><span style="font-family: calibri, arial, helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgba(0, 0, 0, 0);">Sjoerd.<br>
</span></tt></font></tt></font></tt></font></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<font size="+1"><tt><font size="+1"><tt><font size="+1"><tt><span style="font-family: calibri, arial, helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgba(0, 0, 0, 0);"></span></tt></font></tt></font></tt></font><br>
</div>
<div id="appendonsend"></div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="divRplyFwdMsg" dir="ltr"><font style="font-size:11pt" face="Calibri, sans-serif" color="#000000"><b>From:</b> Simon Moll <Simon.Moll@EMEA.NEC.COM><br>
<b>Sent:</b> 06 November 2020 15:37<br>
<b>To:</b> Sjoerd Meijer <Sjoerd.Meijer@arm.com>; Roger Ferrer Ibáñez <rofirrim@gmail.com><br>
<b>Cc:</b> Renato Golin <rengolin@gmail.com>; Vineet Kumar <vineet.kumar@bsc.es>; LLVM Dev <llvm-dev@lists.llvm.org>; ROGER FERRER IBANEZ <roger.ferrer@bsc.es>; Arai, Masaki <arai.masaki@jp.fujitsu.com><br>
<b>Subject:</b> Re: [llvm-dev] Loop-vectorizer prototype for the EPI Project based on the RISC-V Vector Extension (Scalable vectors)</font>
<div> </div>
</div>
<div>
<div class="x_moz-cite-prefix">On 11/6/20 12:39 PM, Sjoerd Meijer wrote:<br>
</div>
<blockquote type="cite">
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
Hello Simon,</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
Thanks for your replies, very useful. And yes, thanks for the example and making the target differences clear:<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<blockquote class="x_quotableTextTraining" style="border-color:rgb(200,200,200); border-left:3px solid rgb(200,200,200); padding-left:1ex; margin-left:0.8ex; color:rgb(102,102,102)">
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<font size="+1"><tt><font size="+1"><tt> ; 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></font></div>
</blockquote>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
Unless I miss something, the AVX example is semantically the same as get.active.lane.mask:</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
%m[i] = icmp ult (%base + i), %n</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
with i = 8.</div>
</blockquote>
Correct (llvm.get.active.lane.mask.v8i1.i32).<br>
<blockquote type="cite">
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
Just saying this to see if we can have "1 interface" for generating the mask (which is what I was perhaps expecting), and if you just want an all true mask for VE and if we can merge AVX with the other 2 we just have:<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<font size="+1"><tt>; RISC-V V & VE(*):<br>
; </tt></font><font size="+1"><tt><font size="+1"><tt>%mask = <font size="+1">
<tt>get.active.lane.mask(%i, %i)</tt></font></tt><tt><br>
</tt></font> ; %evl = min(256, %n - %i)</tt></font></div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<font size="+1"><tt><font size="+1"><tt> ; MVE/SVE/AVX :<br>
; %mask = get.active.lane.mask(%i, %n)<br>
; %evl = call @llvm.vscale()</tt><tt><br>
</tt></font></tt></font></div>
</blockquote>
For VE, we want to do as much predication as possible through %evl and as little as possible with %mask. This has performance implications on VE and RISC-V - VE does not generate a mask from %evl but %evl is directly mapped to hardware, passing the all-true
mask is free.<br>
So for VE, the %evl does all the predication and there is no reason to have anything other than a (splat i1 1) %mask here.<br>
<br>
On SVE/MVE you may want to use get.active.lane.mask instead and on RISC-V V, AFAIU, the %evl parameter will have to be computed by some RISC-V specific `setvl` intrinsic. Both of this is okay because VP gives you that flexibility.<br>
<br>
<blockquote type="cite">
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<font size="+1"><tt><font size="+1"><tt></tt></font></tt></font></div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<font size="+1"><tt><br>
</tt></font></div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<font size="+1"><tt>I am not sure why MVE (or AVX) would need the vscale(). But if it does, I am wondering if it could be something like:
<br>
</tt></font></div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<font size="+1"><tt><br>
</tt></font></div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<div style="font-size:12pt"><font size="+1"><tt>; RISC-V V & VE(*):<br>
; </tt></font><font size="+1"><tt><font size="+1"><tt>%mask = <font size="+1">
<tt>get.active.lane.mask(%i, %i)</tt></font></tt><tt><br>
</tt></font> ; %evl = call @llvm.vscale(256, %n - %i)</tt></font></div>
<div style="font-size:12pt"><font size="+1"><tt><font size="+1"><tt> ; MVE/SVE/AVX :<br>
; %mask = get.active.lane.mask(%i, %n)<br>
; %evl = call @llvm.vscale(... ,..)</tt><tt><br>
</tt></font></tt></font></div>
</div>
</blockquote>
The vscale is only necessary with scalable types, eg you can inactivate the %evl parameter like so:<tt><font size="+1"><br>
<br>
llvm.vp.fadd nxv4f128(%x, %y, %mask, (@llvm.vscale() * 4))<br>
<br>
</font></tt>The VPIntrinsic class upstream already has the functionality to check whether the %evl parameter is inactivated in this way<tt><font size="+1"> (VPIntrinsic::canIgnoreVectorLengthParam()).</font></tt><tt><font size="+1"><br>
<br>
</font></tt>
<blockquote type="cite">
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<div style="font-size:12pt"><font size="+1"><tt><font size="+1"><tt></tt></font></tt></font></div>
<div style="font-size:12pt"><font size="+1"><tt><font size="+1"><tt><br>
</tt></font></tt></font></div>
<div style="font-size:12pt"><font size="+1"><tt><font size="+1"><tt>Cheers,</tt></font></tt></font></div>
<div style="font-size:12pt"><font size="+1"><tt><font size="+1"><tt>Sjoerd.<br>
</tt></font></tt></font></div>
</div>
</blockquote>
- Simon<br>
<blockquote type="cite">
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<div style="font-size:12pt"><font size="+1"><tt><font size="+1"><tt></tt></font></tt></font></div>
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="x_divRplyFwdMsg" dir="ltr"><font style="font-size:11pt" face="Calibri, sans-serif" color="#000000"><b>From:</b> Simon Moll
<a class="x_moz-txt-link-rfc2396E" href="mailto:Simon.Moll@EMEA.NEC.COM"><Simon.Moll@EMEA.NEC.COM></a><br>
<b>Sent:</b> 06 November 2020 10:07<br>
<b>To:</b> Roger Ferrer Ibáñez <a class="x_moz-txt-link-rfc2396E" href="mailto:rofirrim@gmail.com">
<rofirrim@gmail.com></a>; Sjoerd Meijer <a class="x_moz-txt-link-rfc2396E" href="mailto:Sjoerd.Meijer@arm.com">
<Sjoerd.Meijer@arm.com></a><br>
<b>Cc:</b> Renato Golin <a class="x_moz-txt-link-rfc2396E" href="mailto:rengolin@gmail.com">
<rengolin@gmail.com></a>; Vineet Kumar <a class="x_moz-txt-link-rfc2396E" href="mailto:vineet.kumar@bsc.es">
<vineet.kumar@bsc.es></a>; LLVM Dev <a class="x_moz-txt-link-rfc2396E" href="mailto:llvm-dev@lists.llvm.org">
<llvm-dev@lists.llvm.org></a>; ROGER FERRER IBANEZ <a class="x_moz-txt-link-rfc2396E" href="mailto:roger.ferrer@bsc.es">
<roger.ferrer@bsc.es></a>; Arai, Masaki <a class="x_moz-txt-link-rfc2396E" href="mailto:arai.masaki@jp.fujitsu.com">
<arai.masaki@jp.fujitsu.com></a><br>
<b>Subject:</b> Re: [llvm-dev] Loop-vectorizer prototype for the EPI Project based on the RISC-V Vector Extension (Scalable vectors)</font>
<div> </div>
</div>
<div>
<div class="x_x_moz-cite-prefix">On 11/6/20 8:49 AM, Roger Ferrer Ibáñez wrote:<br>
</div>
<blockquote type="cite">
<div dir="ltr">
<div dir="ltr">
<div>Hi Sjoerd,<br>
</div>
<div><br>
</div>
</div>
<div class="x_x_gmail_quote">
<blockquote class="x_x_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">
<div dir="ltr">
<div class="x_x_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">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">
<div dir="ltr">
<div class="x_x_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">
<div dir="ltr">
<div class="x_x_gmail_quote">
<div>
<div dir="ltr">
<div><br>
</div>
<div>Thoughts?<br>
</div>
<div><br>
</div>
<div>Kind regards,</div>
</div>
</div>
</div>
-- <br>
<div dir="ltr" class="x_x_gmail_signature">Roger Ferrer Ibáñez<br>
</div>
</div>
</blockquote>
</div>
</blockquote>
<br>
</div>
</body>
</html>