Skip to content

Commit

Permalink
compact: Don't attempt to amend basic block 0 (#54566)
Browse files Browse the repository at this point in the history
This allows insert_node_here! with reverse affinity at the start of the
first basic block, which is a bit of a corner case, but no reason for it
to be disallowed.
  • Loading branch information
Keno authored May 24, 2024
1 parent 5a5624c commit 424ac6e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion base/compiler/ssair/ir.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1018,7 +1018,8 @@ function did_just_finish_bb(compact)
result_idx = compact.result_idx
result_bbs = compact.cfg_transform.result_bbs
(compact.active_result_bb == length(result_bbs) + 1) ||
result_idx == first(result_bbs[compact.active_result_bb].stmts)
(result_idx == first(result_bbs[compact.active_result_bb].stmts) &&
compact.active_result_bb != 1)
end

function maybe_reopen_bb!(compact)
Expand Down
14 changes: 14 additions & 0 deletions test/compiler/compact.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,17 @@ end
verify_ir(new_ir)
@test length(new_ir.cfg.blocks) == 1
end

# Test reverse affinity insert at start of compact
@testset "IncrementalCompact reverse affinity insert" begin
ir = only(Base.code_ircode(foo_test_function, (Int,)))[1]
compact = IncrementalCompact(ir)
@test !Core.Compiler.did_just_finish_bb(compact)

insert_node_here!(compact, NewInstruction(ReturnNode(1), Union{}, ir[SSAValue(1)][:line]), true)
new_ir = finish(compact)
# TODO: Should IncrementalCompact be doing this internally?
empty!(new_ir.cfg.blocks[1].succs)
verify_ir(new_ir)
@test length(new_ir.cfg.blocks) == 1
end

0 comments on commit 424ac6e

Please sign in to comment.