Skip to content

Commit

Permalink
optimizer: fix the all_rettypes_consistent case of post-opt analysis (
Browse files Browse the repository at this point in the history
#51187)

The case does not seem to be functional, although it looks like we never
hit it currently.
We should have added test cases for this, so WIP until we come up with
some.
  • Loading branch information
aviatesk authored Sep 5, 2023
1 parent 354c367 commit 78e0ca3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
2 changes: 2 additions & 0 deletions base/compiler/inferencestate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ function in(idx::Int, bsbmp::BitSetBoundedMinPrioritySet)
return idx in bsbmp.elems
end

iterate(bsbmp::BitSetBoundedMinPrioritySet, s...) = iterate(bsbmp.elems, s...)

function append!(bsbmp::BitSetBoundedMinPrioritySet, itr)
for val in itr
push!(bsbmp, val)
Expand Down
10 changes: 6 additions & 4 deletions base/compiler/optimize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ struct AugmentedDomtree
end

function ipo_dataflow_analysis!(interp::AbstractInterpreter, ir::IRCode, result::InferenceResult)
inconsistent = BitSet()
inconsistent = BitSetBoundedMinPrioritySet(length(ir.stmts))
inconsistent_bbs = BitSet()
tpdum = TwoPhaseDefUseMap(length(ir.stmts))
lazypostdomtree = LazyPostDomtree(ir)
Expand Down Expand Up @@ -655,6 +655,8 @@ function ipo_dataflow_analysis!(interp::AbstractInterpreter, ir::IRCode, result:
scan!(scan_stmt!, scanner, true)
complete!(tpdum); push!(scanner.bb_ip, 1)
populate_def_use_map!(tpdum, scanner)

stmt_ip = BitSetBoundedMinPrioritySet(length(ir.stmts))
for def in inconsistent
for use in tpdum[def]
if !(use in inconsistent)
Expand All @@ -663,8 +665,6 @@ function ipo_dataflow_analysis!(interp::AbstractInterpreter, ir::IRCode, result:
end
end
end

stmt_ip = BitSetBoundedMinPrioritySet(length(ir.stmts))
while !isempty(stmt_ip)
idx = popfirst!(stmt_ip)
inst = ir[SSAValue(idx)]
Expand All @@ -683,7 +683,9 @@ function ipo_dataflow_analysis!(interp::AbstractInterpreter, ir::IRCode, result:
all_retpaths_consistent = false
else isa(stmt, GotoIfNot)
bb = block_for_inst(ir, idx)
for succ in iterated_dominance_frontier(ir.cfg, BlockLiveness(ir.cfg.blocks[bb].succs, nothing), get!(lazydomtree))
blockliveness = BlockLiveness(ir.cfg.blocks[bb].succs, nothing)
domtree = construct_domtree(ir.cfg.blocks)
for succ in iterated_dominance_frontier(ir.cfg, blockliveness, domtree)
visit_bb_phis!(ir, succ) do phiidx
push!(inconsistent, phiidx)
push!(stmt_ip, phiidx)
Expand Down
13 changes: 13 additions & 0 deletions test/compiler/datastructures.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,19 @@ end
bsbmp = Core.Compiler.BitSetBoundedMinPrioritySet(5)
Core.Compiler.push!(bsbmp, 2)
Core.Compiler.push!(bsbmp, 2)
iterateok = true
cnt = 0
@eval Core.Compiler for v in $bsbmp
if cnt == 0
iterateok &= v == 2
elseif cnt == 1
iterateok &= v == 5
else
iterateok = false
end
cnt += 1
end
@test iterateok
@test Core.Compiler.popfirst!(bsbmp) == 2
Core.Compiler.push!(bsbmp, 1)
@test Core.Compiler.popfirst!(bsbmp) == 1
Expand Down

0 comments on commit 78e0ca3

Please sign in to comment.