<div dir="ltr"><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Jul 8, 2020 at 5:31 PM Bevin Hansson via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<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_-3800141808592769840WordSection1">
<p class="MsoNormal"><span lang="SV">Hello,</span></p>
<p class="MsoNormal"><span lang="SV"> </span></p>
<p class="MsoNormal">This is an RFC for adding intrinsics which perform saturating signed/unsigned left shift.</p>
<p class="MsoNormal">There is currently a patch on Phabricator here:</p>
<p class="MsoNormal"><a href="https://reviews.llvm.org/D83216" target="_blank">https://reviews.llvm.org/D83216</a></p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">The intrinsics are of the form</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal"><span lang="SV">    i32 @llvm.sshl.sat.i32(i32, i32)</span></p>
<p class="MsoNormal"><span lang="SV">    i32 @llvm.ushl.sat.i32(i32, i32)</span></p>
<p class="MsoNormal"><span lang="SV">    <4 x i32> @llvm.sshl.sat.v4i32(<4 x i32>, <4 x i32>)</span></p>
<p class="MsoNormal"><span lang="SV">    <4 x i32> @llvm.ushl.sat.v4i32(<4 x i32>, <4 x i32>)</span></p>
<p class="MsoNormal"><span lang="SV"> </span></p>
<p class="MsoNormal">and are overloaded with a single type which can be either an integer type or a vector of integers. The value(s) provided in the first operand are shifted left by the amount(s) given by the second operand. As with regular left shift instructions,
 the second operand is an unsigned quantity and must be less than the integer bitwidth.</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">If the true result of the operation (given infinite precision) lies outside of the maximum or minimum representable value of the signed/unsigned integer, the result saturates to the maximum or minimum depending on the sign of the shifted
 value.</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">These are useful for implementing the Embedded-C fixed-point arithmetic support in Clang, as previously detailed and discussed here:</p>
<p class="MsoNormal"><a href="http://lists.llvm.org/pipermail/llvm-dev/2018-August/125433.html" target="_blank">http://lists.llvm.org/pipermail/llvm-dev/2018-August/125433.html</a></p>
<p class="MsoNormal"><a href="http://lists.llvm.org/pipermail/cfe-dev/2018-May/058019.html" target="_blank">http://lists.llvm.org/pipermail/cfe-dev/2018-May/058019.html</a></p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">It is of course possible to emit these shifts as regular IR instructions, but targets which support saturating shifts might have difficulties efficiently selecting native instructions if the optimizer undoes the particular expected instruction
 pattern that the shifts would be selected on.</p></div></div></blockquote><div><br></div><div>These generally look reasonable to me, and fit in with the existing saturating arithmetic intrinsics. My only question here would be what kind of support these intrinsics are targeting.</div><div><br></div><div>Are you planning to work on high-quality middle end support for them, with an eventual goal of canonicality (as is the case for the existing saturating arithmetic intrinsics), or are these intended to be target intrinsics in all but name (as is the case for the existing fixed-point intrinsics)?<br></div></div><div class="gmail_quote"><br></div><div class="gmail_quote">Regards,</div><div class="gmail_quote">Nikita<br></div></div>