Skip to content

Commit

Permalink
compact: Don't try to kill the same edge twice (#48343)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Keno authored Jan 20, 2023
1 parent 6d8f54a commit 57101cf
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion base/compiler/ssair/ir.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1189,6 +1189,12 @@ function kill_edge!(compact::IncrementalCompact, active_bb::Int, from::Int, to::
compact.result[stmt][:inst] = nothing
end
compact.result[last(stmts)][:inst] = ReturnNode()
else
# Tell compaction to not schedule this block. A value of -2 here
# indicates that the block is not to be scheduled, but there should
# still be an (unreachable) BB inserted into the final IR to avoid
# disturbing the BB numbering.
compact.bb_rename_succ[to] = -2
end
else
# Remove this edge from all phi nodes in `to` block
Expand Down Expand Up @@ -1531,7 +1537,7 @@ function iterate_compact(compact::IncrementalCompact)
resize!(compact, old_result_idx)
end
bb = compact.ir.cfg.blocks[active_bb]
if compact.cfg_transforms_enabled && active_bb > 1 && active_bb <= length(compact.bb_rename_succ) && compact.bb_rename_succ[active_bb] == -1
if compact.cfg_transforms_enabled && active_bb > 1 && active_bb <= length(compact.bb_rename_succ) && compact.bb_rename_succ[active_bb] <= -1
# Dead block, so kill the entire block.
compact.idx = last(bb.stmts)
# Pop any remaining insertion nodes
Expand Down

0 comments on commit 57101cf

Please sign in to comment.