Skip to content

Commit fdfc6e4

Browse files
committed
Undo change that dropped const-propped information
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.
1 parent adff8e7 commit fdfc6e4

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

base/compiler/abstractinterpretation.jl

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ function abstract_call_gf_by_type(interp::AbstractInterpreter, @nospecialize(f),
6767
result, f, this_arginfo, si, match, sv)
6868
const_result = volatile_inf_result
6969
if const_call_result !== nothing
70-
if !(rt const_call_result.rt)
70+
if const_call_result.rt rt
7171
rt = const_call_result.rt
7272
exct = const_call_result.exct
7373
(; effects, const_result, edge) = const_call_result
@@ -76,7 +76,7 @@ function abstract_call_gf_by_type(interp::AbstractInterpreter, @nospecialize(f),
7676
(; effects, const_result, edge) = const_call_result
7777
elseif !(exct ₚ const_call_result.exct)
7878
exct = const_call_result.exct
79-
(; effects, const_result, edge) = const_call_result
79+
(; const_result, edge) = const_call_result
8080
else
8181
add_remark!(interp, sv, "[constprop] Discarded because the result was wider than inference")
8282
end
@@ -113,9 +113,14 @@ function abstract_call_gf_by_type(interp::AbstractInterpreter, @nospecialize(f),
113113
if const_call_result !== nothing
114114
this_const_conditional = ignorelimited(const_call_result.rt)
115115
this_const_rt = widenwrappedconditional(const_call_result.rt)
116-
# return type of const-prop' inference can be wider than that of non const-prop' inference
117-
# e.g. in cases when there are cycles but cached result is still accurate
118-
if !(this_rt ₚ this_const_rt)
116+
if this_const_rt ₚ this_rt
117+
# As long as the const-prop result we have is not *worse* than
118+
# what we found out on types, we'd like to use it. Even if the
119+
# end result is exactly equivalent, it is likely that the IR
120+
# we produced while constproping is better than that with
121+
# generic types.
122+
# Return type of const-prop' inference can be wider than that of non const-prop' inference
123+
# e.g. in cases when there are cycles but cached result is still accurate
119124
this_conditional = this_const_conditional
120125
this_rt = this_const_rt
121126
this_exct = const_call_result.exct
@@ -125,7 +130,7 @@ function abstract_call_gf_by_type(interp::AbstractInterpreter, @nospecialize(f),
125130
(; effects, const_result, edge) = const_call_result
126131
elseif !(this_exct ₚ const_call_result.exct)
127132
this_exct = const_call_result.exct
128-
(; effects, const_result, edge) = const_call_result
133+
(; const_result, edge) = const_call_result
129134
else
130135
add_remark!(interp, sv, "[constprop] Discarded because the result was wider than inference")
131136
end

0 commit comments

Comments
 (0)