Skip to content

Commit 8e7034e

Browse files
KenoJeffBezanson
authored andcommitted
[NewOptimizer] Fix _apply elision (#26821)
The old optimizer had an extra loop outside the inlining pass that would turn _apply's in to regular calls. When I wrote the new inliner we discussed that this wasn't actually necessary because we could just keep track of this information in the inliner (as we do for invoke). However, that of course also means that if we can't turn something into an :invoke, we should still at least turn it into a regular call. Do that.
1 parent 8ab44ca commit 8e7034e

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

base/compiler/ssair/inlining2.jl

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -309,14 +309,22 @@ function maybe_make_invoke!(ir::IRCode, idx::Int, @nospecialize(etype), atypes::
309309
@nospecialize(atype_unlimited), isinvoke::Bool, isapply::Bool, @nospecialize(invoke_data))
310310
nu = countunionsplit(atypes)
311311
nu > 1 && return # TODO: The old optimizer did union splitting here. Is this the right place?
312-
ex = Expr(:invoke)
313312
linfo = spec_lambda(atype_unlimited, sv, invoke_data)
314-
linfo === nothing && return
315-
add_backedge!(linfo, sv)
313+
if linfo === nothing
314+
if !isapply || isinvoke
315+
return
316+
end
317+
# We might not have an linfo, but we can still rewrite the _apply into a regular call
318+
# based on our analysis
319+
ex = Expr(:call)
320+
else
321+
ex = Expr(:invoke)
322+
add_backedge!(linfo, sv)
323+
end
316324
argexprs = ir[SSAValue(idx)].args
317325
argexprs = rewrite_exprargs((node, typ)->insert_node!(ir, idx, typ, node), arg->exprtype(arg, ir, ir.mod),
318326
isinvoke, isapply, argexprs)
319-
pushfirst!(argexprs, linfo)
327+
linfo !== nothing && pushfirst!(argexprs, linfo)
320328
ex.typ = etype
321329
ex.args = argexprs
322330
ir[SSAValue(idx)] = ex
@@ -466,7 +474,6 @@ function assemble_inline_todo!(ir::IRCode, linetable::Vector{LineInfoNode}, sv::
466474
methsp = methsp::SimpleVector
467475
end
468476

469-
470477
methsig = method.sig
471478
if !(atype <: metharg)
472479
maybe_make_invoke!(ir, idx, stmt.typ, atypes, sv, atype_unlimited, isinvoke, isapply, invoke_data)

0 commit comments

Comments
 (0)