<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=koi8-r">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:Helvetica;
panose-1:2 11 6 4 2 2 2 2 2 4;}
@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;
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="blue" vlink="purple" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal">I propose they have signatures similar to non-atomic/atomic llvm.memcpy:<br>
llvm_i32_ty llvm.memcmp (llvm_anyptr_ty %lhs, llvm_anyptr_ty %rhs, llvm_anyint_ty %length, llvm_i1_ty %is_volatile),<br>
llvm_i32_ty llvm.bcmp (llvm_anyptr_ty %lhs, llvm_anyptr_ty %rhs, llvm_anyint_ty %length, llvm_i1_ty %is_volatile),<br>
llvm_i32_ty llvm.memcmp.element.unordered.atomic (llvm_anyptr_ty %lhs, llvm_anyptr_ty %rhs, llvm_anyint_ty %length, llvm_i32_ty %element_size),<br>
llvm_i32_ty llvm.bcmp.element.unordered.atomic (llvm_anyptr_ty %lhs, llvm_anyptr_ty %rhs, llvm_anyint_ty %length, llvm_i32_ty %element_size).<br>
<br>
<o:p></o:p></p>
<p class="MsoNormal">Having such signatures, it’s easy to transform the libc calls to the new intrinsics.<br>
<br>
Our main motivation for having these intrinsics is that we want to have an atomic memory comparison semantics, which we can’t express through a libc call.
<br>
And if we are to add an atomic memcmp intrinsic, it’d natural to transform libc calls to intrinsics and we’d have some common logic work for all these functions.<br>
<br>
Dmitry<br>
<br>
<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"><b><span lang="RU">От:</span></b><span lang="RU"> Chris Lattner <clattner@nondot.org>
<br>
<b>Отправлено:</b> Tuesday, November 23, 2021 2:29 PM<br>
<b>Кому:</b> Dmitry Makogon <dmakogon@azul.com><br>
<b>Копия:</b> llvm-dev@lists.llvm.org<br>
<b>Тема:</b> Re: [llvm-dev] Proposal: Introduce memory comparison intrinsics<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal"><br>
<br>
<o:p></o:p></p>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<div>
<p class="MsoNormal">On Nov 22, 2021, at 6:22 AM, Dmitry Makogon via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<o:p></o:p></p>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<p class="MsoNormal">Hello everyone.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">I would like to introduce new intrinsics for memory comparison:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">memcmp - an equivalent of libc' memcmp,<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">bcmp - an equivalent of libc' bcmp,<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">memcmp.element.unordered.atomic - an element atomic version of memcmp,<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">bcmp.element.unordered.atomic - an element atomic version of bcmp.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">Currently there exist some optimizations for memcmp/bcmp libc calls.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">We would like to have these optimizations for element atomic comparisons (atomicity permitted).<o:p></o:p></p>
</div>
</div>
</blockquote>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Could you elaborate on the specific signatures these intrinsics would have?<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">llvm.memcpy and friends exist because we want to capture additional semantics beyond what the memcpy signature does - notably alignment information. What is all the additional information are you planning to capture for these?<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">-Chris<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<p class="MsoNormal"><br>
<br>
<o:p></o:p></p>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">I suggest we rewrite the existing optimizations to work with on new intrinsics and transform<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">memcmp/bcmp libc calls to the corresponding intrinsics. This is similar to what we do with<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">memcpy library calls.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">Having these optimizations work on intrinsics and not on recognized libc calls<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">will allow us to share some existing transforms between atomic and non-atomic variants.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">I propose the following plan for introducing the new intrinsics:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">1. Introduce non-atomic memcmp and bcmp intrinsics.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">2. Reimplement existing transforms for non-atomic memcmp intrinsic,<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">the same way as it's done for memcpy.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">3. Introduce atomic intrinsics and reuse the optimizations.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">Please express your concerns about this.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">Dmitry<o:p></o:p></p>
</div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Helvetica",sans-serif">_______________________________________________<br>
LLVM Developers mailing list<br>
</span><a href="mailto:llvm-dev@lists.llvm.org"><span style="font-size:9.0pt;font-family:"Helvetica",sans-serif">llvm-dev@lists.llvm.org</span></a><span style="font-size:9.0pt;font-family:"Helvetica",sans-serif"><br>
</span><a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev"><span style="font-size:9.0pt;font-family:"Helvetica",sans-serif">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</span></a><o:p></o:p></p>
</div>
</blockquote>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</body>
</html>