Skip to content

Commit

Permalink
Merge pull request #42805 from JuliaLang/avi/backport-42766
Browse files Browse the repository at this point in the history
backport #42766 into `backports-release-1.7`
  • Loading branch information
aviatesk authored Oct 27, 2021
2 parents 069861a + c22889e commit f662b0a
Show file tree
Hide file tree
Showing 3 changed files with 319 additions and 149 deletions.
29 changes: 22 additions & 7 deletions base/compiler/abstractinterpretation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -568,17 +568,27 @@ end
function maybe_get_const_prop_profitable(interp::AbstractInterpreter, result::MethodCallResult,
@nospecialize(f), argtypes::Vector{Any}, match::MethodMatch,
sv::InferenceState)
const_prop_entry_heuristic(interp, result, sv) || return nothing
if !InferenceParams(interp).ipo_constant_propagation
add_remark!(interp, sv, "[constprop] Disabled by parameter")
return nothing
end
method = match.method
force = force_const_prop(interp, f, method)
force || const_prop_entry_heuristic(interp, result, sv) || return nothing
nargs::Int = method.nargs
method.isva && (nargs -= 1)
if length(argtypes) < nargs
length(argtypes) < nargs && return nothing
if !(const_prop_argument_heuristic(interp, argtypes) || const_prop_rettype_heuristic(interp, result.rt))
add_remark!(interp, sv, "[constprop] Disabled by argument and rettype heuristics")
return nothing
end
const_prop_argument_heuristic(interp, argtypes) || const_prop_rettype_heuristic(interp, result.rt) || return nothing
allconst = is_allconst(argtypes)
force = force_const_prop(interp, f, method)
force || const_prop_function_heuristic(interp, f, argtypes, nargs, allconst) || return nothing
if !force
if !const_prop_function_heuristic(interp, f, argtypes, nargs, allconst)
add_remark!(interp, sv, "[constprop] Disabled by function heuristic")
return nothing
end
end
force |= allconst
mi = specialize_method(match, !force)
if mi === nothing
Expand All @@ -594,8 +604,13 @@ function maybe_get_const_prop_profitable(interp::AbstractInterpreter, result::Me
end

function const_prop_entry_heuristic(interp::AbstractInterpreter, result::MethodCallResult, sv::InferenceState)
call_result_unused(sv) && result.edgecycle && return false
return is_improvable(result.rt) && InferenceParams(interp).ipo_constant_propagation
if call_result_unused(sv) && result.edgecycle
add_remark!(interp, sv, "[constprop] Disabled by entry heuristic (edgecycle with unused result)")
return false
end
is_improvable(result.rt) && return true
add_remark!(interp, sv, "[constprop] Disabled by entry heuristic (unimprovable return type)")
return false
end

# see if propagating constants may be worthwhile
Expand Down
Loading

0 comments on commit f662b0a

Please sign in to comment.