Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code generation failure on expression involving Tuples of length > 2 (regression in 0.4-dev) #12163

Closed
samuelpowell opened this issue Jul 15, 2015 · 11 comments
Labels
bug Indicates an unexpected problem or unintended behavior compiler:codegen Generation of LLVM IR and native code priority This should be addressed urgently regression Regression in behavior compared to a previous version

Comments

@samuelpowell
Copy link
Member

The following works as expected:

stup = (-6.3, 100.3)
stupfloor(tup::Tuple) = floor(tup[1]), floor(tup[2])
stupfloor(stup)
(-7.0,100.0)

However increasing the length of the tuple beyond two elements results in abnormal behaviour:

ltup = (-6.3, 100.3, -6.8, 19.6)
ltupfloor(tup::Tuple) = floor(tup[1]), floor(tup[2]), floor(tup[3]), floor(tup[4])
ltupfloor(ltup)
(19.0,6.500476771537064e252,NaN,NaN)

Evaluating in the global scope works correctly:

floor(tup[1]), floor(tup[2]), floor(tup[3]), floor(tup[4])
(-7.0,100.0,-7.0,19.0)

In the failing cases, Julia appears simply to move some data around to jump somewhere:

    .text
Filename: In[2]
Source line: 2
    pushq   %rbp
    movq    %rsp, %rbp
Source line: 2
`   movsd   24(%rdi), %xmm0
    movabsq $139740990100656, %rax  # imm = 0x7F17FC1354B0
    popq    %rbp
    jmpq    *%rax

Everything works correctly under 0.3.9.

I have encountered this error on the following builds of 0.4-dev

Julia Version 0.4.0-dev+5933
Commit b2528a6* (2015-07-12 17:39 UTC)
Platform Info:
  System: Darwin (x86_64-apple-darwin13.4.0)
  CPU: Intel(R) Core(TM) i5-4670 CPU @ 3.40GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Haswell)
  LAPACK: libopenblas
  LIBM: libopenlibm
  LLVM: libLLVM-3.3
Julia Version 0.4.0-dev+5491
Commit cb77503 (2015-06-21 09:45 UTC)
Platform Info:
  System: Linux (x86_64-unknown-linux-gnu)
  CPU: Intel(R) Xeon(R) CPU E5-2670 v2 @ 2.50GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Sandybridge)
  LAPACK: libopenblas
  LIBM: libopenlibm
  LLVM: libLLVM-3.3
@yuyichao
Copy link
Contributor

Hmm, I could't reproduce on 0.4-dev on two different machines with LLVM-3.3 or LLVM-3.6.

@samuelpowell
Copy link
Member Author

@yuyichao, one can reproduce in Juliabox.

@simonster simonster added bug Indicates an unexpected problem or unintended behavior compiler:codegen Generation of LLVM IR and native code regression Regression in behavior compared to a previous version labels Jul 15, 2015
@yuyichao
Copy link
Contributor

@samuelpowell Yeah, that's true.

Somehow the llvm IR looks correct but the assembly looks wrong?

@JeffBezanson
Copy link
Member

Looks very similar to #8932

@yuyichao
Copy link
Contributor

So LLVM optimized too much after #10380 ?

@vtjnash
Copy link
Member

vtjnash commented Jul 15, 2015

code_native on a machine that gave the right answer:

    .section    __TEXT,__text,regular,pure_instructions
Filename: none
Source line: 1
    pushq   %rbp
    movq    %rsp, %rbp
Source line: 1
    vmovsd  24(%rdi), %xmm0
    vroundsd    $1, %xmm0, %xmm0, %xmm0
    vmovsd  %xmm0, -8(%rbp)
    vmovsd  16(%rdi), %xmm0
    vroundsd    $1, %xmm0, %xmm0, %xmm0
    vmovsd  %xmm0, -16(%rbp)
    vmovsd  (%rdi), %xmm0
    vmovsd  8(%rdi), %xmm1
    vroundsd    $1, %xmm0, %xmm0, %xmm0
    vroundsd    $1, %xmm1, %xmm0, %xmm1
    fldl    -8(%rbp)
    fldl    -16(%rbp)
    popq    %rbp
    ret

juliabox:


    .text
Filename: In[1]
Source line: 2
    pushq   %rbp
    movq    %rsp, %rbp
Source line: 2
    movsd   24(%rdi), %xmm0
    movabsq $140148947293360, %rax  # imm = 0x7F76F83814B0
    popq    %rbp
    jmpq    *%rax

@carnaval
Copy link
Contributor

Isn't this just a (far) tail call ? Would be interesting to know where it goes.

@samuelpowell
Copy link
Member Author

The jump location appears to be unstable. In one instance it seems to try to call sincos...

@code_native ltupfloor(ltup)
    .section    __TEXT,__text,regular,pure_instructions
Filename: none
Source line: 1
    pushq   %rbp
    movq    %rsp, %rbp
Source line: 1
    movsd   24(%rdi), %xmm0
    movabsq $__sincospi, %rax
    popq    %rbp
    jmpq    *%rax

@samuelpowell
Copy link
Member Author

Works fine on an old build of 0.4-dev under what was then llvm-svn

Julia Version 0.4.0-dev+5312
Commit 47f697b (2015-06-11 07:05 UTC)
Platform Info:
  System: Darwin (x86_64-apple-darwin14.3.0)
  CPU: Intel(R) Core(TM) i5-4670 CPU @ 3.40GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Haswell)
  LAPACK: libopenblas
  LIBM: libopenlibm
  LLVM: libLLVM-svn

@vtjnash
Copy link
Member

vtjnash commented Sep 16, 2015

possibly the same as #7434 also

@JeffBezanson
Copy link
Member

Also possible (fingers crossed!) it could be behind #12899 and #10908.

vtjnash added a commit that referenced this issue Sep 17, 2015
it seems that the llvm 3.3 return type legalizer may not be properly
handling large types. this is more efficient anyways.

fixes #8932, should fix #12163, probably fixes #7434

(cherry picked from commit 13c83db)
vtjnash added a commit that referenced this issue Sep 17, 2015
it seems that the llvm 3.3 return type legalizer may not be properly
handling large types. this is more efficient anyways.

fixes #8932, should fix #12163, probably fixes #7434

(cherry picked from commit 13c83db)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior compiler:codegen Generation of LLVM IR and native code priority This should be addressed urgently regression Regression in behavior compared to a previous version
Projects
None yet
Development

No branches or pull requests

6 participants