814
814
function abstract_call_method_with_const_args (interp:: AbstractInterpreter ,
815
815
result:: MethodCallResult , @nospecialize (f), arginfo:: ArgInfo , si:: StmtInfo ,
816
816
match:: MethodMatch , sv:: AbsIntState , invokecall:: Union{Nothing,InvokeCall} = nothing )
817
-
818
- if ! const_prop_enabled (interp, sv, match)
819
- return nothing
820
- end
821
- if bail_out_const_call (interp, result, si)
822
- add_remark! (interp, sv, " [constprop] No more information to be gained" )
817
+ if ! const_prop_enabled (interp, match, sv) || bail_out_const_call (interp, result, si, sv)
823
818
return nothing
824
819
end
825
820
eligibility = concrete_eval_eligible (interp, f, result, arginfo, sv)
@@ -852,7 +847,7 @@ function abstract_call_method_with_const_args(interp::AbstractInterpreter,
852
847
return const_prop_call (interp, mi, result, arginfo, sv, concrete_eval_result)
853
848
end
854
849
855
- function const_prop_enabled (interp:: AbstractInterpreter , sv :: AbsIntState , match :: MethodMatch )
850
+ function const_prop_enabled (interp:: AbstractInterpreter , match :: MethodMatch , sv :: AbsIntState )
856
851
if ! InferenceParams (interp). ipo_constant_propagation
857
852
add_remark! (interp, sv, " [constprop] Disabled by parameter" )
858
853
return false
@@ -864,9 +859,11 @@ function const_prop_enabled(interp::AbstractInterpreter, sv::AbsIntState, match:
864
859
return true
865
860
end
866
861
867
- function bail_out_const_call (interp:: AbstractInterpreter , result:: MethodCallResult , si:: StmtInfo )
862
+ function bail_out_const_call (interp:: AbstractInterpreter , result:: MethodCallResult ,
863
+ si:: StmtInfo , sv:: AbsIntState )
868
864
if is_removable_if_unused (result. effects)
869
865
if isa (result. rt, Const) || call_result_unused (si)
866
+ add_remark! (interp, sv, " [constprop] No more information to be gained (const)" )
870
867
return true
871
868
end
872
869
elseif result. rt === Bottom
@@ -876,6 +873,7 @@ function bail_out_const_call(interp::AbstractInterpreter, result::MethodCallResu
876
873
# precise enough to let us determine :consistency of `exct`, so we
877
874
# would have to force constprop just to determine this, which is too
878
875
# expensive.
876
+ add_remark! (interp, sv, " [constprop] No more information to be gained (bottom)" )
879
877
return true
880
878
end
881
879
end
@@ -974,7 +972,10 @@ function maybe_get_const_prop_profitable(interp::AbstractInterpreter,
974
972
match:: MethodMatch , sv:: AbsIntState )
975
973
method = match. method
976
974
force = force_const_prop (interp, f, method)
977
- force || const_prop_entry_heuristic (interp, result, si, sv) || return nothing
975
+ if ! const_prop_entry_heuristic (interp, result, si, sv, force)
976
+ # N.B. remarks are emitted within `const_prop_entry_heuristic`
977
+ return nothing
978
+ end
978
979
nargs:: Int = method. nargs
979
980
method. isva && (nargs -= 1 )
980
981
length (arginfo. argtypes) < nargs && return nothing
@@ -1001,8 +1002,17 @@ function maybe_get_const_prop_profitable(interp::AbstractInterpreter,
1001
1002
return mi
1002
1003
end
1003
1004
1004
- function const_prop_entry_heuristic (interp:: AbstractInterpreter , result:: MethodCallResult , si:: StmtInfo , sv:: AbsIntState )
1005
- if call_result_unused (si) && result. edgecycle
1005
+ function const_prop_entry_heuristic (interp:: AbstractInterpreter , result:: MethodCallResult ,
1006
+ si:: StmtInfo , sv:: AbsIntState , force:: Bool )
1007
+ if result. rt isa LimitedAccuracy
1008
+ # optimizations like inlining are disabled for limited frames,
1009
+ # thus there won't be much benefit in constant-prop' here
1010
+ # N.B. don't allow forced constprop' for safety (xref #52763)
1011
+ add_remark! (interp, sv, " [constprop] Disabled by entry heuristic (limited accuracy)" )
1012
+ return false
1013
+ elseif force
1014
+ return true
1015
+ elseif call_result_unused (si) && result. edgecycle
1006
1016
add_remark! (interp, sv, " [constprop] Disabled by entry heuristic (edgecycle with unused result)" )
1007
1017
return false
1008
1018
end
@@ -1015,27 +1025,21 @@ function const_prop_entry_heuristic(interp::AbstractInterpreter, result::MethodC
1015
1025
if rt === Bottom
1016
1026
add_remark! (interp, sv, " [constprop] Disabled by entry heuristic (erroneous result)" )
1017
1027
return false
1018
- else
1019
- return true
1020
1028
end
1029
+ return true
1021
1030
elseif isa (rt, PartialStruct) || isa (rt, InterConditional) || isa (rt, InterMustAlias)
1022
1031
# could be improved to `Const` or a more precise wrapper
1023
1032
return true
1024
- elseif isa (rt, LimitedAccuracy)
1025
- # optimizations like inlining are disabled for limited frames,
1026
- # thus there won't be much benefit in constant-prop' here
1027
- add_remark! (interp, sv, " [constprop] Disabled by entry heuristic (limited accuracy)" )
1028
- return false
1029
- else
1030
- if isa (rt, Const)
1031
- if ! is_nothrow (result. effects)
1032
- # Could still be improved to Bottom (or at least could see the effects improved)
1033
- return true
1034
- end
1033
+ elseif isa (rt, Const)
1034
+ if is_nothrow (result. effects)
1035
+ add_remark! (interp, sv, " [constprop] Disabled by entry heuristic (nothrow const)" )
1036
+ return false
1035
1037
end
1036
- add_remark! (interp, sv, " [constprop] Disabled by entry heuristic (unimprovable result) " )
1037
- return false
1038
+ # Could still be improved to Bottom (or at least could see the effects improved )
1039
+ return true
1038
1040
end
1041
+ add_remark! (interp, sv, " [constprop] Disabled by entry heuristic (unimprovable result)" )
1042
+ return false
1039
1043
end
1040
1044
1041
1045
# determines heuristically whether if constant propagation can be worthwhile
0 commit comments