<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"MS Mincho";
        panose-1:2 2 6 9 4 2 5 8 3 4;}
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:"\@MS Mincho";
        panose-1:2 2 6 9 4 2 5 8 3 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman",serif;
        color:black;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p
        {mso-style-priority:99;
        mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:12.0pt;
        font-family:"Times New Roman",serif;
        color:black;}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body bgcolor="white" lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal">>when we have a mask loaded from an external source (memory, function call boundary, etc...) and a short sequence of vector ops<span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">Mask value from function call parameter is common. OpenMP declare simd function does exactly that for the masked cases.<o:p></o:p></span></p>
<p class="MsoNormal"><a name="_MailEndCompose"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></a></p>
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><a name="_____replyseparator"></a><b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:windowtext">From:</span></b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:windowtext"> Philip Reames [mailto:listmail@philipreames.com]
<br>
<b>Sent:</b> Thursday, January 31, 2019 4:05 PM<br>
<b>To:</b> Robin Kruppe <robin.kruppe@gmail.com><br>
<b>Cc:</b> David Greene <dag@cray.com>; via llvm-dev <llvm-dev@lists.llvm.org>; Saito, Hideki <hideki.saito@intel.com>; Topper, Craig <craig.topper@intel.com>; Maslov, Sergey V <sergey.v.maslov@intel.com><br>
<b>Subject:</b> Re: [llvm-dev] [RFC] Vector Predication<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p><o:p> </o:p></p>
<div>
<p class="MsoNormal">On 1/31/19 1:14 PM, Robin Kruppe wrote:<o:p></o:p></p>
</div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<p class="MsoNormal">On Thu, 31 Jan 2019 at 20:17, Philip Reames via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<o:p></o:p></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<p class="MsoNormal"><br>
On 1/31/19 11:03 AM, David Greene wrote:<br>
> Philip Reames <<a href="mailto:listmail@philipreames.com" target="_blank">listmail@philipreames.com</a>> writes:<br>
><br>
>> Question 1 - Why do we need separate mask and lengths? Can't the<br>
>> length be easily folded into the mask operand?<br>
>><br>
>> e.g. newmask = (<4 x i1>)((i4)%y & (1 << %L -1))<br>
>> and then pattern matched in the backend if needed<br>
> I'm a little concerned about how difficult it will be to maintain enough<br>
> information throughout compilation to be able to match this on a machine<br>
> with an explicit vector length value.<br>
Does the hardware *also* have a mask register?  If so, this is a likely <br>
minor code quality issue which can be incrementally refined on.  If it <br>
doesn't, then I can see your concern.<o:p></o:p></p>
</blockquote>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Masking/predication is supported nearly universally, but I don't think the code quality issue is minor. It would be on a typical packed-SIMD machine with 128/256/512 bit registers, but the processors with a vector length register are usually
 built with much larger registers files and without a corresponding increase in the number of functional units. For example, 4096 bit per vector register is really quite modest for this kind of machine, while the data path can reasonable be "only" 128 or 256
 bit.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">This changes the calculus quite a bit: vector lengths much shorter or minimally larger than one full register are suddenly reasonable common (in application code, not so much in HPC kernels) and because each vector instruction is split
 into many data-path-sized uops, it's trivial and very rewarding to cut processing short halfway through a vector. The efficiency of "short vector code" then depends on the ability to finish each operation on those short vectors relatively quickly rather than
 padding everything to a full vector register. <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">For example, if a loop with a trip count of 20 is vectorized on a machine with 64 elements per vector (that's 64b elements in a 4096b register, so this is lowballing it!), using only masks and not the vector length register makes your vector
 unit do about three times more work than it would have to if you set the vector length register to 20. That keeps the register file and functional units busy for no good reason. Some microarchitectures take on the burden of determining when a whole chunk of
 the vector is masked out and can then skip over it quickly, but many others don't. So you're likely burning a whole bunch of power and quite possibly taking up cycles that could be filled with useful work from other instructions instead.<o:p></o:p></p>
</div>
</div>
</div>
</blockquote>
<p>Thank you for the explanation.  <o:p></o:p></p>
<p>Do such architectures frequently have arithmetic operations on the mask registers?  (i.e. can I reasonable compute a conservative length given a mask register value)  If I can, then having a mask as the canonical form and re-deriving the length register
 from a mask for a sequence of instructions which share a predicate seems fairly reasonable.  Note that I'm assuming this as a fallback, and that the common case is handled via the equivalent of ComputeKnownBits on the mask itself at compile time. 
<o:p></o:p></p>
<p>The only case where the combination of a CKB and dynamic mask->length fallback wouldn't handle reliably is when we have a mask loaded from an external source (memory, function call boundary, etc...) and a short sequence of vector ops.  Are such really common
 enough that it needs to be a first class element of the design?<o:p></o:p></p>
<p><o:p> </o:p></p>
<p>p.s. To make sure my tone is coming across correctly, let me spell out that I'm not convinced, but I'm not actively objecting.  I'm playing devils advocate for the purposes of fleshing out a design, but if folks more knowledgeable than I strongly believe
 the right design requires both masks and lengths, I'm happy to defer on that point. 
<o:p></o:p></p>
<p><o:p> </o:p></p>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<div>
<div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Cheers,<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">Robin<o:p></o:p></p>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<p class="MsoNormal">>> Question 2 - Have you explored using selects instead? What practical<br>
>> problems do you run into which make you believe explicit predication<br>
>> is required?<br>
>><br>
>> e.g. %sub = fsub <4 x float> %x, %y<br>
>> %result = select <4 x i1> %M, <4 x float> %sub, undef<br>
> That is semantically incorrect.  According to IR semantics, the fsub is<br>
> fully evaluated before the select comes along.  It could trap for<br>
> elements where %M is 0, whereas a masked intrinsic conveys the proper<br>
> semantics of masking traps for masked-out elements.  We need intrinsics<br>
> and eventually (IMHO) fully first-class predication to make this work<br>
> properly.<br>
<br>
If you want specific trap behavior, you need to use the constrained <br>
family of intrinsics instead.  In IR, fsub is expected not to trap.<br>
<br>
We have an existing solution for modeling FP environment aspects such as <br>
rounding and trapping.  The proposed signatures for your EVL proposal do <br>
not appear to subsume those, and you've not proposed their retirement.  <br>
We definitely don't want *two* ways of describing FP trapping.<br>
<br>
In other words, I don't find this reason compelling since my example can <br>
simply be rewritten using the appropriate constrained intrinsic.<br>
<br>
<br>
><br>
>> My context for these questions is that my experience recently w/o<br>
>> existing masked intrinsics shows us missing fairly basic<br>
>> optimizations, precisely because they weren't able to reuse all of the<br>
>> existing infrastructure. (I've been working on<br>
>> SimplifyDemandedVectorElts recently for exactly this reason.) My<br>
>> concern is that your EVL proposal will end up in the same state.<br>
> I think that's just the nature of the beast.  We need IR-level support<br>
> for masking and we have to teach LLVM about it.<br>
I'm solidly of the opinion that we already *have* IR support for <br>
explicit masking in the form of gather/scatter/etc...  Until someone has <br>
taken the effort to make masking in this context *actually work well*, <br>
I'm unconvinced that we should greatly expand the usage in the IR.<br>
><br>
>                             -David<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><o:p></o:p></p>
</blockquote>
</div>
</div>
</blockquote>
</div>
</body>
</html>