Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion base/compiler/abstractinterpretation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,13 @@ function const_prop_entry_heuristic(interp::AbstractInterpreter, result::MethodC
add_remark!(interp, sv, "[constprop] Disabled by entry heuristic (limited accuracy)")
return false
else
add_remark!(interp, sv, "[constprop] Disabled by entry heuristic (unimprovable return type)")
if isa(rt, Const)
if result.edge_effects.nothrow !== ALWAYS_TRUE
# Could still be improved to Bottom (or at least could see the effects improved)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems specifically the case that function was intended to ignore as a possibility. I think a more correct version of this PR would be removing this function entirely, and remarking here only that we do const_prop as a pre-inlining optimization, so the return result is irrelevant to whether it may improve the quality of the inlined code.

return true
end
end
add_remark!(interp, sv, "[constprop] Disabled by entry heuristic (unimprovable result)")
return false
end
end
Expand Down
25 changes: 19 additions & 6 deletions test/compiler/inline.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1136,14 +1136,14 @@ ambig_effect_test(a, b::Int) = 1
ambig_effect_test(a, b) = 1
global ambig_unknown_type_global=1
@noinline function conditionally_call_ambig(b::Bool, a)
if b
ambig_effect_test(a, ambig_unknown_type_global)
end
return 0
if b
ambig_effect_test(a, ambig_unknown_type_global)
end
return 0
end
function call_call_ambig(b::Bool)
conditionally_call_ambig(b, 1)
return 1
conditionally_call_ambig(b, 1)
return 1
end
@test !fully_eliminated(call_call_ambig, Tuple{Bool})

Expand Down Expand Up @@ -1246,3 +1246,16 @@ end
@test !fully_eliminated() do
getglobal(@__MODULE__, :my_defined_var, :foo)
end

# Test for deletion of value-dependent control flow that is apparent
# at inference time, but hard to delete later.
function maybe_error_int(x::Int)
if x > 2
Base.donotdelete(Base.inferencebarrier(x))
error()
end
return 1
end
@test fully_eliminated() do
return maybe_error_int(1)
end