<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:SimSun;
panose-1:2 1 6 0 3 1 1 1 1 1;}
@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:SimSun;
panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
{font-family:Verdana;
panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
text-align:justify;
text-justify:inter-ideograph;
font-size:10.5pt;
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;}
span.EmailStyle17
{mso-style-type:personal-compose;
font-family:"Calibri",sans-serif;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;
font-family:"Calibri",sans-serif;}
/* Page Definitions */
@page WordSection1
{size:612.0pt 792.0pt;
margin:72.0pt 90.0pt 72.0pt 90.0pt;}
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="ZH-CN" link="#0563C1" vlink="#954F72" style="text-justify-trim:punctuation">
<div class="WordSection1">
<p class="MsoNormal"><span lang="EN-US">Hello,<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">We are developing the atomic built-in function for OpenCL 2.0. we use SPIR64 as the target and hope to lower the llvm built-in functions like ‘__c11_atomic_fetch_and_sub’ to instructions like ‘atomicrmw’, but the MaxAtomicInlineWidth
of SPIR64TargetInfo is not set by default, so the EmitAtomicExpr goes to libcall path and got function ‘__atomic_fetch_sub_4’, which is unexpected.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">After set the variable <b><i>MaxAtomicInlineWidth, the
</i></b>EmitAtomicExpr take the non-libcall path and get instruction: ‘%1 = atomicrmw volatile sub i32* %arrayinit.begin, i32 1 acquire’<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><i><span lang="EN-US">class SPIR64TargetInfo : public SPIRTargetInfo {<o:p></o:p></span></i></p>
<p class="MsoNormal"><i><span lang="EN-US">public:<o:p></o:p></span></i></p>
<p class="MsoNormal"><i><span lang="EN-US"> SPIR64TargetInfo(const llvm::Triple &Triple) : SPIRTargetInfo(Triple) {<o:p></o:p></span></i></p>
<p class="MsoNormal"><i><span lang="EN-US"> PointerWidth = PointerAlign = 64;<o:p></o:p></span></i></p>
<p class="MsoNormal"><i><span lang="EN-US"> SizeType = TargetInfo::UnsignedLong;<o:p></o:p></span></i></p>
<p class="MsoNormal"><i><span lang="EN-US"> PtrDiffType = IntPtrType = TargetInfo::SignedLong;<o:p></o:p></span></i></p>
<p class="MsoNormal"><i><span lang="EN-US"> DataLayoutString = "e-i64:64-v16:16-v24:32-v32:32-v48:64-"<o:p></o:p></span></i></p>
<p class="MsoNormal"><i><span lang="EN-US"> "v96:128-v192:256-v256:256-v512:512-v1024:1024";<o:p></o:p></span></i></p>
<p class="MsoNormal"><b><i><span lang="EN-US">+ MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;<o:p></o:p></span></i></b></p>
<p class="MsoNormal"><i><span lang="EN-US"> }<o:p></o:p></span></i></p>
<p class="MsoNormal"><i><span lang="EN-US"> void getTargetDefines(const LangOptions &Opts,<o:p></o:p></span></i></p>
<p class="MsoNormal"><i><span lang="EN-US"> MacroBuilder &Builder) const override {<o:p></o:p></span></i></p>
<p class="MsoNormal"><i><span lang="EN-US"> DefineStd(Builder, "SPIR64", Opts);<o:p></o:p></span></i></p>
<p class="MsoNormal"><i><span lang="EN-US"> }<o:p></o:p></span></i></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">So the question is why some other targets set the MaxAtomicInlineWidth when created but SPIR64TargetInfo did NOT? Shall we add it as above?<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Thanks.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">The mentioned OpenCL test kernel is as below, command is ‘./clang -cc1 -emit-llvm -triple spir64 -cl-std=CL2.0 atomic_functions.cl -o atomic_functions.spir’:<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><i><span lang="EN-US">__kernel void atomic_functions()<o:p></o:p></span></i></p>
<p class="MsoNormal"><i><span lang="EN-US">{<o:p></o:p></span></i></p>
<p class="MsoNormal"><i><span lang="EN-US"> volatile atomic_uint ptest[2] = {0};<o:p></o:p></span></i></p>
<p class="MsoNormal"><i><span lang="EN-US"> int test = __c11_atomic_fetch_sub(&ptest[0], 1, 1);<o:p></o:p></span></i></p>
<p class="MsoNormal"><i><span lang="EN-US">}<o:p></o:p></span></i></p>
<p class="MsoNormal"><i><span lang="EN-US"><o:p> </o:p></span></i></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-family:"Verdana",sans-serif;color:#44546A">Luo
</span><span lang="EN-US" style="font-family:"Verdana",sans-serif;color:#1F497D">Xionghu</span><span lang="EN-US" style="font-family:"Verdana",sans-serif;color:#44546A"><o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-family:"Verdana",sans-serif;color:#44546A">Best Regards<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
</div>
</body>
</html>