<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=utf-8">
<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;
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;}
span.EmailStyle20
{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">
<div class="WordSection1">
<p class="MsoNormal">I don’t particularly get the ‘expand is never valid for returns’, as I’m sure I’ve seen it before, but I’m also sure I don’t know the ABI code well enough to speak with authority.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">There might be some other goofiness in that code as well. I wouldn’t expect the return-value to decrease the available number of registers, since returns re-use registers.
<o:p></o:p></p>
<p class="MsoNormal"><br>
Either way, you’re likely right that that this code needs work. Patches welcome <span style="font-family:"Segoe UI Emoji",sans-serif">
😊</span> <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>From:</b> Christoffer Lernö <christoffer@aegik.com> <br>
<b>Sent:</b> Monday, November 16, 2020 9:37 AM<br>
<b>To:</b> Keane, Erich <erich.keane@intel.com><br>
<b>Cc:</b> Hans Wennborg <hans@chromium.org>; clang developer list <cfe-dev@lists.llvm.org><br>
<b>Subject:</b> Re: [cfe-dev] Possible bug in Win64 ABI in Clang?<o:p></o:p></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">”Expand” is never valid for returns, as it simply splits an aggregate over multiple parameters. If it fits in 4 registers I assume it is a ”direct” as it is written.<o:p></o:p></p>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<p class="MsoNormal"><span style="font-family:"Helvetica",sans-serif;color:black">Christoffer<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:"Helvetica",sans-serif;color:black">AEGIK /
<a href="http://www.aegik.se">www.aegik.se</a><o:p></o:p></span></p>
</div>
</div>
<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 16 Nov 2020, at 18:35, Keane, Erich <<a href="mailto:erich.keane@intel.com">erich.keane@intel.com</a>> wrote:<o:p></o:p></p>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<p class="MsoNormal">Does:<br>
<br>
<o:p></o:p></p>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<p class="MsoNormal">HVA results have each data element returned by value in registers XMM0:XMM3 or YMM0:YMM3, depending on element size. Other result types are returned by reference to memory allocated by the caller.<o:p></o:p></p>
</blockquote>
<p class="MsoNormal"><br>
Mean we should be doing 'expand' if the type fits in 4 registers? <br>
<br>
-----Original Message-----<br>
From: Christoffer Lernö <<a href="mailto:christoffer@aegik.com">christoffer@aegik.com</a>>
<br>
Sent: Monday, November 16, 2020 9:33 AM<br>
To: Keane, Erich <<a href="mailto:erich.keane@intel.com">erich.keane@intel.com</a>><br>
Cc: Hans Wennborg <<a href="mailto:hans@chromium.org">hans@chromium.org</a>>; clang developer list <<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>><br>
Subject: Re: [cfe-dev] Possible bug in Win64 ABI in Clang?<br>
<br>
As far as I can tell it should simply do an indirect here:<br>
<br>
<br>
<o:p></o:p></p>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<p class="MsoNormal">Results of __vectorcall functions are returned by value in registers when possible. Results of integer type, including structs or unions of 4 bytes or less, are returned by value in EAX. Integer type structs or unions of 8 bytes or less
are returned by value in EDX:EAX. Vector type results are returned by value in XMM0 or YMM0, depending on size. HVA results have each data element returned by value in registers XMM0:XMM3 or YMM0:YMM3, depending on element size. Other result types are returned
by reference to memory allocated by the caller.<o:p></o:p></p>
</blockquote>
<p class="MsoNormal"><br>
Christoffer<br>
AEGIK / <a href="http://www.aegik.se">www.aegik.se</a><br>
<br>
<br>
<o:p></o:p></p>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<p class="MsoNormal">On 16 Nov 2020, at 17:30, Keane, Erich <<a href="mailto:erich.keane@intel.com">erich.keane@intel.com</a>> wrote:<br>
<br>
That was long enough ago that I don't really remember. At the time, I wrote tests to validate the behaviors I think (which would mean it didn't crash?), but I could buy that I did something wrong back then. Do we have an idea what the return-type ABIArgInfo
should be? I'm sorry I cannot be more helpful here. <br>
<br>
-----Original Message-----<br>
From: Hans Wennborg <<a href="mailto:hans@chromium.org">hans@chromium.org</a>> <br>
Sent: Monday, November 16, 2020 8:24 AM<br>
To: Christoffer Lernö <<a href="mailto:christoffer@aegik.com">christoffer@aegik.com</a>>; Keane, Erich <<a href="mailto:erich.keane@intel.com">erich.keane@intel.com</a>><br>
Cc: clang developer list <<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>><br>
Subject: Re: [cfe-dev] Possible bug in Win64 ABI in Clang?<br>
<br>
On Sat, Nov 14, 2020 at 12:36 PM Christoffer Lernö via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>> wrote:<br>
<br>
<o:p></o:p></p>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<p class="MsoNormal"><br>
Perusing the Clang source, I found something rather confusing:<br>
<br>
if ((IsVectorCall || IsRegCall) &&<br>
isHomogeneousAggregate(Ty, Base, NumElts)) {<br>
if (IsRegCall) {<br>
if (FreeSSERegs >= NumElts) {<br>
FreeSSERegs -= NumElts;<br>
if (IsReturnType || Ty->isBuiltinType() || Ty->isVectorType())<br>
return ABIArgInfo::getDirect();<br>
return ABIArgInfo::getExpand();<br>
}<br>
return ABIArgInfo::getIndirect(Align, /*ByVal=*/false);<br>
} else if (IsVectorCall) {<br>
if (FreeSSERegs >= NumElts &&<br>
(IsReturnType || Ty->isBuiltinType() || Ty->isVectorType())) {<br>
FreeSSERegs -= NumElts;<br>
return ABIArgInfo::getDirect();<br>
} else if (IsReturnType) {<br>
return ABIArgInfo::getExpand();<br>
} else if (!Ty->isBuiltinType() && !Ty->isVectorType()) {<br>
// HVAs are delayed and reclassified in the 2nd step.<br>
return ABIArgInfo::getIndirect(Align, /*ByVal=*/false);<br>
}<br>
}<br>
}<br>
<br>
<br>
If we look at ”isReturnType” for IsVectorCall = true has ”ABIArgInfo::getExpand()” however, ”expand” is not a valid type of ABIArgInfo and will throw an error.<br>
<br>
So this seems to be incorrect and should crash on vectorcall with HVA. Can someone confirm?<o:p></o:p></p>
</blockquote>
<p class="MsoNormal"><br>
For reference, that code is from WinX86_64ABIInfo::classify() here:<br>
<a href="https://github.com/llvm/llvm-project/blob/bc7df035ae68648fe39304d9e77cd7618812cca8/clang/lib/CodeGen/TargetInfo.cpp#L4200">https://github.com/llvm/llvm-project/blob/bc7df035ae68648fe39304d9e77cd7618812cca8/clang/lib/CodeGen/TargetInfo.cpp#L4200</a><br>
<br>
I'm not familiar with this code, but it looks like Erich wrote it in<br>
<a href="https://reviews.llvm.org/D27529">https://reviews.llvm.org/D27529</a> Maybe he can comment?<br>
<br>
Thanks,<br>
Hans<o:p></o:p></p>
</blockquote>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
</blockquote>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
</body>
</html>