Skip to content

Commit

Permalink
irinterp: Fix accidentally introduced deletion of effectful statement (
Browse files Browse the repository at this point in the history
…#49750)

I moved around some code in #49692 that broadened the replacement of
statements by their const results. This is fine for how we're currently
using irinterp in base, because we're requiring some fairly strong
effects, but some downstream pipelines (and potentially Base in the future)
want to use irinterp on code with arbitrary effects, so put in an
appropriate check.
  • Loading branch information
Keno authored May 11, 2023
1 parent 7757e46 commit 0b5ec1f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 5 deletions.
1 change: 1 addition & 0 deletions base/compiler/abstractinterpretation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2544,6 +2544,7 @@ end
function abstract_eval_statement(interp::AbstractInterpreter, @nospecialize(e), vtypes::VarTable, sv::InferenceState)
if !isa(e, Expr)
if isa(e, PhiNode)
add_curr_ssaflag!(sv, IR_FLAG_EFFECT_FREE)
return abstract_eval_phi(interp, e, vtypes, sv)
end
return abstract_eval_special_value(interp, e, vtypes, sv)
Expand Down
6 changes: 1 addition & 5 deletions base/compiler/ssair/irinterp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -128,16 +128,12 @@ function reprocess_instruction!(interp::AbstractInterpreter, idx::Int, bb::Union
end
return propagate_control_effects!(interp, idx, inst, irsv, extra_reprocess)
end

rt = nothing
if isa(inst, Expr)
head = inst.head
if head === :call || head === :foreigncall || head === :new || head === :splatnew
(; rt, effects) = abstract_eval_statement_expr(interp, inst, nothing, irsv)
ir.stmts[idx][:flag] |= flags_for_effects(effects)
if is_foldable(effects) && isa(rt, Const) && is_inlineable_constant(rt.val)
ir.stmts[idx][:inst] = quoted(rt.val)
end
elseif head === :invoke
rt, nothrow = concrete_eval_invoke(interp, inst, inst.args[1]::MethodInstance, irsv)
if nothrow
Expand Down Expand Up @@ -167,7 +163,7 @@ function reprocess_instruction!(interp::AbstractInterpreter, idx::Int, bb::Union
if rt !== nothing
if isa(rt, Const)
ir.stmts[idx][:type] = rt
if is_inlineable_constant(rt.val)
if is_inlineable_constant(rt.val) && (ir.stmts[idx][:flag] & IR_FLAG_EFFECT_FREE) != 0
ir.stmts[idx][:inst] = quoted(rt.val)
end
return true
Expand Down

0 comments on commit 0b5ec1f

Please sign in to comment.