<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=us-ascii">
<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;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
span.EmailStyle19
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.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="#0563C1" vlink="#954F72">
<div class="WordSection1">
<p class="MsoNormal">For this specific sort of issue, we have some code in CodeGenPrepare::tryToSinkFreeOperands to try to rearrange the IR so the necessary instructions are in the same basic block.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">If we can’t make that work, we could consider adding a separate intrinsic.
<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>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal" style="margin-left:.5in"><b>From:</b> llvm-dev <llvm-dev-bounces@lists.llvm.org>
<b>On Behalf Of </b>Alexey Lapshin via llvm-dev<br>
<b>Sent:</b> Monday, May 18, 2020 5:28 AM<br>
<b>To:</b> llvm-dev@lists.llvm.org<br>
<b>Subject:</b> [EXT] [llvm-dev] [AARCH64][NEON] Do we need extra builtin for vmull_high_p64?<o:p></o:p></p>
</div>
</div>
<p class="MsoNormal" style="margin-left:.5in"><o:p> </o:p></p>
<p style="margin-left:.5in"><span style="font-size:12.0pt;color:black">Folks, we encountered a problem: for vmull_high_p64 intrinsic there was not generated PMULL2 instruction.<br>
This happened because the vmull_high_p64 is implemented through vmull_p64:<br>
<br>
</span><span style="font-size:12.0pt;font-family:"Courier New";color:black">arm_neon.h:<br>
__ai poly128_t vmull_high_p64(poly64x2_t __p0, poly64x2_t __p1) { </span><span style="font-size:12.0pt;color:black"><o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-size:12.0pt;font-family:"Courier New";color:black">   poly128_t __ret;
</span><span style="font-size:12.0pt;color:black"><o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-size:12.0pt;font-family:"Courier New";color:black">   __ret = vmull_p64((poly64_t)(vget_high_p64(__p0)), (poly64_t)(vget_high_p64(__p1)));
</span><span style="font-size:12.0pt;color:black"><o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-size:12.0pt;font-family:"Courier New";color:black">   return __ret;
</span><span style="font-size:12.0pt;color:black"><o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-size:12.0pt;font-family:"Courier New";color:black">}
</span><span style="font-size:12.0pt;color:black"><o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-size:12.0pt;font-family:"Courier New";color:black">__ai poly128_t vmull_p64(poly64_t __p0, poly64_t __p1) {
</span><span style="font-size:12.0pt;color:black"><o:p></o:p></span></p>
<div>
<p class="MsoNormal" style="margin-left:.5in"><span style="font-size:12.0pt;font-family:"Courier New";color:black">  poly128_t __ret;
</span><span style="font-size:12.0pt;color:black"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in"><span style="font-size:12.0pt;font-family:"Courier New";color:black">  __ret = (poly128_t) __builtin_neon_vmull_p64(__p0, __p1);
</span><span style="font-size:12.0pt;color:black"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in"><span style="font-size:12.0pt;font-family:"Courier New";color:black">  return __ret;
</span><span style="font-size:12.0pt;color:black"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in"><span style="font-size:12.0pt;font-family:"Courier New";color:black">}
</span><span style="font-size:12.0pt;color:black"><o:p></o:p></span></p>
</div>
<p style="margin-left:.5in"><span style="font-size:12.0pt;color:black"><br>
There also exist pattern to convert this into PMULL2:<br>
<br>
</span><span style="font-size:12.0pt;font-family:"Courier New";color:black">def : Pat<(int_aarch64_neon_pmull64 (extractelt (v2i64 V128:$Rn), (i64 1)),<br>
(extractelt (v2i64 V128:$Rm), (i64 1))),<br>
(PMULLv2i64 V128:$Rn, V128:$Rm)>;</span><span style="font-size:12.0pt;color:black"><br>
<br>
The problem is that ISel apply that pattern only when corresponding IR is inside basic block.<br>
Some optimizations could hoist extraction operators out of current basic block(Loop invariant code motion).<br>
In the result PMULL2 is not used.<br>
<br>
GlobalISel could resolve that problem. But it does not handle this pattern yet and switched on by default for -O0 only.<br>
Another alternative to have PMULL2 is to create specific builtin for vmull_high_p64 intrinsic.<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-size:12.0pt;color:black"><br>
Would it be OK to add extra builtin for vmull_high_p64 intrinsic to resolve this problem(<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-size:12.0pt;font-family:"Courier New";color:black">__builtin_neon_vmull_high_p64</span><span style="font-size:12.0pt;color:black">/llvm.aarch64.neon.pmull_high_64) ?<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-size:12.0pt;color:black"><o:p> </o:p></span></p>
<p style="margin-left:.5in"><span style="font-size:12.0pt;color:black">Thank you, Alexey.<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-size:12.0pt;color:black"><o:p> </o:p></span></p>
<div id="Signature">
<div name="divtagdefaultwrapper">
<p class="MsoNormal" style="margin-left:.5in"><span style="font-size:12.0pt;color:black"><o:p> </o:p></span></p>
</div>
</div>
</div>
</body>
</html>