Skip to content

Commit

Permalink
Mark unionsplit effect-free cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Keno committed Feb 10, 2022
1 parent 37d5613 commit 93eb06c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion base/compiler/abstractinterpretation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1971,7 +1971,7 @@ function abstract_eval_global(M::Module, s::Symbol, frame::InferenceState)
if isdefined(M,s)
tristate_merge!(frame, Effects(EFFECTS_TOTAL, consistent=ALWAYS_FALSE))
else
tristate_merge!(frame, Effects(EFFECTS_TOTAL, consistent=ALWAYS_FALSE, nothrow=ALWAYS_FALSE, nothrow_if_inbounds=false))
tristate_merge!(frame, Effects(EFFECTS_TOTAL, consistent=ALWAYS_FALSE, nothrow=ALWAYS_FALSE, nothrow_if_inbounds=ALWAYS_FALSE))
end
return ty
end
Expand Down
18 changes: 18 additions & 0 deletions base/compiler/ssair/inlining.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1318,6 +1318,24 @@ function handle_cases!(ir::IRCode, idx::Int, stmt::Expr, @nospecialize(atype),
if fully_covered && length(cases) == 1
handle_single_case!(ir, idx, stmt, cases[1].item, todo, params)
elseif length(cases) > 0
all_removable = true
for case in cases
if isa(case, InvokeCase)
effects = case.effects
elseif isa(case, InliningTodo)
effects = case.spec.effects
else
continue
end
if !is_total(case.effects) &&
!(is_removable_if_unused(case.effects, ir[SSAValue(idx)][:flag] & IR_FLAG_INBOUNDS != 0))
all_removable = false
break
end
end
if all_removable
ir[SSAValue(idx)][:flag] |= IR_FLAG_EFFECT_FREE
end
push!(todo, idx=>UnionSplit(fully_covered, atype, cases))
end
return nothing
Expand Down
4 changes: 2 additions & 2 deletions base/compiler/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ struct Effects
# :consistent before caching. We may want to track it in the future.
inbounds_taints_consistency::Bool
end
Effects(consistent::TriState, effect_free::TriState, nothrow::TriState nothrow_if_inbounds::TriState, terminates::TriState) =
Effects(consistent::TriState, effect_free::TriState, nothrow::TriState, nothrow_if_inbounds::TriState, terminates::TriState) =
Effects(consistent, effect_free, nothrow, nothrow_if_inbounds, terminates, false)
Effects() = Effects(TRISTATE_UNKNOWN, TRISTATE_UNKNOWN, TRISTATE_UNKNOWN, TRISTATE_UNKNOWN, TRISTATE_UNKNOWN)

Effects(e::Effects; consistent::TriState=e.consistent,
effect_free::TriState = e.effect_free, nothrow::TriState=e.nothrow, nothrow_if_inbounds::TriState=e.nothrow_if_inbounds,
terminates::TriState=e.terminates, inbounds_taints_consistency::Bool = e.inbounds_taints_consistency) =
Effects(consistent, effect_free, nothrow, terminates, inbounds_taints_consistency)
Effects(consistent, effect_free, nothrow, nothrow_if_inbounds, terminates, inbounds_taints_consistency)

is_total_or_error(effects::Effects) =
effects.consistent === ALWAYS_TRUE && effects.effect_free === ALWAYS_TRUE &&
Expand Down

0 comments on commit 93eb06c

Please sign in to comment.