From c6c46b60658065d20f4e083a9d25214d381d9286 Mon Sep 17 00:00:00 2001 From: Jameson Nash Date: Wed, 10 Aug 2016 15:33:22 -0400 Subject: [PATCH 1/2] preserve functionality of special ^ inliner in linear IR --- base/inference.jl | 53 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 37 insertions(+), 16 deletions(-) diff --git a/base/inference.jl b/base/inference.jl index 4022da0726a60..cdbac8dc07792 100644 --- a/base/inference.jl +++ b/base/inference.jl @@ -2797,8 +2797,6 @@ function mk_tuplecall(args, sv::InferenceState) e end -const corenumtype = Union{Int32,Int64,Float32,Float64} - function inlining_pass!(linfo::LambdaInfo, sv::InferenceState) eargs = linfo.code i = 1 @@ -2819,6 +2817,8 @@ function inlining_pass!(linfo::LambdaInfo, sv::InferenceState) end end +const corenumtype = Union{Int32, Int64, Float32, Float64} + function inlining_pass(e::Expr, sv, linfo) if e.head === :method # avoid running the inlining pass on function definitions @@ -2908,20 +2908,41 @@ function inlining_pass(e::Expr, sv, linfo) end end - if sv.inlining && isdefined(Main, :Base) && - ((isdefined(Main.Base, :^) && is(f, Main.Base.:^)) || - (isdefined(Main.Base, :.^) && is(f, Main.Base.:.^))) - if length(e.args) == 3 && isa(e.args[3],Union{Int32,Int64}) - a1 = e.args[2] - basenumtype = Union{corenumtype, Main.Base.Complex64, Main.Base.Complex128, Main.Base.Rational} - if isa(a1,basenumtype) || ((isa(a1,Symbol) || isa(a1,Slot) || isa(a1,SSAValue)) && - exprtype(a1,sv) ⊑ basenumtype) - if e.args[3]==2 - e.args = Any[GlobalRef(Main.Base,:*), a1, a1] - f = Main.Base.:*; ft = abstract_eval_constant(f) - elseif e.args[3]==3 - e.args = Any[GlobalRef(Main.Base,:*), a1, a1, a1] - f = Main.Base.:*; ft = abstract_eval_constant(f) + if sv.inlining + if isdefined(Main, :Base) && + ((isdefined(Main.Base, :^) && is(f, Main.Base.:^)) || + (isdefined(Main.Base, :.^) && is(f, Main.Base.:.^))) && + length(e.args) == 3 + + a2 = e.args[3] + if isa(a2, Symbol) || isa(a2, Slot) || isa(a2, SSAValue) + ta2 = exprtype(a2, sv) + if isa(ta2, Const) + a2 = ta2.val + end + end + + square = (a2 === Int32(2) || a2 === Int64(2)) + triple = (a2 === Int32(3) || a2 === Int64(3)) + if square || triple + a1 = e.args[2] + basenumtype = Union{corenumtype, Main.Base.Complex64, Main.Base.Complex128, Main.Base.Rational} + if isa(a1, basenumtype) || ((isa(a1, Symbol) || isa(a1, Slot) || isa(a1, SSAValue)) && + exprtype(a1, sv) ⊑ basenumtype) + if square + e.args = Any[GlobalRef(Main.Base,:*), a1, a1] + res = inlining_pass(e, sv, linfo) + else + e.args = Any[GlobalRef(Main.Base,:*), Expr(:call, GlobalRef(Main.Base,:*), a1, a1), a1] + res = inlining_pass(e, sv, linfo) + end + if isa(res, Tuple) + if isa(res[2], Array) && !isempty(res[2]) + append!(stmts, res[2]) + end + res = res[1] + end + return (res, stmts) end end end From 19b1276eec40900ccf27ae2976fe9a6821b0668c Mon Sep 17 00:00:00 2001 From: Jameson Nash Date: Wed, 10 Aug 2016 15:56:19 -0400 Subject: [PATCH 2/2] add model of special case ^ inliner to inference edges required for the inliner to work, since all of the logic for computing edges is supposed to be handle by the inference step fix #17759 --- base/inference.jl | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/base/inference.jl b/base/inference.jl index cdbac8dc07792..350146c799c0d 100644 --- a/base/inference.jl +++ b/base/inference.jl @@ -1037,6 +1037,23 @@ function abstract_call(f::ANY, fargs, argtypes::Vector{Any}, vtypes::VarTable, s return Type end + if sv.inlining + # need to model the special inliner for ^ + # to ensure we have added the same edge + if isdefined(Main, :Base) && + ((isdefined(Main.Base, :^) && is(f, Main.Base.:^)) || + (isdefined(Main.Base, :.^) && is(f, Main.Base.:.^))) && + length(argtypes) == 3 && (argtypes[3] ⊑ Int32 || argtypes[3] ⊑ Int64) + + a1 = argtypes[2] + basenumtype = Union{corenumtype, Main.Base.Complex64, Main.Base.Complex128, Main.Base.Rational} + if a1 ⊑ basenumtype + ftimes = Main.Base.:* + ta1 = widenconst(a1) + abstract_call_gf_by_type(ftimes, Tuple{typeof(ftimes), ta1, ta1}, sv) + end + end + end return abstract_call_gf_by_type(f, atype, sv) end