{"action":"created","issue":{"url":"https://api.github.com/repos/JuliaLang/julia/issues/18857","repository_url":"https://api.github.com/repos/JuliaLang/julia","labels_url":"https://api.github.com/repos/JuliaLang/julia/issues/18857/labels{/name}","comments_url":"https://api.github.com/repos/JuliaLang/julia/issues/18857/comments","events_url":"https://api.github.com/repos/JuliaLang/julia/issues/18857/events","html_url":"https://github.com/JuliaLang/julia/issues/18857","id":181918639,"number":18857,"title":"Nested VecElement structures generate bulky code","user":{"login":"dbeach24","id":11604259,"avatar_url":"https://avatars.githubusercontent.com/u/11604259?v=3","gravatar_id":"","url":"https://api.github.com/users/dbeach24","html_url":"https://github.com/dbeach24","followers_url":"https://api.github.com/users/dbeach24/followers","following_url":"https://api.github.com/users/dbeach24/following{/other_user}","gists_url":"https://api.github.com/users/dbeach24/gists{/gist_id}","starred_url":"https://api.github.com/users/dbeach24/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dbeach24/subscriptions","organizations_url":"https://api.github.com/users/dbeach24/orgs","repos_url":"https://api.github.com/users/dbeach24/repos","events_url":"https://api.github.com/users/dbeach24/events{/privacy}","received_events_url":"https://api.github.com/users/dbeach24/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/JuliaLang/julia/labels/codegen","name":"codegen","color":"d4c5f9"},{"url":"https://api.github.com/repos/JuliaLang/julia/labels/needs%20more%20info","name":"needs more info","color":"e0d5f0"},{"url":"https://api.github.com/repos/JuliaLang/julia/labels/won't%20fix","name":"won't fix","color":"e10c02"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":11,"created_at":"2016-10-09T23:14:49Z","updated_at":"2016-10-10T04:06:03Z","closed_at":null,"body":"Julia 0.5.0 generates inefficient LLVM code when tuples of `VecElement` are composed within other tuples or immutable types.  This is problematic, for example, when trying to leverage SIMD within a dual numbers implementation.\r\n\r\nSuppose we define a simple dual number structure as follows:\r\n\r\n```jl\r\nimmutable Dual{T <: Real} <: Real\r\n    val::T\r\n    partials::NTuple{3,T}\r\nend\r\n```\r\n\r\nand a similar `SIMDDual` type as follows:\r\n\r\n```jl\r\nimmutable SIMDDual{T <: Real} <: Real\r\n    val::T\r\n    partials::NTuple{3,VecElement{T}}\r\nend\r\n```\r\n\r\nFor each of these, `+` is defined by adding the corresponding `val` and `partials` elements.  (See attached code.)\r\n\r\nUsing the above, let's define some dual numbers as follows:\r\n\r\n```jl\r\nconst r = Dual{Float64}(1., (1., 2., 3.))\r\nconst s = SIMDDual{Float64}(1.,\r\n    (VecElement(1.), VecElement(2.), VecElement(3.)))\r\n\r\n# compositions of dual numbers\r\n# these are the sorts of structures you would use to compute 2nd derivatives\r\nconst a = Dual{Dual{Float64}}(r, (r, r, r))\r\nconst b = SIMDDual{SIMDDual{Float64}}(s, (s, s, s))\r\nconst c = Dual{SIMDDual{Float64}}(s, (s, s, s))\r\n```\r\n\r\nWhen evaluating these codes:\r\n- `@code_llvm a+a` => 117 lines\r\n- `@code_llvm b+b` => 151 lines\r\n- `@code_llvm c+c` => 151 lines\r\n\r\nSee attached script and output files:\r\n- [simdcheck.jl.txt](https://github.com/JuliaLang/julia/files/518693/simdcheck.jl.txt)\r\n- [a.txt](https://github.com/JuliaLang/julia/files/518694/a.txt)\r\n- [b.txt](https://github.com/JuliaLang/julia/files/518695/b.txt)\r\n- [c.txt](https://github.com/JuliaLang/julia/files/518696/c.txt)\r\n\r\nThe point here is to show that merely adding the `VecElement` wrapper increases the number of instructions. \r\n\r\nI know I can't expect to get SIMD instructions automatically from the compiler here; *that's not the issue*.  The problem is that merely using the `VecElement` wrapper causes code to be generated that is far more bulky.\r\n\r\nWhy is this happening?  Can it be fixed?\r\n\r\nSee also: JuliaDiff/ForwardDiff.jl#98\r\n\r\nEDIT:  Updated to fix a bug in the example code and for corrected line counts.\r\n"},"comment":{"url":"https://api.github.com/repos/JuliaLang/julia/issues/comments/252535256","html_url":"https://github.com/JuliaLang/julia/issues/18857#issuecomment-252535256","issue_url":"https://api.github.com/repos/JuliaLang/julia/issues/18857","id":252535256,"user":{"login":"dbeach24","id":11604259,"avatar_url":"https://avatars.githubusercontent.com/u/11604259?v=3","gravatar_id":"","url":"https://api.github.com/users/dbeach24","html_url":"https://github.com/dbeach24","followers_url":"https://api.github.com/users/dbeach24/followers","following_url":"https://api.github.com/users/dbeach24/following{/other_user}","gists_url":"https://api.github.com/users/dbeach24/gists{/gist_id}","starred_url":"https://api.github.com/users/dbeach24/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dbeach24/subscriptions","organizations_url":"https://api.github.com/users/dbeach24/orgs","repos_url":"https://api.github.com/users/dbeach24/repos","events_url":"https://api.github.com/users/dbeach24/events{/privacy}","received_events_url":"https://api.github.com/users/dbeach24/received_events","type":"User","site_admin":false},"created_at":"2016-10-10T04:06:03Z","updated_at":"2016-10-10T04:06:03Z","body":"@yuyichao Thank you.  Your last comment, in particular, addresses the essence of what I'm trying to understand."}}
{"actor":{"display_login":"dbeach24"}}