Skip to content

Wrong GEP emission for tuple containing VecElement #32414

@chriselrod

Description

@chriselrod
julia> @noinline function foo(a)
           v = ntuple(Val(8)) do w Core.VecElement(Float64(10w)) end
           a, (v, (a,(1e6,1e9)))
       end
foo (generic function with 1 method)

julia> foo(-35.0)
(10.0, ((VecElement{Float64}(30.0), VecElement{Float64}(40.0), VecElement{Float64}(50.0), VecElement{Float64}(60.0), VecElement{Float64}(70.0), VecElement{Float64}(80.0), VecElement{Float64}(-35.0), VecElement{Float64}(1.0e6)), (1.0e9, (1.2353556789225747e-307, 6.9513596813479e-310))))

julia> versioninfo()
Julia Version 1.3.0-DEV.428
Commit 863e03fbb1* (2019-06-19 15:07 UTC)
Platform Info:
  OS: Linux (x86_64-generic-linux)
  CPU: Intel(R) Core(TM) i9-7900X CPU @ 3.30GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-8.0.0 (ORCJIT, skylake)

The answer should be:

(-35.0, ((VecElement{Float64}(10.0), VecElement{Float64}(20.0), VecElement{Float64}(30.0), VecElement{Float64}(40.0), VecElement{Float64}(50.0), VecElement{Float64}(60.0), VecElement{Float64}(70.0), VecElement{Float64}(80.0), VecElement{Float64}(-35.0), VecElement{Float64}(1.0e6)), (-35.0, (1.0e6, 1.0e9))))

That is, the incorrect answer we received is shifted to the left by 16 bytes, and there appears to be an 8-byte gap between the first float and the following vector.

If we replace the tuple of VecElements with a standard tuple, that is what we get:

julia> @noinline function bar(a)
           v = ntuple(Val(8)) do w Float64(10w) end
           a, (v, (a,(1e6,1e9)))
       end
bar (generic function with 1 method)

julia> bar(-35.0)
(-35.0, ((10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0, 80.0), (-35.0, (1.0e6, 1.0e9))))

This silently corrupts data -- not the easiest problem to track down!

I referenced the issue here, where vtjnash said:

Seems like a new issue: it looks like we're specifying the wrong sort of vector to LLVM for our desired alignment for Julia.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIndicates an unexpected problem or unintended behaviorcompiler:codegenGeneration of LLVM IR and native codecompiler:simdinstruction-level vectorization

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions