Skip to content

Commit

Permalink
cfg_simplify: Add one more check to avoid merging :leave terminator (#…
Browse files Browse the repository at this point in the history
…52621)

In #52608, I made `:leave` a proper terminator (we already considered it
as such during CFG construction, we just didn't maintain that property
in the optimizer). As part of this, I adjusted one place in cfg_simplify
to avoid merging blocks that end with non-trivial terminators
(previously only EnterNode was considered). Turns out there's another
one, so fix that as well.
  • Loading branch information
Keno authored Dec 23, 2023
1 parent 0b5cf42 commit 52ff558
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions base/compiler/ssair/passes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2140,10 +2140,10 @@ function legalize_bb_drop_pred!(ir::IRCode, bb::BasicBlock, bbidx::Int, bbs::Vec
end
ir[last_fallthrough_term_ssa] = nothing
kill_edge!(bbs, last_fallthrough, terminator.dest)
elseif isa(terminator, EnterNode)
return false
elseif isa(terminator, GotoNode)
return true
elseif isterminator(terminator)
return false
end
# Hack, but effective. If we have a predecessor with a fall-through terminator, change the
# instruction numbering to merge the blocks now such that below processing will properly
Expand Down
4 changes: 2 additions & 2 deletions test/compiler/irpasses.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1594,7 +1594,7 @@ let code = Any[
# Block 2
EnterNode(4),
# Block 3
Expr(:leave),
Expr(:leave, SSAValue(2)),
# Block 4
GotoNode(5),
# Block 5
Expand All @@ -1603,7 +1603,7 @@ let code = Any[
ir = make_ircode(code)
ir = Core.Compiler.cfg_simplify!(ir)
Core.Compiler.verify_ir(ir)
@test length(ir.cfg.blocks) == 4
@test length(ir.cfg.blocks) <= 5
end

# Test CFG simplify with single predecessor phi node
Expand Down

0 comments on commit 52ff558

Please sign in to comment.