Skip to content

Commit

Permalink
Update defuses based on DCE results
Browse files Browse the repository at this point in the history
  • Loading branch information
Cédric Belmant committed Jan 30, 2025
1 parent 683c5e7 commit 925afc6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Compiler/src/ssair/passes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1511,6 +1511,10 @@ function sroa_pass!(ir::IRCode, inlining::Union{Nothing,InliningState}=nothing)
used_ssas[x.id] -= 1
end
ir = complete(compact)
# remove any use that has been optimized away by the DCE
for (intermediaries, defuse) in values(defuses)
filter!(x -> ir[SSAValue(x.idx)][:stmt] !== nothing, defuse.uses)
end
sroa_mutables!(ir, defuses, used_ssas, lazydomtree, inlining)
return ir
else
Expand Down
16 changes: 16 additions & 0 deletions Compiler/test/irpasses.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2030,3 +2030,19 @@ let code = Any[
ir = Compiler.domsort_ssa!(ir, domtree)
Compiler.verify_ir(ir)
end

# https://github.com/JuliaLang/julia/issues/57141
# don't eliminate `setfield!` when the field is to be used
let src = code_typed1(()) do
f = function ()
ref = Ref{Any}()
ref[] = 0
@assert isdefined(ref, :x)
inner() = ref[] + 1
(inner(), ref[])
end
first(f())
end
ex = src.code[2]
@test isexpr(ex, :call) && argextype(ex.args[1], src) === Const(setfield!)
end

0 comments on commit 925afc6

Please sign in to comment.