Skip to content

Commit

Permalink
Undo change that dropped const-propped information
Browse files Browse the repository at this point in the history
This PR included a change that only used constant results if the
result was *better*. However, this is not what we want, because
even though the result may have been the same, the IR we computed
will likely still have more precise (and fewer) statements, because
we optimized a bunch of things away based on constant information.
  • Loading branch information
Keno committed Nov 19, 2023
1 parent adff8e7 commit fdfc6e4
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions base/compiler/abstractinterpretation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function abstract_call_gf_by_type(interp::AbstractInterpreter, @nospecialize(f),
result, f, this_arginfo, si, match, sv)
const_result = volatile_inf_result
if const_call_result !== nothing
if !(rt const_call_result.rt)
if const_call_result.rt rt
rt = const_call_result.rt
exct = const_call_result.exct
(; effects, const_result, edge) = const_call_result
Expand All @@ -76,7 +76,7 @@ function abstract_call_gf_by_type(interp::AbstractInterpreter, @nospecialize(f),
(; effects, const_result, edge) = const_call_result
elseif !(exct ₚ const_call_result.exct)
exct = const_call_result.exct
(; effects, const_result, edge) = const_call_result
(; const_result, edge) = const_call_result
else
add_remark!(interp, sv, "[constprop] Discarded because the result was wider than inference")
end
Expand Down Expand Up @@ -113,9 +113,14 @@ function abstract_call_gf_by_type(interp::AbstractInterpreter, @nospecialize(f),
if const_call_result !== nothing
this_const_conditional = ignorelimited(const_call_result.rt)
this_const_rt = widenwrappedconditional(const_call_result.rt)
# return type of const-prop' inference can be wider than that of non const-prop' inference
# e.g. in cases when there are cycles but cached result is still accurate
if !(this_rt ₚ this_const_rt)
if this_const_rt ₚ this_rt
# As long as the const-prop result we have is not *worse* than
# what we found out on types, we'd like to use it. Even if the
# end result is exactly equivalent, it is likely that the IR
# we produced while constproping is better than that with
# generic types.
# Return type of const-prop' inference can be wider than that of non const-prop' inference
# e.g. in cases when there are cycles but cached result is still accurate
this_conditional = this_const_conditional
this_rt = this_const_rt
this_exct = const_call_result.exct
Expand All @@ -125,7 +130,7 @@ function abstract_call_gf_by_type(interp::AbstractInterpreter, @nospecialize(f),
(; effects, const_result, edge) = const_call_result
elseif !(this_exct ₚ const_call_result.exct)
this_exct = const_call_result.exct
(; effects, const_result, edge) = const_call_result
(; const_result, edge) = const_call_result
else
add_remark!(interp, sv, "[constprop] Discarded because the result was wider than inference")
end
Expand Down

0 comments on commit fdfc6e4

Please sign in to comment.