Skip to content

Commit

Permalink
optimize identity splat of a tuple, (t...,) (JuliaLang#30571)
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Jan 4, 2019
1 parent 0b7f689 commit a153fea
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions base/compiler/ssair/inlining.jl
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,12 @@ function assemble_inline_todo!(ir::IRCode, linetable::Vector{LineInfoNode}, sv::
# Independent of whether we can inline, the above analysis allows us to rewrite
# this apply call to a regular call
ft = atypes[2]
if length(atypes) == 3 && ft isa Const && ft.val === Core.tuple && atypes[3] Tuple
# rewrite `((t::Tuple)...,)` to `t`
ir.stmts[idx] = stmt.args[3]
ok = false
break
end
stmt.args, atypes = rewrite_apply_exprargs!(ir, idx, stmt.args, atypes, sv)
ok = !has_free_typevars(ft)
ok || break
Expand Down
3 changes: 3 additions & 0 deletions src/builtins.c
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,9 @@ JL_CALLABLE(jl_f__apply)
return (jl_value_t*)t;
}
}
else if (f == jl_builtin_tuple && jl_is_tuple(args[1])) {
return args[1];
}
}
size_t n=0, i, j;
for(i=1; i < nargs; i++) {
Expand Down
3 changes: 3 additions & 0 deletions test/compiler/inline.jl
Original file line number Diff line number Diff line change
Expand Up @@ -217,3 +217,6 @@ function f_div(x, y)
return x
end
@test length(code_typed(f_div, (Int, Int))[1][1].code) > 1

f_identity_splat(t) = (t...,)
@test length(code_typed(f_identity_splat, (Tuple{Int,Int},))[1][1].code) == 1

0 comments on commit a153fea

Please sign in to comment.