<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:"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:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
/* 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:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        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="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal">Hi all,<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I have a question about how large objects passed as arguments by value are handled .<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">One way a target may handle a large object being passed by value is to memcpy the object into the stack before the call. This is seen in the LLVM regressions test suite as 2010-11-04-BigByval.ll<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal" style="line-height:14.25pt;background:#FFFFFE"><span style="font-size:10.5pt;font-family:Consolas;color:black">%big = type [</span><span style="font-size:10.5pt;font-family:Consolas;color:#098658">131072</span><span style="font-size:10.5pt;font-family:Consolas;color:black"> x i8]<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height:14.25pt;background:#FFFFFE"><span style="font-size:10.5pt;font-family:Consolas;color:black"><o:p> </o:p></span></p>
<p class="MsoNormal" style="line-height:14.25pt;background:#FFFFFE"><span style="font-size:10.5pt;font-family:Consolas;color:black">declare </span><span style="font-size:10.5pt;font-family:Consolas;color:blue">void</span><span style="font-size:10.5pt;font-family:Consolas;color:black"> @foo(%big* byval(%big) align </span><span style="font-size:10.5pt;font-family:Consolas;color:#098658">1</span><span style="font-size:10.5pt;font-family:Consolas;color:black">)<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height:14.25pt;background:#FFFFFE"><span style="font-size:10.5pt;font-family:Consolas;color:black"><o:p> </o:p></span></p>
<p class="MsoNormal" style="line-height:14.25pt;background:#FFFFFE"><span style="font-size:10.5pt;font-family:Consolas;color:black">define </span><span style="font-size:10.5pt;font-family:Consolas;color:blue">void</span><span style="font-size:10.5pt;font-family:Consolas;color:black"> @bar(%big* byval(%big) align </span><span style="font-size:10.5pt;font-family:Consolas;color:#098658">1</span><span style="font-size:10.5pt;font-family:Consolas;color:black"> %x) {<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height:14.25pt;background:#FFFFFE"><span style="font-size:10.5pt;font-family:Consolas;color:black">  call </span><span style="font-size:10.5pt;font-family:Consolas;color:blue">void</span><span style="font-size:10.5pt;font-family:Consolas;color:black"> @foo(%big* byval(%big) align </span><span style="font-size:10.5pt;font-family:Consolas;color:#098658">1</span><span style="font-size:10.5pt;font-family:Consolas;color:black"> %x)<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height:14.25pt;background:#FFFFFE"><span style="font-size:10.5pt;font-family:Consolas;color:black">  ret </span><span style="font-size:10.5pt;font-family:Consolas;color:blue">void</span><span style="font-size:10.5pt;font-family:Consolas;color:black"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height:14.25pt;background:#FFFFFE"><span style="font-size:10.5pt;font-family:Consolas;color:black">}<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">On our downstream target, this test fails in the MachineVerifier. Lowering of the call to @foo creates a call to memcpy to copy %x onto the stack so that it’s passed by value. This results in the following code:<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">ADJCALLSTACKDOWN (For call to @foo)<o:p></o:p></p>
<p class="MsoNormal" style="text-indent:.5in">ADJCALLSTACKDOWN (For call to @memcpy)<o:p></o:p></p>
<p class="MsoNormal" style="text-indent:.5in">call memcpy<o:p></o:p></p>
<p class="MsoNormal" style="text-indent:.5in">ADJCALLSTACKUP (For call to @memcpy)<o:p></o:p></p>
<p class="MsoNormal">call @foo<o:p></o:p></p>
<p class="MsoNormal">ADJCALLSTACKUP (For call to @foo)<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">The verifier is specifically checking that each ‘FrameSetup’ (here, ADJCALLSTACKDOWN) is followed by ‘FrameDestroy’ (here, ADJCALLSTACKUP), with no intervening ‘FrameSetup’. I thought this to be an issue with our implementation, but I then
 ran this example on the AArch64 target available on Compiler Explorer:<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><a href="https://godbolt.org/z/j1veMhqdY">https://godbolt.org/z/j1veMhqdY</a><o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">And saw the same error. My searches through the email list, docs, and bug list couldn’t immediately find a reference to this test or error and how to avoid it or do it correctly. The only thing I can think of is hoisting the call to memcpy
 above the first FrameSetup instruction, but I don’t think I understand enough about what these instructions are doing or why the MachineVerifier cares about such ordering. Is there a correct way to perform this operation to make the verifier happy?<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Regards,<o:p></o:p></p>
<p class="MsoNormal">J.B. Nagurne<o:p></o:p></p>
<p class="MsoNormal">Code Generation<o:p></o:p></p>
<p class="MsoNormal">Texas Instruments<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</body>
</html>