<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;}
/* 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:#0563C1;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri",sans-serif;}
@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" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:14.0pt">We encounter a inline bug in generating call, hard to fix.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:14.0pt">I want to ask some questions here.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:14.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:14.0pt">1<sup>st</sup>  Does the IR generate from FE is wrong ?<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:14.0pt">PLS refer t.ll line3, it use “*m” constrain for call operand “void (...)* @sincos”.   I think the right IR should be   (“m” + “void (...)* @sincos”) or (“*m” + “void (...)** @sincos_ptr”)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:14.0pt">related patch in FE <a href="https://reviews.llvm.org/D107523">
https://reviews.llvm.org/D107523</a><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:14.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:14.0pt">2<sup>nd</sup> How we fix it in Back End ?<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:14.0pt">I find it is hard to fix in BE, because the current arch of inline_asm let us hard to match the variable to its instruction.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:14.0pt">I create a unbeautiful patch at BE too
<a href="https://reviews.llvm.org/D108024">https://reviews.llvm.org/D108024</a>  <o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:14.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:14.0pt">The following code will generate one more time load for “sincos” with cmd “clang -fasm-blocks t.c -fpic -S -emit-llvm” + “llc t.ll”<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:14.0pt">t.c:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:14.0pt">1 extern void sincos ();<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:14.0pt">2 void foo (){<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:14.0pt">3    __asm{<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:14.0pt">4    call  sincos<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:14.0pt">5    ret };<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:14.0pt">6 }<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:14.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:14.0pt">t.ll:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:14.0pt">  1 define void @foo() #0 {<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:14.0pt">  2 entry:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:14.0pt">  3   call void asm sideeffect inteldialect "call qword ptr ${0:P}\0A\09ret", "*m,~{dirflag},~{fpsr},~{flags}"(void (...)* @sincos) #2, !srcloc !5<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:14.0pt">4   ret void<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:14.0pt">5 }<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:14.0pt"><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:14.0pt">t.s:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:14.0pt">1         movq    sincos@GOTPCREL(%rip), %rax        // now the rax has been the function address  “sincos”<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:14.0pt">2 #APP<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:14.0pt">3       callq   *(%rax)                                                      //  the call should directly read the %rax, should not “load” it again, it should be “callq *%rax” or better code “call sincos@plt”<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:14.0pt">4        retq<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:14.0pt">5 #NO_APP<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:14.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:14.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:14.0pt">BR!<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:14.0pt">Thank you!<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:14.0pt">Xiang<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</body>
</html>