Skip to content

Commit 0b5ec1f

Browse files
authored
irinterp: Fix accidentally introduced deletion of effectful statement (#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.
1 parent 7757e46 commit 0b5ec1f

File tree

2 files changed

+2
-5
lines changed

2 files changed

+2
-5
lines changed

base/compiler/abstractinterpretation.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2544,6 +2544,7 @@ end
25442544
function abstract_eval_statement(interp::AbstractInterpreter, @nospecialize(e), vtypes::VarTable, sv::InferenceState)
25452545
if !isa(e, Expr)
25462546
if isa(e, PhiNode)
2547+
add_curr_ssaflag!(sv, IR_FLAG_EFFECT_FREE)
25472548
return abstract_eval_phi(interp, e, vtypes, sv)
25482549
end
25492550
return abstract_eval_special_value(interp, e, vtypes, sv)

base/compiler/ssair/irinterp.jl

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,16 +128,12 @@ function reprocess_instruction!(interp::AbstractInterpreter, idx::Int, bb::Union
128128
end
129129
return propagate_control_effects!(interp, idx, inst, irsv, extra_reprocess)
130130
end
131-
132131
rt = nothing
133132
if isa(inst, Expr)
134133
head = inst.head
135134
if head === :call || head === :foreigncall || head === :new || head === :splatnew
136135
(; rt, effects) = abstract_eval_statement_expr(interp, inst, nothing, irsv)
137136
ir.stmts[idx][:flag] |= flags_for_effects(effects)
138-
if is_foldable(effects) && isa(rt, Const) && is_inlineable_constant(rt.val)
139-
ir.stmts[idx][:inst] = quoted(rt.val)
140-
end
141137
elseif head === :invoke
142138
rt, nothrow = concrete_eval_invoke(interp, inst, inst.args[1]::MethodInstance, irsv)
143139
if nothrow
@@ -167,7 +163,7 @@ function reprocess_instruction!(interp::AbstractInterpreter, idx::Int, bb::Union
167163
if rt !== nothing
168164
if isa(rt, Const)
169165
ir.stmts[idx][:type] = rt
170-
if is_inlineable_constant(rt.val)
166+
if is_inlineable_constant(rt.val) && (ir.stmts[idx][:flag] & IR_FLAG_EFFECT_FREE) != 0
171167
ir.stmts[idx][:inst] = quoted(rt.val)
172168
end
173169
return true

0 commit comments

Comments
 (0)