<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div>Thanks Bruce.</div><div><br class=""><blockquote type="cite" class=""><div class="">On 4 May 2015, at 13:18, Bruce Hoult <<a href="mailto:bruce@hoult.org" class="">bruce@hoult.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">I can confirm that, with Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn)<div class=""><br class=""></div><div class="">Very strange!</div></div></div></blockquote><div><br class=""></div><div>Yes, that’s what I thought. I’ve also checked the binary downloads for OS X from <a href="http://llvm.org" class="">llvm.org</a> and get the same broken code from both the 3.5.2 and 3.6.0 releases. -arch arm64 wasn’t supported on the 3.4 branch, so wasn’t able to test there, but I imagine this has been there from the start of the arm64 backend.</div><div><br class=""></div><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="">I don't know if it helps you, but this looks correct:</div></div></div></blockquote><div><br class=""></div><div>My guess was that as the result elements are returned in registers there might be a bug somewhere around the final element being treated as unused and optimized away, but I’d expect your code to trigger the same issue in that case. My actual code uses a Vector class templated on the size of the vector so your approach so your approach doesn’t really help there. I’m able to work around it easily enough though - as soon as the function does any actual work with the value it seems to work OK.</div><div><br class=""></div><div>It is quite a worrying bug for me though - there are quite a lot of functions in my codebase that return small (length 2 or 3) Vector types - generally in headers so they can be inlined an optimized well - but I’d definitely like to understand the root cause of this one so I can be on the lookout for any other similar failures.</div><div><br class=""></div><div>Simon</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><br class=""></div><div class=""><div class="">typedef struct {float v0, v1;} vec2;</div><div class="">typedef struct {float v0, v1, v2;} vec3;</div><div class=""><br class=""></div><div class="">vec2 getVec2();</div><div class=""><br class=""></div><div class="">vec3 getVec3()</div><div class="">{</div><div class="">  vec2 myVec = getVec2();</div><div class=""><br class=""></div><div class="">  vec3 res;</div><div class="">  res.v0 = myVec.v0;</div><div class="">  res.v1 = myVec.v1;</div><div class="">  res.v2 = 1;</div><div class="">  return res;</div><div class="">}</div></div><div class=""><br class=""></div><div class=""><div class=""><span class="" style="white-space:pre">        </span>.section<span class="" style="white-space:pre">  </span>__TEXT,__text,regular,pure_instructions</div><div class=""><span class="" style="white-space:pre"> </span>.globl<span class="" style="white-space:pre">    </span>_getVec3</div><div class=""><span class="" style="white-space:pre">        </span>.align<span class="" style="white-space:pre">    </span>2</div><div class="">_getVec3:                               ; @getVec3</div><div class="">; BB#0:</div><div class=""><span class="" style="white-space:pre">       </span>stp<span class="" style="white-space:pre">       </span>fp, lr, [sp, #-16]!</div><div class=""><span class="" style="white-space:pre">     </span>mov<span class="" style="white-space:pre">       </span> fp, sp</div><div class=""><span class="" style="white-space:pre"> </span>bl<span class="" style="white-space:pre">        </span>_getVec2</div><div class=""><span class="" style="white-space:pre">        </span>fmov<span class="" style="white-space:pre">      </span>s2, #1.000000e+00</div><div class=""><span class="" style="white-space:pre">       </span>ldp<span class="" style="white-space:pre">       </span>fp, lr, [sp], #16</div><div class=""><span class="" style="white-space:pre">       </span>ret</div></div><div class=""><br class=""></div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Mon, May 4, 2015 at 1:19 PM, Simon Taylor <span dir="ltr" class=""><<a href="mailto:simontaylor1@ntlworld.com" target="_blank" class="">simontaylor1@ntlworld.com</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi all,<br class="">
<br class="">
I’ve narrowed down a problem in my code to the following test case:<br class="">
<br class="">
- - - -<br class="">
<br class="">
typedef struct {float v[2];} vec2;<br class="">
typedef struct {float v[3];} vec3;<br class="">
<br class="">
vec2 getVec2();<br class="">
<br class="">
vec3 getVec3()<br class="">
{<br class="">
  vec2 myVec = getVec2();<br class="">
<br class="">
  vec3 res;<br class="">
  res.v[0] = myVec.v[0];<br class="">
  res.v[1] = myVec.v[1];<br class="">
  res.v[2] = 1;<br class="">
  return res;<br class="">
}<br class="">
<br class="">
- - - -<br class="">
<br class="">
Compiling this with any level of optimization for arm64 gives incorrect code, unless my test case above is triggering some undefined behaviour that I’m not aware of. Other architectures appear to work OK.<br class="">
<br class="">
$ clang -arch arm64 -O1 test.c -S -o -<br class="">
        .section        __TEXT,__text,regular,pure_instructions<br class="">
        .ios_version_min 5, 0<br class="">
        .globl  _getVec3<br class="">
        .align  2<br class="">
_getVec3:                               ; @getVec3<br class="">
; BB#0:<br class="">
        b       _getVec2<br class="">
<br class="">
<br class="">
.subsections_via_symbols<br class="">
<br class="">
- - - -<br class="">
<br class="">
I’m happy to file a bug for this, but not sure quite where it belongs - clang, LLVM or direct to Apple. Can someone test the top of tree and see if it suffers the same issue?<br class="">
<br class="">
I’m currently using the latest Xcode from Apple (clang -v gives “Apple LLVM version 6.1.0 (clang-602.0.49) (based on LLVM 3.6.0svn)”) but the LLVM 3.5-based compiler in the previous Xcode release also generates the same code.<br class="">
<br class="">
<br class="">
Simon<br class="">
<br class="">
<br class="">
_______________________________________________<br class="">
LLVM Developers mailing list<br class="">
<a href="mailto:LLVMdev@cs.uiuc.edu" class="">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu/" target="_blank" class="">http://llvm.cs.uiuc.edu</a><br class="">
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank" class="">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br class="">
</blockquote></div><br class=""></div>
</div></blockquote></div><br class=""></body></html>