Skip to content

Commit 908bc08

Browse files
committed
Stop renumbering statements in inference proper
I don't think there's any good reason to try to delete the statements here. The very next thing we do is to convert to IRCode which drops dead code anyway, so this just seems redundant. In addition, it complicates Cthulhu-like analysis, which now has to track an extra set of statement numbers.
1 parent 82fbf54 commit 908bc08

File tree

3 files changed

+11
-23
lines changed

3 files changed

+11
-23
lines changed

base/compiler/ssair/irinterp.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,8 @@ function reprocess_instruction!(interp::AbstractInterpreter,
251251
return false
252252
elseif isa(inst, PiNode)
253253
rt = tmeet(typeinf_lattice(interp), argextype(inst.val, ir), widenconst(inst.typ))
254+
elseif inst === nothing
255+
return false
254256
else
255257
ccall(:jl_, Cvoid, (Any,), inst)
256258
error()

base/compiler/ssair/slot2ssa.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,9 @@ function iterated_dominance_frontier(cfg::CFG, liveness::BlockLiveness, domtree:
338338
end
339339

340340
function rename_incoming_edge(old_edge::Int, old_to::Int, result_order::Vector{Int}, bb_rename::Vector{Int})
341+
old_edge == 0 && return 0
341342
new_edge_from = bb_rename[old_edge]
343+
new_edge_from < 0 && return new_edge_from
342344
if old_edge == old_to - 1
343345
# Could have been a crit edge break
344346
if new_edge_from < length(result_order) && result_order[new_edge_from + 1] == 0
@@ -364,7 +366,7 @@ function rename_phinode_edges(node::PhiNode, bb::Int, result_order::Vector{Int},
364366
new_edges = Int32[]
365367
for (idx, edge) in pairs(node.edges)
366368
edge = Int(edge)
367-
(edge == 0 || bb_rename[edge] != 0) || continue
369+
(edge == 0 || bb_rename[edge] != -1) || continue
368370
new_edge_from = edge == 0 ? 0 : rename_incoming_edge(edge, bb, result_order, bb_rename)
369371
push!(new_edges, new_edge_from)
370372
if isassigned(node.values, idx)
@@ -387,7 +389,7 @@ function domsort_ssa!(ir::IRCode, domtree::DomTree)
387389
# First compute the new order of basic blocks
388390
result_order = Int[]
389391
stack = Int[]
390-
bb_rename = zeros(Int, length(ir.cfg.blocks))
392+
bb_rename = fill(-1, length(ir.cfg.blocks))
391393
node = 1
392394
ncritbreaks = 0
393395
nnewfallthroughs = 0
@@ -498,7 +500,7 @@ function domsort_ssa!(ir::IRCode, domtree::DomTree)
498500
bb_start_off += length(inst_range)
499501
local new_preds, new_succs
500502
let bb = bb, bb_rename = bb_rename, result_order = result_order
501-
new_preds = Int[i == 0 ? 0 : rename_incoming_edge(i, bb, result_order, bb_rename) for i in ir.cfg.blocks[bb].preds]
503+
new_preds = Int[bb for bb in (rename_incoming_edge(i, bb, result_order, bb_rename) for i in ir.cfg.blocks[bb].preds) if bb != -1]
502504
new_succs = Int[ rename_outgoing_edge(i, bb, result_order, bb_rename) for i in ir.cfg.blocks[bb].succs]
503505
end
504506
new_bbs[new_bb] = BasicBlock(inst_range, new_preds, new_succs)

base/compiler/typeinfer.jl

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -556,8 +556,7 @@ function finish(me::InferenceState, interp::AbstractInterpreter)
556556
# annotate fulltree with type information,
557557
# either because we are the outermost code, or we might use this later
558558
doopt = (me.cached || me.parent !== nothing)
559-
changemap = type_annotate!(interp, me, doopt)
560-
recompute_cfg = changemap !== nothing
559+
recompute_cfg = type_annotate!(interp, me, doopt)
561560
if doopt && may_optimize(interp)
562561
me.result.src = OptimizationState(me, OptimizationParams(interp), interp, recompute_cfg)
563562
else
@@ -715,6 +714,7 @@ function type_annotate!(interp::AbstractInterpreter, sv::InferenceState, run_opt
715714
slotflags = src.slotflags
716715
nslots = length(slotflags)
717716
undefs = fill(false, nslots)
717+
any_unreachable = false
718718

719719
# this statement traversal does five things:
720720
# 1. introduce temporary `TypedSlot`s that are supposed to be replaced with π-nodes later
@@ -742,13 +742,9 @@ function type_annotate!(interp::AbstractInterpreter, sv::InferenceState, run_opt
742742
body[i] = annotate_slot_load!(undefs, i, sv, expr) # 1&2
743743
ssavaluetypes[i] = widenslotwrapper(ssavaluetypes[i]) # 4
744744
else # i.e. any runtime execution will never reach this statement
745+
any_unreachable = true
745746
if is_meta_expr(expr) # keep any lexically scoped expressions
746747
ssavaluetypes[i] = Any # 4
747-
elseif run_optimizer
748-
if changemap === nothing
749-
changemap = fill(0, nexpr)
750-
end
751-
changemap[i] = -1 # 3&4: mark for the bulk deletion
752748
else
753749
ssavaluetypes[i] = Bottom # 4
754750
body[i] = Const(expr) # annotate that this statement actually is dead
@@ -763,19 +759,7 @@ function type_annotate!(interp::AbstractInterpreter, sv::InferenceState, run_opt
763759
end
764760
end
765761

766-
# do the bulk deletion of unreached statements
767-
if changemap !== nothing
768-
inds = Int[i for (i,v) in enumerate(changemap) if v == -1]
769-
deleteat!(body, inds)
770-
deleteat!(ssavaluetypes, inds)
771-
deleteat!(codelocs, inds)
772-
deleteat!(stmt_info, inds)
773-
deleteat!(ssaflags, inds)
774-
renumber_ir_elements!(body, changemap)
775-
return changemap
776-
else
777-
return nothing
778-
end
762+
return any_unreachable
779763
end
780764

781765
# at the end, all items in b's cycle

0 commit comments

Comments
 (0)