Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions Compiler/src/typeinfer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -440,18 +440,20 @@ function inline_cost_model(interp::AbstractInterpreter, result::InferenceResult,
# compute the cost (size) of inlining this code
params = OptimizationParams(interp)
cost_threshold = default = params.inline_cost_threshold
if ⊑(optimizer_lattice(interp), rt, Tuple) && !isconcretetype(widenconst(rt))
cost_threshold += params.inline_tupleret_bonus
end
# if the method is declared as `@inline`, increase the cost threshold 20x
if declared_inline
cost_threshold += 19*default
end
# a few functions get special treatment
if def.module === _topmod(def.module)
name = def.name
if name === :iterate || name === :unsafe_convert || name === :cconvert
cost_threshold += 4*default
if cost_threshold != typemax(Int)
if ⊑(optimizer_lattice(interp), rt, Tuple) && !isconcretetype(widenconst(rt))
cost_threshold += params.inline_tupleret_bonus
end
# if the method is declared as `@inline`, increase the cost threshold 20x
if declared_inline
cost_threshold += 19*default
end
# a few functions get special treatment
if def.module === _topmod(def.module)
name = def.name
if name === :iterate || name === :unsafe_convert || name === :cconvert
cost_threshold += 4*default
end
end
end
return inline_cost_model(ir, params, cost_threshold)
Expand Down
9 changes: 9 additions & 0 deletions Compiler/test/inline.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2345,4 +2345,13 @@ let src = code_typed1(Base.setindex, (@NamedTuple{next::UInt32,prev::UInt32}, In
@test count(iscall((src, Base.merge_fallback)), src.code) == 0
end

f60121(t) = t[1]
let
interp = Compiler.NativeInterpreter(; opt_params=Compiler.OptimizationParams(; inline_cost_threshold=typemax(Int)))
res = Base.code_ircode(f60121, (Tuple{Tuple{Val{4}}, Tuple{Float32}},); interp)
@test !isempty(res)
ir, rt = only(res)
@test rt == Tuple{Val{4}}
end

end # module inline_tests