From 84298cba7b0bdf740e13c9f3c0fc729f45baafb3 Mon Sep 17 00:00:00 2001 From: Keno Fischer Date: Mon, 16 Apr 2018 16:30:38 -0400 Subject: [PATCH] [NewOptimizer] Fix _apply elision 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. --- base/compiler/ssair/inlining2.jl | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/base/compiler/ssair/inlining2.jl b/base/compiler/ssair/inlining2.jl index bf9b177a9e4fa..f24a14715c5e6 100644 --- a/base/compiler/ssair/inlining2.jl +++ b/base/compiler/ssair/inlining2.jl @@ -309,14 +309,22 @@ function maybe_make_invoke!(ir::IRCode, idx::Int, @nospecialize(etype), atypes:: @nospecialize(atype_unlimited), isinvoke::Bool, isapply::Bool, @nospecialize(invoke_data)) nu = countunionsplit(atypes) nu > 1 && return # TODO: The old optimizer did union splitting here. Is this the right place? - ex = Expr(:invoke) linfo = spec_lambda(atype_unlimited, sv, invoke_data) - linfo === nothing && return - add_backedge!(linfo, sv) + if linfo === nothing + if !isapply || isinvoke + return + end + # We might not have an linfo, but we can still rewrite the _apply into a regular call + # based on our analysis + ex = Expr(:call) + else + ex = Expr(:invoke) + add_backedge!(linfo, sv) + end argexprs = ir[SSAValue(idx)].args argexprs = rewrite_exprargs((node, typ)->insert_node!(ir, idx, typ, node), arg->exprtype(arg, ir, ir.mod), isinvoke, isapply, argexprs) - pushfirst!(argexprs, linfo) + linfo !== nothing && pushfirst!(argexprs, linfo) ex.typ = etype ex.args = argexprs ir[SSAValue(idx)] = ex @@ -466,7 +474,6 @@ function assemble_inline_todo!(ir::IRCode, linetable::Vector{LineInfoNode}, sv:: methsp = methsp::SimpleVector end - methsig = method.sig if !(atype <: metharg) maybe_make_invoke!(ir, idx, stmt.typ, atypes, sv, atype_unlimited, isinvoke, isapply, invoke_data)