Ellide immutable allocation in some simple cases#15259
Conversation
|
Any way of testing that it stays this way? |
|
@tkelman yep, I'll write those About the 32 bit failure I'm trying to repro but apparently building a 32 bit version of julia is beyond me |
|
Something that initially confused me: "no allocations" means for the immutable wrapper, but the array output still gets allocation due to the call to Excited about this! |
|
Yep sorry that was unclear. This requires the compiler to see both the allocation and every usage (getfield) so it needs a lot of inlining. It is useful for example to get rid of overhead for small wrapper structs such as enumerate : julia> f(x) = (for (i,j) in enumerate(x); i; end)
f (generic function with 1 method)
julia> code_typed(f, (Vector{Int},))
1-element Array{Any,1}:
:($(Expr(:lambda, Any[symbol("#self#"),:x], Any[Any[Any[symbol("#self#"),#f,0],Any[:x,Array{Int64,1},0],Any[symbol("#s1"),Tuple{Int64,Int64},2],Any[:i,Int64,18],Any[:j,Int64,18],Any[symbol("#s2"),Int64,2],Any[symbol("##n#9276"),Tuple{Int64,Int64},18]],Any[],Any[Enumerate{Array{Int64,1}},Tuple{Tuple{Int64,Int64},Tuple{Int64,Int64}},Tuple{Int64,Int64},Tuple{Int64,Int64},Tuple{Int64,Int64},Int64,Int64,Int64,Array{Int64,1},Tuple{Int64,Int64},Tuple{Int64,Int64},Int64,Int64,Int64,Int64]], :(begin # none, line 1:
GenSym(8) = x::Array{Int64,1}
#s1 = (top(tuple))(1,1)::Tuple{Int64,Int64}
2:
unless (Base.box)(Base.Bool,(Base.not_int)(((Base.getfield)(#s1::Tuple{Int64,Int64},2)::Int64 === (Base.box)(Int64,(Base.add_int)((Base.arraylen)(GenSym(8))::Int64,1)))::Bool)) goto 1 # iterator.jl, line 15:
GenSym(5) = (Base.getfield)(#s1::Tuple{Int64,Int64},2)::Int64 # array.jl, line 234:
GenSym(6) = (Base.arrayref)(GenSym(8),GenSym(5))::Int64
GenSym(7) = (Base.box)(Int64,(Base.add_int)(GenSym(5),1)) # iterator.jl, line 16:
GenSym(9) = (top(tuple))((Base.getfield)(#s1::Tuple{Int64,Int64},1)::Int64,GenSym(6))::Tuple{Int64,Int64}
GenSym(10) = (top(tuple))((Base.box)(Int64,(Base.add_int)((Base.getfield)(#s1::Tuple{Int64,Int64},1)::Int64,1)),GenSym(7))::Tuple{Int64,Int64}
GenSym(2) = GenSym(9)
#s2 = 1
GenSym(11) = (Base.getfield)(GenSym(2),1)::Int64
GenSym(12) = (Base.box)(Int64,(Base.add_int)(1,1))
i = GenSym(11)
#s2 = GenSym(12)
GenSym(13) = (Base.getfield)(GenSym(2),2)::Int64
GenSym(14) = (Base.box)(Int64,(Base.add_int)(2,1))
j = GenSym(13)
#s2 = GenSym(14)
#s1 = GenSym(10) # none, line 1:
i::Int64
3:
goto 2
1:
0:
return
end::Void)))) |
|
The 32bit travis failure in the math test already shows up at least twice on master.. |
|
@simonbyrne I think you tweaked bessel in some way recently? |
|
Hopefully this should be fixed by #15272. Sorry about that. |
6ef3947 to
a7490f5
Compare
Extend tuple_elim_pass and getfield_elim_pass to handle immutable object allocations.
Ellide immutable allocation in some simple cases
Extend tuple_elim_pass and getfield_elim_pass to handle immutable object allocations.
@andreasnoack
no allocations