Skip to content

Commit 350c774

Browse files
JeffBezansonAmit Shirodkar
authored andcommitted
some inlining cost model updates (JuliaLang#35235)
- treat arrayset like arrayref - add small cost for typeof
1 parent 8c98647 commit 350c774

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

base/compiler/optimize.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -355,20 +355,22 @@ function statement_cost(ex::Expr, line::Int, src::Union{CodeInfo, IRCode}, sptyp
355355
# tuple iteration/destructuring makes that impossible
356356
# return plus_saturate(argcost, isknowntype(extyp) ? 1 : params.inline_nonleaf_penalty)
357357
return 0
358+
elseif (f === Core.arrayref || f === Core.const_arrayref || f === Core.arrayset) && length(ex.args) >= 3
359+
atyp = argextype(ex.args[3], src, sptypes, slottypes)
360+
return isknowntype(atyp) ? 4 : error_path ? params.inline_error_path_cost : params.inline_nonleaf_penalty
361+
elseif f === typeassert && isconstType(widenconst(argextype(ex.args[3], src, sptypes, slottypes)))
362+
return 1
358363
elseif f === Core.isa
359364
# If we're in a union context, we penalize type computations
360365
# on union types. In such cases, it is usually better to perform
361366
# union splitting on the outside.
362367
if union_penalties && isa(argextype(ex.args[2], src, sptypes, slottypes), Union)
363368
return params.inline_nonleaf_penalty
364369
end
365-
elseif (f === Core.arrayref || f === Core.const_arrayref) && length(ex.args) >= 3
366-
atyp = argextype(ex.args[3], src, sptypes, slottypes)
367-
return isknowntype(atyp) ? 4 : error_path ? params.inline_error_path_cost : params.inline_nonleaf_penalty
368370
end
369371
fidx = find_tfunc(f)
370372
if fidx === nothing
371-
# unknown/unhandled builtin or anonymous function
373+
# unknown/unhandled builtin
372374
# Use the generic cost of a direct function call
373375
return 20
374376
end

base/compiler/tfuncs.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ function typeof_tfunc(@nospecialize(t))
550550
end
551551
return DataType # typeof(anything)::DataType
552552
end
553-
add_tfunc(typeof, 1, 1, typeof_tfunc, 0)
553+
add_tfunc(typeof, 1, 1, typeof_tfunc, 1)
554554

555555
function typeassert_tfunc(@nospecialize(v), @nospecialize(t))
556556
t = instanceof_tfunc(t)[1]

0 commit comments

Comments
 (0)