<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” 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.<div class=""><br class=""><div class="">
<span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;  "><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:35, 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="">Does:<br class=""><blockquote type="cite" 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.<br class=""></blockquote><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" class="">christoffer@aegik.com</a>> <br class="">Sent: Monday, November 16, 2020 9:33 AM<br class="">To: Keane, Erich <<a href="mailto:erich.keane@intel.com" class="">erich.keane@intel.com</a>><br class="">Cc: Hans Wennborg <<a href="mailto:hans@chromium.org" class="">hans@chromium.org</a>>; clang developer list <<a href="mailto:cfe-dev@lists.llvm.org" 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=""><blockquote type="cite" 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.<br class=""></blockquote><br class="">Christoffer<br class="">AEGIK / <a href="http://www.aegik.se" class="">www.aegik.se</a><br class=""><br class=""><blockquote type="cite" class="">On 16 Nov 2020, at 17:30, Keane, Erich <<a href="mailto:erich.keane@intel.com" 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" class="">hans@chromium.org</a>> <br class="">Sent: Monday, November 16, 2020 8:24 AM<br class="">To: Christoffer Lernö <<a href="mailto:christoffer@aegik.com" class="">christoffer@aegik.com</a>>; Keane, Erich <<a href="mailto:erich.keane@intel.com" class="">erich.keane@intel.com</a>><br class="">Cc: clang developer list <<a href="mailto:cfe-dev@lists.llvm.org" 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" class="">cfe-dev@lists.llvm.org</a>> wrote:<br class=""><blockquote type="cite" 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?<br class=""></blockquote><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" 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="">https://reviews.llvm.org/D27529 Maybe he can comment?<br class=""><br class="">Thanks,<br class="">Hans<br class=""></blockquote><br class=""></div></div></blockquote></div><br class=""></div></body></html>