Skip to content

Commit

Permalink
inlining: Use tmeet for result of inserted PiNode
Browse files Browse the repository at this point in the history
For extended lattice elements, the type of the resulting PiNode can end
up imprecise when `tmeet(argextype(argex), mft) ⊑ mft`
  • Loading branch information
topolarity authored and aviatesk committed Apr 19, 2024
1 parent 7f8635f commit 99a6efc
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions base/compiler/ssair/inlining.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function ssa_inlining_pass!(ir::IRCode, state::InliningState, propagate_inbounds
@timeit "analysis" todo = assemble_inline_todo!(ir, state)
isempty(todo) && return ir
# Do the actual inlining for every call we identified
@timeit "execution" ir = batch_inline!(ir, todo, propagate_inbounds, OptimizationParams(state.interp))
@timeit "execution" ir = batch_inline!(ir, todo, propagate_inbounds, state.interp)
return ir
end

Expand Down Expand Up @@ -522,7 +522,7 @@ assuming their order stays the same post-discovery in `ml_matches`.
"""
function ir_inline_unionsplit!(compact::IncrementalCompact, idx::Int, argexprs::Vector{Any},
union_split::UnionSplit, boundscheck::Symbol,
todo_bbs::Vector{Tuple{Int,Int}}, params::OptimizationParams)
todo_bbs::Vector{Tuple{Int,Int}}, interp::AbstractInterpreter)
(; fully_covered, atype, cases, bbs) = union_split
stmt, typ, line = compact.result[idx][:stmt], compact.result[idx][:type], compact.result[idx][:line]
join_bb = bbs[end]
Expand Down Expand Up @@ -565,8 +565,10 @@ function ir_inline_unionsplit!(compact::IncrementalCompact, idx::Int, argexprs::
(isa(argex, SSAValue) || isa(argex, Argument)) || continue
aft, mft = fieldtype(atype, i), fieldtype(mtype, i)
if !(aft <: mft)
𝕃ₒ = optimizer_lattice(interp)
new_type = tmeet(𝕃ₒ, argextype(argex, compact), mft)
argexprs′[i] = insert_node_here!(compact,
NewInstruction(PiNode(argex, mft), mft, line))
NewInstruction(PiNode(argex, mft), new_type, line))
end
end
end
Expand Down Expand Up @@ -605,7 +607,8 @@ function ir_inline_unionsplit!(compact::IncrementalCompact, idx::Int, argexprs::
return insert_node_here!(compact, NewInstruction(pn, typ, line))
end

function batch_inline!(ir::IRCode, todo::Vector{Pair{Int,Any}}, propagate_inbounds::Bool, params::OptimizationParams)
function batch_inline!(ir::IRCode, todo::Vector{Pair{Int,Any}}, propagate_inbounds::Bool, interp::AbstractInterpreter)
params = OptimizationParams(interp)
# Compute the new CFG first (modulo statement ranges, which will be computed below)
state = CFGInliningState(ir)
for (idx, item) in todo
Expand Down Expand Up @@ -662,7 +665,7 @@ function batch_inline!(ir::IRCode, todo::Vector{Pair{Int,Any}}, propagate_inboun
if isa(item, InliningTodo)
compact.ssa_rename[old_idx] = ir_inline_item!(compact, idx, argexprs, item, boundscheck, state.todo_bbs)
elseif isa(item, UnionSplit)
compact.ssa_rename[old_idx] = ir_inline_unionsplit!(compact, idx, argexprs, item, boundscheck, state.todo_bbs, params)
compact.ssa_rename[old_idx] = ir_inline_unionsplit!(compact, idx, argexprs, item, boundscheck, state.todo_bbs, interp)
end
compact[idx] = nothing
refinish && finish_current_bb!(compact, 0)
Expand Down

0 comments on commit 99a6efc

Please sign in to comment.