<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Expand assumes parameters, since it basically takes the struct and drops each part of the struct into a different parameter (e.g. void foo(struct { int , int }) -> void foo(int, int) ). Which cannot work because you can at most have a single value return value in the function prototype. So the ”expand” is not even implemented for return values in the code.<div class=""><br class=""><div class=""><div class="">
<span class="Apple-style-span" style="border-collapse: separate; font-variant-ligatures: normal; font-variant-east-asian: normal; font-variant-position: normal; line-height: normal; border-spacing: 0px; -webkit-text-decorations-in-effect: none;"><div class="">Christoffer</div><div class="">AEGIK / <a href="http://www.aegik.se" class="">www.aegik.se</a></div></span>

</div>
<div><br class=""><blockquote type="cite" class=""><div class="">On 16 Nov 2020, at 18:39, Keane, Erich <<a href="mailto:erich.keane@intel.com" class="">erich.keane@intel.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="WordSection1" style="page: WordSection1; caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class="">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 class=""></o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class="">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 class=""></o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><br class="">Either way, you’re likely right that that this code needs work.  Patches welcome<span class="Apple-converted-space"> </span><span style="font-family: "Segoe UI Emoji", sans-serif;" class="">😊</span><o:p class=""></o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div><div class=""><div style="border-style: solid none none; border-top-width: 1pt; border-top-color: rgb(225, 225, 225); padding: 3pt 0in 0in;" class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><b class="">From:</b><span class="Apple-converted-space"> </span>Christoffer Lernö <<a href="mailto:christoffer@aegik.com" style="color: blue; text-decoration: underline;" class="">christoffer@aegik.com</a>><span class="Apple-converted-space"> </span><br class=""><b class="">Sent:</b><span class="Apple-converted-space"> </span>Monday, November 16, 2020 9:37 AM<br class=""><b class="">To:</b><span class="Apple-converted-space"> </span>Keane, Erich <<a href="mailto:erich.keane@intel.com" style="color: blue; text-decoration: underline;" class="">erich.keane@intel.com</a>><br class=""><b class="">Cc:</b><span class="Apple-converted-space"> </span>Hans Wennborg <<a href="mailto:hans@chromium.org" style="color: blue; text-decoration: underline;" class="">hans@chromium.org</a>>; clang developer list <<a href="mailto:cfe-dev@lists.llvm.org" style="color: blue; text-decoration: underline;" class="">cfe-dev@lists.llvm.org</a>><br class=""><b class="">Subject:</b><span class="Apple-converted-space"> </span>Re: [cfe-dev] Possible bug in Win64 ABI in Clang?<o:p class=""></o:p></div></div></div><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class="">”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 class=""></o:p></div><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div><div class=""><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span style="font-family: Helvetica, sans-serif;" class="">Christoffer<o:p class=""></o:p></span></div></div><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span style="font-family: Helvetica, sans-serif;" class="">AEGIK /<span class="Apple-converted-space"> </span><a href="http://www.aegik.se/" style="color: blue; text-decoration: underline;" class="">www.aegik.se</a><o:p class=""></o:p></span></div></div></div><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><br class=""><br class=""><o:p class=""></o:p></div><blockquote style="margin-top: 5pt; margin-bottom: 5pt;" class=""><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class="">On 16 Nov 2020, at 18:35, Keane, Erich <<a href="mailto:erich.keane@intel.com" style="color: blue; text-decoration: underline;" class="">erich.keane@intel.com</a>> wrote:<o:p class=""></o:p></div></div><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div><div class=""><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class="">Does:<br class=""><br class=""><o:p class=""></o:p></div><blockquote style="margin-top: 5pt; margin-bottom: 5pt;" class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class="">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 class=""></o:p></div></blockquote><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><br class="">Mean we should be doing 'expand' if the type fits in 4 registers?  <br class=""><br class="">-----Original Message-----<br class="">From: Christoffer Lernö <<a href="mailto:christoffer@aegik.com" style="color: blue; text-decoration: underline;" class="">christoffer@aegik.com</a>><span class="Apple-converted-space"> </span><br class="">Sent: Monday, November 16, 2020 9:33 AM<br class="">To: Keane, Erich <<a href="mailto:erich.keane@intel.com" style="color: blue; text-decoration: underline;" class="">erich.keane@intel.com</a>><br class="">Cc: Hans Wennborg <<a href="mailto:hans@chromium.org" style="color: blue; text-decoration: underline;" class="">hans@chromium.org</a>>; clang developer list <<a href="mailto:cfe-dev@lists.llvm.org" style="color: blue; text-decoration: underline;" class="">cfe-dev@lists.llvm.org</a>><br class="">Subject: Re: [cfe-dev] Possible bug in Win64 ABI in Clang?<br class=""><br class="">As far as I can tell it should simply do an indirect here:<br class=""><br class=""><br class=""><o:p class=""></o:p></div><blockquote style="margin-top: 5pt; margin-bottom: 5pt;" class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class="">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 class=""></o:p></div></blockquote><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><br class="">Christoffer<br class="">AEGIK /<span class="Apple-converted-space"> </span><a href="http://www.aegik.se/" style="color: blue; text-decoration: underline;" class="">www.aegik.se</a><br class=""><br class=""><br class=""><o:p class=""></o:p></div><blockquote style="margin-top: 5pt; margin-bottom: 5pt;" class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class="">On 16 Nov 2020, at 17:30, Keane, Erich <<a href="mailto:erich.keane@intel.com" style="color: blue; text-decoration: underline;" class="">erich.keane@intel.com</a>> wrote:<br class=""><br class="">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 class=""><br class="">-----Original Message-----<br class="">From: Hans Wennborg <<a href="mailto:hans@chromium.org" style="color: blue; text-decoration: underline;" class="">hans@chromium.org</a>><span class="Apple-converted-space"> </span><br class="">Sent: Monday, November 16, 2020 8:24 AM<br class="">To: Christoffer Lernö <<a href="mailto:christoffer@aegik.com" style="color: blue; text-decoration: underline;" class="">christoffer@aegik.com</a>>; Keane, Erich <<a href="mailto:erich.keane@intel.com" style="color: blue; text-decoration: underline;" class="">erich.keane@intel.com</a>><br class="">Cc: clang developer list <<a href="mailto:cfe-dev@lists.llvm.org" style="color: blue; text-decoration: underline;" class="">cfe-dev@lists.llvm.org</a>><br class="">Subject: Re: [cfe-dev] Possible bug in Win64 ABI in Clang?<br class=""><br class="">On Sat, Nov 14, 2020 at 12:36 PM Christoffer Lernö via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org" style="color: blue; text-decoration: underline;" class="">cfe-dev@lists.llvm.org</a>> wrote:<br class=""><br class=""><o:p class=""></o:p></div><blockquote style="margin-top: 5pt; margin-bottom: 5pt;" class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><br class="">Perusing the Clang source, I found something rather confusing:<br class=""><br class="">if ((IsVectorCall || IsRegCall) &&<br class="">    isHomogeneousAggregate(Ty, Base, NumElts)) {<br class="">  if (IsRegCall) {<br class="">    if (FreeSSERegs >= NumElts) {<br class="">      FreeSSERegs -= NumElts;<br class="">      if (IsReturnType || Ty->isBuiltinType() || Ty->isVectorType())<br class="">        return ABIArgInfo::getDirect();<br class="">      return ABIArgInfo::getExpand();<br class="">    }<br class="">    return ABIArgInfo::getIndirect(Align, /*ByVal=*/false);<br class="">  } else if (IsVectorCall) {<br class="">    if (FreeSSERegs >= NumElts &&<br class="">        (IsReturnType || Ty->isBuiltinType() || Ty->isVectorType())) {<br class="">      FreeSSERegs -= NumElts;<br class="">      return ABIArgInfo::getDirect();<br class="">    } else if (IsReturnType) {<br class="">      return ABIArgInfo::getExpand();<br class="">    } else if (!Ty->isBuiltinType() && !Ty->isVectorType()) {<br class="">      // HVAs are delayed and reclassified in the 2nd step.<br class="">      return ABIArgInfo::getIndirect(Align, /*ByVal=*/false);<br class="">    }<br class="">  }<br class="">}<br class=""><br class=""><br class="">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 class=""><br class="">So this seems to be incorrect and should crash on vectorcall with HVA. Can someone confirm?<o:p class=""></o:p></div></blockquote><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><br class="">For reference, that code is from WinX86_64ABIInfo::classify() here:<br class=""><a href="https://github.com/llvm/llvm-project/blob/bc7df035ae68648fe39304d9e77cd7618812cca8/clang/lib/CodeGen/TargetInfo.cpp#L4200" style="color: blue; text-decoration: underline;" class="">https://github.com/llvm/llvm-project/blob/bc7df035ae68648fe39304d9e77cd7618812cca8/clang/lib/CodeGen/TargetInfo.cpp#L4200</a><br class=""><br class="">I'm not familiar with this code, but it looks like Erich wrote it in<br class=""><a href="https://reviews.llvm.org/D27529" style="color: blue; text-decoration: underline;" class="">https://reviews.llvm.org/D27529</a><span class="Apple-converted-space"> </span>Maybe he can comment?<br class=""><br class="">Thanks,<br class="">Hans</div></blockquote></div></div></blockquote></div></div></div></div></blockquote></div><br class=""></div></div></body></html>