Skip to content

Commit

Permalink
fix bug in which uses of SSA values that occur in late fixup were not…
Browse files Browse the repository at this point in the history
… counted

this led to stuff being erroneously removed by `simple_dce!`
this fixes #29253
  • Loading branch information
yhls committed Dec 14, 2019
1 parent 8595fc0 commit 5479a4f
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 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 @@ -498,7 +500,7 @@ mutable struct IncrementalCompact
bb_rename_pred::Vector{Int}
bb_rename_succ::Vector{Int}

used_ssas::Vector{Int} # not renamed but including new statements
used_ssas::Vector{Int}
late_fixup::Vector{Int}

# This could be Stateful, but bootstrapping doesn't like that
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 @@ -1344,10 +1346,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 5479a4f

Please sign in to comment.