<div dir="ltr"><div>Hi Chris,</div><div><br></div><div>vscale is constant in RISC-V as well. It doesn't change from instruction to instruction.</div><div><br></div><div>There are two implementation parameters of the RISC-V V-extension called VLEN, the number of bits of a (base) vector register, and ELEN, the maximum width in bits of an element in a vector register (i.e. if ELEN=32 one can't operate vectors of i64 or f64). Ideally we'd want to make the compiler as oblivious as possible to these parameters as we can. VLEN itself is not that different to the SVE situation. ELEN is a bit different because it impacts what vector types are legal in the code generator, this in turns impacts other parts like the loop vectorizer.<br></div><div><br></div><div>It seems reasonable to make vscale = VLEN / ELEN.</div><div><br></div><div>In this model, assume ELEN=64, legal types include <vscale x 1 x i64> and <vscale x 2 x i32>. As the ISA stands now, it is not efficient to operate, still in ELEN=64, a value of type <vscale x 1 x i32> so it seems reasonable not to make them legal. However in ELEN=32, <vscale x 1 x i32> is a sensible thing.<br></div><div><br></div><div>LMUL is a way that the ISA provides to operate groups of registers (which is useful in a number of cases I won't go into details here). There are 32 (base) vector registers (i.e. LMUL=1). LMUL=2 means grouping them in groups of two, LMUL=4 in groups of 4 and so on, up to LMUL=8. So, under LMUL=2, there are 16 groups, twice the length of the base vector registers, under LMUL=4 there are 8 groups, four times the length of the base registers. The ISA allows using these groups as registers so they can be modelled as "super registers" of the base registers (or the opposite, base registers can be seen as subregisters of group registers).<br></div><div><br></div><div>Continuing with the model above (ELEN=64), an LMUL=2 group would be able to represent IR values of <vscale x 2 x i64> and <vscale x 4 x i32>. An LMUL=4 group can represent IR values of <vscale x 4 x i64>, <vscale x 8 x i32>, and so on.<br></div><div><br></div><div>Kai original question is related to the fact that vscale depends on ELEN and this has the effect that it impacts the legal types. So one modelling option is try to get rid of such dependence on ELEN and fix it, say, to 64. Under this approach, legal values would always be, regardless of ELEN, <vscale x 1 x i64>, <vscale x 2 x i32>. As Hannah has pointed in an earlier answer, this may lead to nonsensical (regardless of legalization) IR types.</div><div><br></div><div>Hope this helps.</div><div><br></div><div>Kind regards,<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Missatge de Chris Tetreault via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> del dia dt., 7 d’abr. 2020 a les 18:39:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">





<div lang="EN-US">
<div class="gmail-m_1250487065401118837WordSection1">
<p class="MsoNormal">Hi,<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">    Looking at the language reference, vscale is an integer. This might pose a problem for fractional vscale. Furthermore, I believe that vscale is constant throughout the life of the program; so if RISC-V vscale can vary from instruction
 to instruction that may also be problematic unless you can just commit to one specific value of vscale.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">   Also, I had a question about your table. Based on your description of how LMUL works, I’d expect that LMUL == vscale, and that each column in your table would be the same:<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="gmail-m_1250487065401118837gmail-p2" style="margin:0in 0in 0.0001pt"><span style="font-size:9pt;font-family:"Helvetica Neue",serif;color:rgb(69,69,69)"><u></u> <u></u></span></p>
<p class="gmail-m_1250487065401118837gmail-p3" style="margin:0in 0in 0.0001pt;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal">
<span style="font-size:9pt;font-family:"Courier New";color:rgb(69,69,69)">int64_t | vscale x 1 x i64<u></u><u></u></span></p>
<p class="gmail-m_1250487065401118837gmail-p3" style="margin:0in 0in 0.0001pt"><span style="font-size:9pt;font-family:"Courier New";color:rgb(69,69,69)">int32_t | vscale x 2 x i32<u></u><u></u></span></p>
<p class="gmail-m_1250487065401118837gmail-p3" style="margin:0in 0in 0.0001pt;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal">
<span style="font-size:9pt;font-family:"Courier New";color:rgb(69,69,69)">int16_t | vscale x 4 x i16<u></u><u></u></span></p>
<p class="MsoNormal" style="font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal">
<span class="gmail-m_1250487065401118837gmail-apple-converted-space"><span style="font-size:9pt;font-family:"Courier New";color:rgb(69,69,69)"> </span></span><span style="font-size:9pt;font-family:"Courier New";color:rgb(69,69,69)">int8_t | vscale x 8 x i8<span class="gmail-m_1250487065401118837gmail-apple-converted-space"> </span></span><span class="gmail-m_1250487065401118837gmail-apple-converted-space"><u></u><u></u></span></p>
<p class="MsoNormal"><span class="gmail-m_1250487065401118837gmail-apple-converted-space"><span style="font-size:9pt;font-family:"Courier New";color:rgb(69,69,69)"><u></u> <u></u></span></span></p>
<p class="MsoNormal">… which is basically equivalent to:<u></u><u></u></p>
<p class="MsoNormal"><span class="gmail-m_1250487065401118837gmail-apple-converted-space"><span style="font-size:9pt;font-family:"Courier New";color:rgb(69,69,69)"><u></u> <u></u></span></span></p>
<p class="gmail-m_1250487065401118837gmail-p3" style="margin:0in 0in 0.0001pt"><span style="font-size:9pt;font-family:"Courier New";color:rgb(69,69,69)">int64_t | LMUL x 1 x i64</span><u></u><u></u></p>
<p class="gmail-m_1250487065401118837gmail-p3" style="margin:0in 0in 0.0001pt"><span style="font-size:9pt;font-family:"Courier New";color:rgb(69,69,69)">int32_t | LMUL x 2 x i32<u></u><u></u></span></p>
<p class="gmail-m_1250487065401118837gmail-p3" style="margin:0in 0in 0.0001pt;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal">
<span style="font-size:9pt;font-family:"Courier New";color:rgb(69,69,69)">int16_t | LMUL x 4 x i16<u></u><u></u></span></p>
<p class="MsoNormal" style="font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal">
<span class="gmail-m_1250487065401118837gmail-apple-converted-space"><span style="font-size:9pt;font-family:"Courier New";color:rgb(69,69,69)"> </span></span><span style="font-size:9pt;font-family:"Courier New";color:rgb(69,69,69)">int8_t | LMUL x 8 x i8<span class="gmail-m_1250487065401118837gmail-apple-converted-space"> </span></span><span class="gmail-m_1250487065401118837gmail-apple-converted-space"><u></u><u></u></span></p>
<p class="MsoNormal"><span class="gmail-m_1250487065401118837gmail-apple-converted-space"><span style="font-size:9pt;font-family:"Courier New";color:rgb(69,69,69)"><u></u> <u></u></span></span></p>
<p class="MsoNormal"><span class="gmail-m_1250487065401118837gmail-apple-converted-space"><span style="font-size:9pt;font-family:"Courier New";color:rgb(69,69,69)"><u></u> <u></u></span></span></p>
<p class="MsoNormal">… is this not the case?<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Thanks,<u></u><u></u></p>
<p class="MsoNormal">   Chris Tetreault<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"><b>From:</b> llvm-dev <<a href="mailto:llvm-dev-bounces@lists.llvm.org" target="_blank">llvm-dev-bounces@lists.llvm.org</a>>
<b>On Behalf Of </b>Kai Wang via llvm-dev<br>
<b>Sent:</b> Tuesday, April 7, 2020 1:31 AM<br>
<b>To:</b> <a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<b>Cc:</b> Roger Ferrer Ibanez <<a href="mailto:roger.ferrer@bsc.es" target="_blank">roger.ferrer@bsc.es</a>>;
<a href="mailto:rengolin@gmail.co" target="_blank">rengolin@gmail.co</a>; <a href="mailto:robin.kruppe@gmail.com" target="_blank">
robin.kruppe@gmail.com</a><br>
<b>Subject:</b> [EXT] [llvm-dev] Questions about vscale<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<p class="gmail-m_1250487065401118837gmail-p1" style="margin:0in 0in 0.0001pt"><span style="font-size:9pt;font-family:"Helvetica Neue",serif;color:rgb(69,69,69)">Hi,<u></u><u></u></span></p>
<p class="gmail-m_1250487065401118837gmail-p1" style="margin:0in 0in 0.0001pt;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal">
<span style="font-size:9pt;font-family:"Helvetica Neue",serif;color:rgb(69,69,69)"><u></u> <u></u></span></p>
<p class="gmail-m_1250487065401118837gmail-p1" style="margin:0in 0in 0.0001pt;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal">
<span style="font-size:9pt;font-family:"Helvetica Neue",serif;color:rgb(69,69,69)">In RISC-V v-extension</span><span class="gmail-m_1250487065401118837gmail-s1"><span style="font-size:9pt;font-family:".PingFang TC",serif;color:rgb(69,69,69)">,</span></span><span style="font-size:9pt;font-family:"Helvetica Neue",serif;color:rgb(69,69,69)">
 operations could operate on a group of vector registers</span><span class="gmail-m_1250487065401118837gmail-s1"><span style="font-size:9pt;font-family:".PingFang TC",serif;color:rgb(69,69,69)">;</span></span><span style="font-size:9pt;font-family:"Helvetica Neue",serif;color:rgb(69,69,69)">
 we called it LMUL. If LMUL equals 2</span><span class="gmail-m_1250487065401118837gmail-s1"><span style="font-size:9pt;font-family:".PingFang TC",serif;color:rgb(69,69,69)">,</span></span><span style="font-size:9pt;font-family:"Helvetica Neue",serif;color:rgb(69,69,69)"> it means we could operate
 on 2 vector registers at the same time. So</span><span class="gmail-m_1250487065401118837gmail-s1"><span style="font-size:9pt;font-family:".PingFang TC",serif;color:rgb(69,69,69)">,</span></span><span style="font-size:9pt;font-family:"Helvetica Neue",serif;color:rgb(69,69,69)"> we have the
 following combinations of types.<u></u><u></u></span></p>
<p class="gmail-m_1250487065401118837gmail-p2" style="margin:0in 0in 0.0001pt;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;min-height:14px">
<span style="font-size:9pt;font-family:"Helvetica Neue",serif;color:rgb(69,69,69)"><u></u> <u></u></span></p>
<p class="gmail-m_1250487065401118837gmail-p3" style="margin:0in 0in 0.0001pt;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal">
<span class="gmail-m_1250487065401118837gmail-apple-converted-space"><span style="font-size:9pt;font-family:"Courier New";color:rgb(69,69,69)">         
</span></span><span style="font-size:9pt;font-family:"Courier New";color:rgb(69,69,69)">LMUL = 1
<span class="gmail-m_1250487065401118837gmail-apple-converted-space">          </span>LMUL = 2<span class="gmail-m_1250487065401118837gmail-apple-converted-space">           
</span>LMUL = 4<span class="gmail-m_1250487065401118837gmail-apple-converted-space">            </span>LMUL = 8<u></u><u></u></span></p>
<p class="gmail-m_1250487065401118837gmail-p3" style="margin:0in 0in 0.0001pt;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal">
<span style="font-size:9pt;font-family:"Courier New";color:rgb(69,69,69)">int64_t | vscale x 1 x i64 | vscale x<span class="gmail-m_1250487065401118837gmail-apple-converted-space"> 
</span>2 x i64 | vscale x<span class="gmail-m_1250487065401118837gmail-apple-converted-space">  </span>4 x i64 | vscale x<span class="gmail-m_1250487065401118837gmail-apple-converted-space"> 
</span>8 x i64<u></u><u></u></span></p>
<p class="gmail-m_1250487065401118837gmail-p3" style="margin:0in 0in 0.0001pt;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal">
<span style="font-size:9pt;font-family:"Courier New";color:rgb(69,69,69)">int32_t | vscale x 2 x i32 | vscale x<span class="gmail-m_1250487065401118837gmail-apple-converted-space"> 
</span>4 x i32 | vscale x<span class="gmail-m_1250487065401118837gmail-apple-converted-space">  </span>8 x i32 | vscale x 16 x i32<u></u><u></u></span></p>
<p class="gmail-m_1250487065401118837gmail-p3" style="margin:0in 0in 0.0001pt;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal">
<span style="font-size:9pt;font-family:"Courier New";color:rgb(69,69,69)">int16_t | vscale x 4 x i16 | vscale x<span class="gmail-m_1250487065401118837gmail-apple-converted-space"> 
</span>8 x i16 | vscale x 16 x i16 | vscale x 32 x i16<u></u><u></u></span></p>
<p class="gmail-m_1250487065401118837gmail-p3" style="margin:0in 0in 0.0001pt;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal">
<span class="gmail-m_1250487065401118837gmail-apple-converted-space"><span style="font-size:9pt;font-family:"Courier New";color:rgb(69,69,69)"> </span></span><span style="font-size:9pt;font-family:"Courier New";color:rgb(69,69,69)">int8_t | vscale x 8 x i8<span class="gmail-m_1250487065401118837gmail-apple-converted-space"> 
</span>| vscale x 16 x i8<span class="gmail-m_1250487065401118837gmail-apple-converted-space">  </span>| vscale x 32 x i8<span class="gmail-m_1250487065401118837gmail-apple-converted-space"> 
</span>| vscale x 64 x i8<u></u><u></u></span></p>
<p class="gmail-m_1250487065401118837gmail-p2" style="margin:0in 0in 0.0001pt;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;min-height:14px">
<span style="font-size:9pt;font-family:"Helvetica Neue",serif;color:rgb(69,69,69)"><u></u> <u></u></span></p>
<p class="gmail-m_1250487065401118837gmail-p1" style="margin:0in 0in 0.0001pt;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal">
<span style="font-size:9pt;font-family:"Helvetica Neue",serif;color:rgb(69,69,69)">We have another architecture parameter</span><span class="gmail-m_1250487065401118837gmail-s1"><span style="font-size:9pt;font-family:".PingFang TC",serif;color:rgb(69,69,69)">,</span></span><span style="font-size:9pt;font-family:"Helvetica Neue",serif;color:rgb(69,69,69)">
 ELEN</span><span class="gmail-m_1250487065401118837gmail-s1"><span style="font-size:9pt;font-family:".PingFang TC",serif;color:rgb(69,69,69)">,</span></span><span style="font-size:9pt;font-family:"Helvetica Neue",serif;color:rgb(69,69,69)"> which means the maximum size of a single vector element
 in bits.<u></u><u></u></span></p>
<p class="gmail-m_1250487065401118837gmail-p1" style="margin:0in 0in 0.0001pt;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal">
<span style="font-size:9pt;font-family:"Helvetica Neue",serif;color:rgb(69,69,69)">We hope the type system could be consistent under ELEN = 32 and ELEN = 64. However</span><span class="gmail-m_1250487065401118837gmail-s1"><span style="font-size:9pt;font-family:".PingFang TC",serif;color:rgb(69,69,69)">,</span></span><span style="font-size:9pt;font-family:"Helvetica Neue",serif;color:rgb(69,69,69)">
 vscale may be a fractional value under ELEN = 32 in the above type system. When ELEN = 32</span><span class="gmail-m_1250487065401118837gmail-s1"><span style="font-size:9pt;font-family:".PingFang TC",serif;color:rgb(69,69,69)">,</span></span><span style="font-size:9pt;font-family:"Helvetica Neue",serif;color:rgb(69,69,69)">
 i64 is an invalid type (we could ignore the first row for ELEN = 32) and vscale may become 1/2 on run time to fit the architecture
</span><span class="gmail-m_1250487065401118837gmail-s1"><span style="font-size:9pt;font-family:".PingFang TC",serif;color:rgb(69,69,69)">(</span></span><span style="font-size:9pt;font-family:"Helvetica Neue",serif;color:rgb(69,69,69)">if the vector register only has 32 bits</span><span class="gmail-m_1250487065401118837gmail-s1"><span style="font-size:9pt;font-family:".PingFang TC",serif;color:rgb(69,69,69)">)</span></span><span style="font-size:9pt;font-family:"Helvetica Neue",serif;color:rgb(69,69,69)">.
 Is there any problem to assume vscale to be fractional under some circumstances? vscale should be an unknown value when compiling. So</span><span class="gmail-m_1250487065401118837gmail-s1"><span style="font-size:9pt;font-family:".PingFang TC",serif;color:rgb(69,69,69)">,</span></span><span style="font-size:9pt;font-family:"Helvetica Neue",serif;color:rgb(69,69,69)">
 it should have no impact on code generation and optimization. The relationship between types is correct regardless vscale</span><span class="gmail-m_1250487065401118837gmail-s1"><span style="font-size:9pt;font-family:".PingFang TC",serif;color:rgb(69,69,69)">’</span></span><span style="font-size:9pt;font-family:"Helvetica Neue",serif;color:rgb(69,69,69)">s
 value. Is there anything I missed</span><span style="font-size:9pt;font-family:".PingFang TC",serif;color:rgb(69,69,69)">?</span><span style="font-size:9pt;color:rgb(69,69,69)"><u></u><u></u></span></p>
<p class="gmail-m_1250487065401118837gmail-p1" style="margin:0in 0in 0.0001pt;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal">
<span style="font-size:9pt;color:rgb(69,69,69)"><u></u> <u></u></span></p>
<p class="gmail-m_1250487065401118837gmail-p1" style="margin:0in 0in 0.0001pt;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal">
<span style="font-size:9pt;font-family:".PingFang TC",serif;color:rgb(69,69,69)">Thanks!</span><span style="font-size:9pt;color:rgb(69,69,69)"><u></u><u></u></span></p>
<p class="gmail-m_1250487065401118837gmail-p1" style="margin:0in 0in 0.0001pt;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal">
<span style="font-size:9pt;font-family:".PingFang TC",serif;color:rgb(69,69,69)">Hsiangkai</span><span style="font-size:9pt;color:rgb(69,69,69)"><u></u><u></u></span></p>
</div>
</div>
</div>

_______________________________________________<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" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div><br clear="all"><br>-- <br><div dir="ltr" class="gmail_signature">Roger Ferrer Ibáñez<br></div>