785
785
function abstract_call_method_with_const_args (interp:: AbstractInterpreter ,
786
786
result:: MethodCallResult , @nospecialize (f), arginfo:: ArgInfo , si:: StmtInfo ,
787
787
match:: MethodMatch , sv:: AbsIntState , invokecall:: Union{Nothing,InvokeCall} = nothing )
788
- if ! const_prop_enabled (interp, sv, match)
789
- return nothing
790
- end
791
- if bail_out_const_call (interp, result, si)
792
- add_remark! (interp, sv, " [constprop] No more information to be gained" )
788
+ if ! const_prop_enabled (interp, match, sv) || bail_out_const_call (interp, result, si, sv)
793
789
return nothing
794
790
end
795
791
eligibility = concrete_eval_eligible (interp, f, result, arginfo, sv)
@@ -822,7 +818,7 @@ function abstract_call_method_with_const_args(interp::AbstractInterpreter,
822
818
return const_prop_call (interp, mi, result, arginfo, sv, concrete_eval_result)
823
819
end
824
820
825
- function const_prop_enabled (interp:: AbstractInterpreter , sv :: AbsIntState , match :: MethodMatch )
821
+ function const_prop_enabled (interp:: AbstractInterpreter , match :: MethodMatch , sv :: AbsIntState )
826
822
if ! InferenceParams (interp). ipo_constant_propagation
827
823
add_remark! (interp, sv, " [constprop] Disabled by parameter" )
828
824
return false
@@ -834,9 +830,11 @@ function const_prop_enabled(interp::AbstractInterpreter, sv::AbsIntState, match:
834
830
return true
835
831
end
836
832
837
- function bail_out_const_call (interp:: AbstractInterpreter , result:: MethodCallResult , si:: StmtInfo )
833
+ function bail_out_const_call (interp:: AbstractInterpreter , result:: MethodCallResult ,
834
+ si:: StmtInfo , sv:: AbsIntState )
838
835
if is_removable_if_unused (result. effects)
839
836
if isa (result. rt, Const) || call_result_unused (si)
837
+ add_remark! (interp, sv, " [constprop] No more information to be gained (const)" )
840
838
return true
841
839
end
842
840
end
@@ -937,7 +935,10 @@ function maybe_get_const_prop_profitable(interp::AbstractInterpreter,
937
935
match:: MethodMatch , sv:: AbsIntState )
938
936
method = match. method
939
937
force = force_const_prop (interp, f, method)
940
- force || const_prop_entry_heuristic (interp, result, si, sv) || return nothing
938
+ if ! const_prop_entry_heuristic (interp, result, si, sv, force)
939
+ # N.B. remarks are emitted within `const_prop_entry_heuristic`
940
+ return nothing
941
+ end
941
942
nargs:: Int = method. nargs
942
943
method. isva && (nargs -= 1 )
943
944
length (arginfo. argtypes) < nargs && return nothing
@@ -964,8 +965,17 @@ function maybe_get_const_prop_profitable(interp::AbstractInterpreter,
964
965
return mi
965
966
end
966
967
967
- function const_prop_entry_heuristic (interp:: AbstractInterpreter , result:: MethodCallResult , si:: StmtInfo , sv:: AbsIntState )
968
- if call_result_unused (si) && result. edgecycle
968
+ function const_prop_entry_heuristic (interp:: AbstractInterpreter , result:: MethodCallResult ,
969
+ si:: StmtInfo , sv:: AbsIntState , force:: Bool )
970
+ if result. rt isa LimitedAccuracy
971
+ # optimizations like inlining are disabled for limited frames,
972
+ # thus there won't be much benefit in constant-prop' here
973
+ # N.B. don't allow forced constprop' for safety (xref #52763)
974
+ add_remark! (interp, sv, " [constprop] Disabled by entry heuristic (limited accuracy)" )
975
+ return false
976
+ elseif force
977
+ return true
978
+ elseif call_result_unused (si) && result. edgecycle
969
979
add_remark! (interp, sv, " [constprop] Disabled by entry heuristic (edgecycle with unused result)" )
970
980
return false
971
981
end
@@ -978,27 +988,21 @@ function const_prop_entry_heuristic(interp::AbstractInterpreter, result::MethodC
978
988
if rt === Bottom
979
989
add_remark! (interp, sv, " [constprop] Disabled by entry heuristic (erroneous result)" )
980
990
return false
981
- else
982
- return true
983
991
end
992
+ return true
984
993
elseif isa (rt, PartialStruct) || isa (rt, InterConditional) || isa (rt, InterMustAlias)
985
994
# could be improved to `Const` or a more precise wrapper
986
995
return true
987
- elseif isa (rt, LimitedAccuracy)
988
- # optimizations like inlining are disabled for limited frames,
989
- # thus there won't be much benefit in constant-prop' here
990
- add_remark! (interp, sv, " [constprop] Disabled by entry heuristic (limited accuracy)" )
991
- return false
992
- else
993
- if isa (rt, Const)
994
- if ! is_nothrow (result. effects)
995
- # Could still be improved to Bottom (or at least could see the effects improved)
996
- return true
997
- end
996
+ elseif isa (rt, Const)
997
+ if is_nothrow (result. effects)
998
+ add_remark! (interp, sv, " [constprop] Disabled by entry heuristic (nothrow const)" )
999
+ return false
998
1000
end
999
- add_remark! (interp, sv, " [constprop] Disabled by entry heuristic (unimprovable result) " )
1000
- return false
1001
+ # Could still be improved to Bottom (or at least could see the effects improved )
1002
+ return true
1001
1003
end
1004
+ add_remark! (interp, sv, " [constprop] Disabled by entry heuristic (unimprovable result)" )
1005
+ return false
1002
1006
end
1003
1007
1004
1008
# determines heuristically whether if constant propagation can be worthwhile
0 commit comments