<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
</head>
<body>
<div class="moz-cite-prefix">Hi Hussain,<br>
<br>
Thanks for your patch! We are working on a similar extension (Vector Predication) with the goal of enabling variable length on all SIMD operations. We have a reference patch that includes variable-length load store intrinsics. You find it here:
<a class="moz-txt-link-freetext" href="https://reviews.llvm.org/D57504">https://reviews.llvm.org/D57504</a>
<br>
Integer VP intrinsics are upstream and documented here: <a class="moz-txt-link-freetext" href="https://llvm.org/docs/LangRef.html#vector-predication-intrinsics">
https://llvm.org/docs/LangRef.html#vector-predication-intrinsics</a><br>
<br>
The VP load/store intrinsics look like this:<br>
<br>
     <tt>@llvm.vp.load(%ptr, %mask, %vector_length)</tt><tt><br>
</tt><tt>    @llvm.vp.store(%data, %ptr, %mask, %vector_length)</tt><br>
<br>
where the %vector_length argument specifies the variable length of the operation. There is also a %mask but you can simply pass the constant-true mask to disable it.<br>
Now i wonder, would VP load/store cover your use case? It'd be great if your patch, the scalarization logic, TTI, could be integrated into the framework of VP intrinsics.<br>
<br>
- Simon<br>
<br>
<br>
On 8/27/20 12:43 PM, Eli Friedman wrote:<br>
</div>
<blockquote type="cite" cite="mid:DM6PR02MB7099E9363B8C7C8F28EEE750CA550@DM6PR02MB7099.namprd02.prod.outlook.com">
<meta name="Generator" content="Microsoft Word 15 (filtered
        medium)">
<style><!--
/* Font Definitions */
@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;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;}
@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]-->
<div class="WordSection1">
<p class="MsoNormal">“The vectorizer needs this” seems like a fair reason to add it to the IR.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Pattern-matching an llvm.masked.load with an llvm.get.active.lane.mask operand might not be that terrible?  If that works, I’d prefer to go with that because we already have that codepath.  Otherwise, adding a new intrinsic seems okay.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">There’s a possibility that we’ll want a version of llvm.masked.load that takes both a length and a mask, eventually. See
<a href="https://reviews.llvm.org/D57504" moz-do-not-send="true">https://reviews.llvm.org/D57504</a> .  Not completely sure how that should interact with this proposal.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">-Eli<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0in
          0in 0in 4.0pt">
<div>
<div style="border:none;border-top:solid #E1E1E1
              1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b>From:</b> llvm-dev <a class="moz-txt-link-rfc2396E" href="mailto:llvm-dev-bounces@lists.llvm.org">
<llvm-dev-bounces@lists.llvm.org></a> <b>On Behalf Of </b>Hussain Kadhem via llvm-dev<br>
<b>Sent:</b> Thursday, August 27, 2020 2:52 AM<br>
<b>To:</b> <a class="moz-txt-link-abbreviated" href="mailto:llvm-dev@lists.llvm.org">
llvm-dev@lists.llvm.org</a><br>
<b>Subject:</b> [EXT] [llvm-dev] [RFC] intrinsics for load/store-with-length semantics<o:p></o:p></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial",sans-serif">We propose introducing two new intrinsics: llvm.variable.length.load and llvm.variable.length.store.<br>
We have implemented the infrastructure for defining and lowering these in this phabricator patch:
<a href="https://reviews.llvm.org/D86693" moz-do-not-send="true">https://reviews.llvm.org/D86693</a><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial",sans-serif"> <o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial",sans-serif">These represent the semantics of loading and storing a variable number of bytes to a fixed-width register;<br>
in effect, a masked load or store where the only active lanes are given by a contiguous block.<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial",sans-serif"> <o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial",sans-serif">There are a few reasons for separately representing this kind of operation, even though as noted it can be represented by a subset of masked loads and stores.<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial",sans-serif"> <o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial",sans-serif">- For targets that have separate hardware support for this kind of operation, it makes it easier to generate an optimal lowering. We are currently working on enabling this for
 some PowerPC subtargets. In particular, there are some targets that support this kind of operation but not masked loads and stores in general, including Power9.<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial",sans-serif"> <o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial",sans-serif">- Scalarization of this pattern can be done using a number of branches logarithmic in the width of the register, rather than the linear case for general masked operations.<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial",sans-serif">- Scalarized residuals of vectorized loops tend to employ these semantics (tail-folding in particular), so this infrastructure can be used to make more specific optimization
 decisions for lowering loop residuals. This also pulls out the logic of how to represent and lower such semantics from the loop vectorizer, allowing for better separation of concerns. Our group is currently working on implementing some of these optimizations
 in the loop vectorizer.<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial",sans-serif"> <o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial",sans-serif">- Representing these semantics using current masked intrinsics would require introducing intermediate steps to generate the appropriate bitmasks, and then detecting them during
 lowering. This introduces nontrivial complexity that we want to avoid. If it isn't possible to detect all cases during lowering by inspecting the AST, expensive runtime checks would then have to be introduced.<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial",sans-serif"> <o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial",sans-serif"> <o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial",sans-serif">Please refer to the phabricator patch for our implementation, which includes intrinsic definitions, new SDAG nodes, and support for type widening and scalarization.<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial",sans-serif"> <o:p></o:p></span></p>
</div>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
</blockquote>
<br>
</body>
</html>