<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jul 26, 2016 at 11:27 PM, Chandler Carruth <span dir="ltr"><<a href="mailto:chandlerc@google.com" target="_blank">chandlerc@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><span class="gmail-"><div dir="ltr">On Tue, Jul 26, 2016 at 11:19 PM Xinliang David Li <<a href="mailto:davidxl@google.com" target="_blank">davidxl@google.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Jul 26, 2016 at 11:11 PM, Chandler Carruth <span dir="ltr"><<a href="mailto:chandlerc@google.com" target="_blank">chandlerc@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><span><div dir="ltr">On Tue, Jul 26, 2016 at 11:08 PM Xinliang David Li via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hmm, why does Clang change the return type from from struct to i64?  Set aside whether it is always beneficial to do it or not, it certainly feels like the wrong place to make such a change.</div></blockquote><div><br></div></span><div>It's necessary to get the right ABI out of LLVM.</div><div><br></div></div></div></blockquote><div><br></div></div></div></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>what ABI issue and what can be wrong without using i64? I might have missed something obvious here.</div></div></div></div></blockquote><div><br></div></span><div>The ABI specifies that a struct such as this is returned in a single 64-bit integer register.</div></div></div></blockquote><div><br></div><div>yes, at least for system V ABI for x86_64.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><div><br></div><div>Consider this C++ test case:</div><div><div>long long a();</div><div><br></div><div>struct S { int i; float f; };</div><div>S b();</div><div><br></div><div>void f(long long *ptr1, S *ptr2) {</div><div>  *ptr1 = a();</div><div>  *ptr2 = b();</div><div>}</div></div><div><br></div><div>It compiles to:</div><div><div>        callq   _Z1av</div><div>        movq    %rax, (%rbx)</div><div>        callq   _Z1bv</div><div>        movq    %rax, (%r14)</div></div><div><br></div><div>Both need to be in the single register.</div><div><br></div><div>But if you consider the following IR:</div><div><div>declare i64 @a()</div><div>declare {i32, float} @b()</div><div><br></div><div>define void @f(i64* %ptr1, {i32, float}* %ptr2) {</div><div>entry:</div><div>  %calla = call i64 @a()</div><div>  store i64 %calla, i64* %ptr1</div><div>  %callb = call {i32, float} @b()</div><div>  store {i32, float} %callb, {i32, float}* %ptr2</div><div>  ret void</div><div>}</div></div><div><br></div><div>The LLVM lowering of the call to @b isn't what you want:</div><div><div>        callq   a</div><div>        movq    %rax, (%r14)</div><div>        callq   b</div><div>        movl    %eax, (%rbx)</div><div>        movss   %xmm0, 4(%rbx)</div></div><div><br></div><div>In order to get the ABI's semantics, we have to map the type into something that will actually get lowered in that exact manner.</div></div></div></blockquote><div><br></div><div>Still, the FE does not seem to be the right place to fix the bug (considering multiple different FEs targeting LLVM). It seems to me this bug is either due to the call return lowering either happens too early or needs to be target dependent.<br></div><div><br></div><div>David</div><div><br></div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><span class="gmail-HOEnZb"><font color="#888888"><div><br></div><div>-Chandler</div></font></span><span class="gmail-"><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><br></div><div>David</div></div></div></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><div></div><div>Lot's of folks have hypothesized about how to separate the ABI concerns from the LLVM IR representation but it has so far proved a really tricky problem and its not clear there is a good solution.</div><div> </div></div></div></blockquote><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span><div dir="ltr"><div><br></div><div>David</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jul 26, 2016 at 10:40 PM, Wei Mi <span dir="ltr"><<a href="mailto:wmi@google.com" target="_blank">wmi@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">wmi added a comment.<br>
<br>
Matt, David and Chandler, thanks for the review.<br>
<br>
I only looked at the code for x86-64, powerpc and aarch64 targets. For those targets, separate stores seemed better. I am not familiar with target like AMDGPU. I guess wider store is generally preferred than multiple narrower stores on AMDGPU? Since it may be undesirable on some targets, I agree it is more appropriate to implement it in SDAG pass. I will update the patch.<br>
<div class="gmail-m_894494155324454185m_-1049574281183097777m_-7379906320026832171m_5537306404573635425HOEnZb"><div class="gmail-m_894494155324454185m_-1049574281183097777m_-7379906320026832171m_5537306404573635425h5"><br>
<br>
Repository:<br>
  rL LLVM<br>
<br>
<a href="https://reviews.llvm.org/D22840" rel="noreferrer" target="_blank">https://reviews.llvm.org/D22840</a><br>
<br>
<br>
<br>
</div></div></blockquote></div><br></div></span>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div></div>
</blockquote></div></div></div></blockquote></span></div></div>
</blockquote></div><br></div></div>