Skip to content

Commit 57101cf

Browse files
authored
compact: Don't try to kill the same edge twice (#48343)
In IR like: ``` goto if not true goto if not true ``` our implementation of `kill_edge!` goes through recursively to kill all newly unreachable blocks. However, it was still attempting to schedule the newly unreachable block. Then, when it got to the next GotoIfNot, it wsa again attempting to kill the same edge, which would fail, because the edge had already been removed from the CFG. Fix that by telling IncrementalCompact not to attempt scheduling any blocks that were newly discovered to be dead.
1 parent 6d8f54a commit 57101cf

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

base/compiler/ssair/ir.jl

+7-1
Original file line numberDiff line numberDiff line change
@@ -1189,6 +1189,12 @@ function kill_edge!(compact::IncrementalCompact, active_bb::Int, from::Int, to::
11891189
compact.result[stmt][:inst] = nothing
11901190
end
11911191
compact.result[last(stmts)][:inst] = ReturnNode()
1192+
else
1193+
# Tell compaction to not schedule this block. A value of -2 here
1194+
# indicates that the block is not to be scheduled, but there should
1195+
# still be an (unreachable) BB inserted into the final IR to avoid
1196+
# disturbing the BB numbering.
1197+
compact.bb_rename_succ[to] = -2
11921198
end
11931199
else
11941200
# Remove this edge from all phi nodes in `to` block
@@ -1531,7 +1537,7 @@ function iterate_compact(compact::IncrementalCompact)
15311537
resize!(compact, old_result_idx)
15321538
end
15331539
bb = compact.ir.cfg.blocks[active_bb]
1534-
if compact.cfg_transforms_enabled && active_bb > 1 && active_bb <= length(compact.bb_rename_succ) && compact.bb_rename_succ[active_bb] == -1
1540+
if compact.cfg_transforms_enabled && active_bb > 1 && active_bb <= length(compact.bb_rename_succ) && compact.bb_rename_succ[active_bb] <= -1
15351541
# Dead block, so kill the entire block.
15361542
compact.idx = last(bb.stmts)
15371543
# Pop any remaining insertion nodes

0 commit comments

Comments
 (0)