[LLVMdev] Incorrect code generated for arm64

Bruce Hoult bruce at hoult.org
Mon May 4 05:18:30 PDT 2015


I can confirm that, with Apple LLVM version 6.0 (clang-600.0.56) (based on
LLVM 3.5svn)

Very strange!

I don't know if it helps you, but this looks correct:

typedef struct {float v0, v1;} vec2;
typedef struct {float v0, v1, v2;} vec3;

vec2 getVec2();

vec3 getVec3()
{
  vec2 myVec = getVec2();

  vec3 res;
  res.v0 = myVec.v0;
  res.v1 = myVec.v1;
  res.v2 = 1;
  return res;
}

.section __TEXT,__text,regular,pure_instructions
.globl _getVec3
.align 2
_getVec3:                               ; @getVec3
; BB#0:
stp fp, lr, [sp, #-16]!
mov fp, sp
bl _getVec2
fmov s2, #1.000000e+00
ldp fp, lr, [sp], #16
ret


On Mon, May 4, 2015 at 1:19 PM, Simon Taylor <simontaylor1 at ntlworld.com>
wrote:

> Hi all,
>
> I’ve narrowed down a problem in my code to the following test case:
>
> - - - -
>
> typedef struct {float v[2];} vec2;
> typedef struct {float v[3];} vec3;
>
> vec2 getVec2();
>
> vec3 getVec3()
> {
>   vec2 myVec = getVec2();
>
>   vec3 res;
>   res.v[0] = myVec.v[0];
>   res.v[1] = myVec.v[1];
>   res.v[2] = 1;
>   return res;
> }
>
> - - - -
>
> 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.
>
> $ clang -arch arm64 -O1 test.c -S -o -
>         .section        __TEXT,__text,regular,pure_instructions
>         .ios_version_min 5, 0
>         .globl  _getVec3
>         .align  2
> _getVec3:                               ; @getVec3
> ; BB#0:
>         b       _getVec2
>
>
> .subsections_via_symbols
>
> - - - -
>
> 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?
>
> 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.
>
>
> Simon
>
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150504/b670a75d/attachment.html>


More information about the llvm-dev mailing list