Skip to content

Commit

Permalink
Fix bug in which uses of SSA values processed in just_fixup! were n…
Browse files Browse the repository at this point in the history
…ot counted

This fixes JuliaLang#29253, which was caused by `simple_dce!` erroneously erasing SSA
values that did not appear to be used, because these uses were only discovered
in `just_fixup!` at the end of iterating over an `IncrementalCompact`.
  • Loading branch information
yhls committed Mar 11, 2020
1 parent a37c4e1 commit 893f8dd
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions base/compiler/ssair/ir.jl
Original file line number Diff line number Diff line change
Expand Up @@ -270,11 +270,13 @@ function setindex!(x::IRCode, @nospecialize(repl), s::SSAValue)
nothing
end


# SSA values that need renaming
struct OldSSAValue
id::Int
end

# SSA values that are in `new_new_nodes` of an `IncrementalCompact` and are to
# be actually inserted next time (they become `new_nodes` next time)
struct NewSSAValue
id::Int
end
Expand Down Expand Up @@ -829,7 +831,7 @@ function process_phinode_values(old_values::Vector{Any}, late_fixup::Vector{Int}
return values
end

function renumber_ssa2(val::SSAValue, ssanums::Vector{Any}, used_ssa::Vector{Int}, do_rename_ssa::Bool)
function renumber_ssa2(val::SSAValue, ssanums::Vector{Any}, used_ssas::Vector{Int}, do_rename_ssa::Bool)
id = val.id
if id > length(ssanums)
return val
Expand All @@ -838,22 +840,22 @@ function renumber_ssa2(val::SSAValue, ssanums::Vector{Any}, used_ssa::Vector{Int
val = ssanums[id]
end
if isa(val, SSAValue)
if used_ssa !== nothing
used_ssa[val.id] += 1
if used_ssas !== nothing
used_ssas[val.id] += 1
end
end
return val
end

function renumber_ssa2!(@nospecialize(stmt), ssanums::Vector{Any}, used_ssa::Vector{Int}, late_fixup::Vector{Int}, result_idx::Int, do_rename_ssa::Bool)
function renumber_ssa2!(@nospecialize(stmt), ssanums::Vector{Any}, used_ssas::Vector{Int}, late_fixup::Vector{Int}, result_idx::Int, do_rename_ssa::Bool)
urs = userefs(stmt)
for op in urs
val = op[]
if isa(val, OldSSAValue) || isa(val, NewSSAValue)
push!(late_fixup, result_idx)
end
if isa(val, SSAValue)
val = renumber_ssa2(val, ssanums, used_ssa, do_rename_ssa)
val = renumber_ssa2(val, ssanums, used_ssas, do_rename_ssa)
end
if isa(val, OldSSAValue) || isa(val, NewSSAValue)
push!(late_fixup, result_idx)
Expand Down Expand Up @@ -1347,10 +1349,17 @@ function fixup_node(compact::IncrementalCompact, @nospecialize(stmt))
for ur in urs
val = ur[]
if isa(val, NewSSAValue)
ur[] = SSAValue(length(compact.result) + val.id)
val = SSAValue(length(compact.result) + val.id)
elseif isa(val, OldSSAValue)
ur[] = compact.ssa_rename[val.id]
val = compact.ssa_rename[val.id]
end
if isa(val, SSAValue) && val.id <= length(compact.used_ssas)
# If `val.id` is greater than the length of `compact.result` or
# `compact.used_ssas`, this SSA value is in `new_new_nodes`, so
# don't count the use
compact.used_ssas[val.id] += 1
end
ur[] = val
end
return urs[]
end
Expand Down

0 comments on commit 893f8dd

Please sign in to comment.