<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:"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:Monaco;
panose-1:0 0 0 0 0 0 0 0 0 0;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:#0563C1;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:#954F72;
text-decoration:underline;}
p.msonormal0, li.msonormal0, div.msonormal0
{mso-style-name:msonormal;
mso-margin-top-alt:auto;
margin-right:0in;
mso-margin-bottom-alt:auto;
margin-left:0in;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
span.EmailStyle18
{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 lang="EN-US" link="#0563C1" vlink="#954F72">
<div class="WordSection1">
<p class="MsoNormal">All in-tree targets have variable shift instructions for native integer types, except for AVR. And AVR implements custom lowering. I’m not sure what else would be required to actually make marking a shift as “libcall” actually work well;
technically, the change you’re proposing might produce valid code, but it would be terrible quality in a lot of cases. So I’m not eager to add partial support just for out-of-tree targets.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Marking CTLZ_ZERO_UNDEF as “LibCall” was implemented in <a href="https://reviews.llvm.org/D47917">
https://reviews.llvm.org/D47917</a> . Probably straightforward to extend that to cover CTTZ_ZERO_UNDEF and CTPOP.<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 <llvm-dev-bounces@lists.llvm.org> <b>On Behalf Of
</b>Joan Lluch via llvm-dev<br>
<b>Sent:</b> Monday, June 10, 2019 8:31 AM<br>
<b>To:</b> llvm-dev <llvm-dev@lists.llvm.org><br>
<b>Subject:</b> [EXT] [llvm-dev] Bug: Library functions for ISD::SRA, ISD::SHL, and ISD::SRL<o:p></o:p></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">LLVM appears to support Library functions for <span style="font-size:8.5pt;font-family:"Monaco",serif;color:#4F8187;background:white">ISD</span><span style="font-size:8.5pt;font-family:"Monaco",serif;background:white">::<span style="color:#31595D">SRA </span></span>,<span style="font-size:8.5pt;font-family:"Monaco",serif;color:#4F8187;background:white">ISD</span><span style="font-size:8.5pt;font-family:"Monaco",serif;background:white">::<span style="color:#31595D">SHL</span></span>,
and <span style="font-size:8.5pt;font-family:"Monaco",serif;color:#4F8187;background:white">ISD</span><span style="font-size:8.5pt;font-family:"Monaco",serif;background:white">::<span style="color:#31595D">SRL</span></span>, as they are properly defined in
RuntimeLibCalls.def.<o:p></o:p></p>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">The library functions defined in RuntimeLibCalls.def (among others) are these:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:8.5pt;font-family:"Monaco",serif">HANDLE_LIBCALL(SRA_I16, "__ashrhi3")<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:8.5pt;font-family:"Monaco",serif">HANDLE_LIBCALL(SRA_I32, "__ashrsi3")<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:8.5pt;font-family:"Monaco",serif">HANDLE_LIBCALL(SRA_I64, "__ashrdi3")<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">However, setting<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:8.5pt;font-family:"Monaco",serif;color:#31595D">setOperationAction</span><span style="font-size:8.5pt;font-family:"Monaco",serif;color:black">(</span><span style="font-size:8.5pt;font-family:"Monaco",serif;color:#4F8187">ISD</span><span style="font-size:8.5pt;font-family:"Monaco",serif;color:black">::</span><span style="font-size:8.5pt;font-family:"Monaco",serif;color:#31595D">SRA</span><span style="font-size:8.5pt;font-family:"Monaco",serif;color:black">, </span><span style="font-size:8.5pt;font-family:"Monaco",serif;color:#4F8187">MVT</span><span style="font-size:8.5pt;font-family:"Monaco",serif;color:black">::</span><span style="font-size:8.5pt;font-family:"Monaco",serif;color:#31595D">i16</span><span style="font-size:8.5pt;font-family:"Monaco",serif;color:black">, </span><span style="font-size:8.5pt;font-family:"Monaco",serif;color:#31595D">LibCall</span><span style="font-size:8.5pt;font-family:"Monaco",serif;color:black">);</span><span style="font-size:8.5pt;font-family:"Monaco",serif;color:#31595D"><o:p></o:p></span></p>
</div>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">in the TargetLowering constructor causes LLVM to stop with an assert as the shift instruction can’t be selected. <o:p></o:p></p>
</div>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">The problem is in <span style="font-size:8.5pt;font-family:"Monaco",serif;color:#4F8187;background:white">SelectionDAGLegalize</span><span style="font-size:8.5pt;font-family:"Monaco",serif;background:white">::ConvertNodeToLibcall </span>because
there’s no switch case for any of the Shift instructions. <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">The problem gets solved by just adding switch cases like this (and similar for the other shift instructions):<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:8.5pt;font-family:"Monaco",serif;color:#BA2DA2">case</span><span style="font-size:8.5pt;font-family:"Monaco",serif;color:black">
</span><span style="font-size:8.5pt;font-family:"Monaco",serif;color:#4F8187">ISD</span><span style="font-size:8.5pt;font-family:"Monaco",serif;color:black">::</span><span style="font-size:8.5pt;font-family:"Monaco",serif;color:#31595D">SRA</span><span style="font-size:8.5pt;font-family:"Monaco",serif;color:black">:</span><span style="font-size:8.5pt;font-family:"Monaco",serif;color:#BA2DA2"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:8.5pt;font-family:"Monaco",serif;color:black"> Results.</span><span style="font-size:8.5pt;font-family:"Monaco",serif;color:#31595D">push_back</span><span style="font-size:8.5pt;font-family:"Monaco",serif;color:black">(</span><span style="font-size:8.5pt;font-family:"Monaco",serif;color:#31595D">ExpandIntLibCall</span><span style="font-size:8.5pt;font-family:"Monaco",serif;color:black">(Node,
</span><span style="font-size:8.5pt;font-family:"Monaco",serif;color:#BA2DA2">false</span><span style="font-size:8.5pt;font-family:"Monaco",serif;color:black">,</span><span style="font-size:8.5pt;font-family:"Monaco",serif;color:#31595D"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:8.5pt;font-family:"Monaco",serif">
<span style="color:#4F8187">RTLIB</span>::<span style="color:#31595D">SRA_I16</span>,<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:8.5pt;font-family:"Monaco",serif">
<span style="color:#4F8187">RTLIB</span>::<span style="color:#31595D">SRA_I16</span>,
<span style="color:#4F8187">RTLIB</span>::<span style="color:#31595D">SRA_I32</span>,<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:8.5pt;font-family:"Monaco",serif;background:white"> <span style="color:#4F8187">RTLIB</span>::<span style="color:#31595D">SRA_I64</span>,
<span style="color:#4F8187">RTLIB</span>::<span style="color:#31595D">SRA_I128</span>));</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">I think this is a BUG by omission of necessary switch cases.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">Similarly, the following ISD codes <span style="font-size:8.5pt;font-family:"Monaco",serif;color:#4F8187;background:white">ISD</span><span style="font-size:8.5pt;font-family:"Monaco",serif;background:white">::<span style="color:#31595D">CTTZ, </span><span style="color:#4F8187">ISD</span>::<span style="color:#31595D">CTLZ, </span><span style="color:#4F8187">ISD</span>::<span style="color:#31595D">CTPOP </span></span>do
not define any Library calls, despite LLVM being able to fully expand them into rather large code for targets that do not natively implement them.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">I regard this also as an omission/bug, because not all targets would benefit from the custom expansion of these ISD codes, which as said can get unnecessarily long and costly. <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">Instead, LLVM should have them available as possible LibCalls.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Any comments or opinions on these subjects are appreciated<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Joan Lluch<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
</div>
</body>
</html>