Skip to content

Commit

Permalink
adjust EA to #52527 (#55986)
Browse files Browse the repository at this point in the history
`EnterNode.catch_dest` can now be `0` after the `try`/`catch` elision
feature implemented in #52527, and we actually need to
adjust `EscapeAnalysis.compute_frameinfo` too.
  • Loading branch information
aviatesk authored Oct 4, 2024
1 parent 636a35d commit 80d67d5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
10 changes: 6 additions & 4 deletions base/compiler/ssair/EscapeAnalysis/EscapeAnalysis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -732,11 +732,13 @@ function compute_frameinfo(ir::IRCode)
inst = ir[SSAValue(idx)]
stmt = inst[:stmt]
if isa(stmt, EnterNode)
@assert idx nstmts "try/catch inside new_nodes unsupported"
tryregions === nothing && (tryregions = UnitRange{Int}[])
leave_block = stmt.catch_dest
leave_pc = first(ir.cfg.blocks[leave_block].stmts)
push!(tryregions, idx:leave_pc)
if leave_block 0
@assert idx nstmts "try/catch inside new_nodes unsupported"
tryregions === nothing && (tryregions = UnitRange{Int}[])
leave_pc = first(ir.cfg.blocks[leave_block].stmts)
push!(tryregions, idx:leave_pc)
end
elseif arrayinfo !== nothing
# TODO this super limited alias analysis is able to handle only very simple cases
# this should be replaced with a proper forward dimension analysis
Expand Down
17 changes: 17 additions & 0 deletions test/compiler/EscapeAnalysis/EscapeAnalysis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2299,4 +2299,21 @@ let result = code_escapes((SafeRef{String},Any)) do x, y
@test has_all_escape(result.state[Argument(3)]) # y
end

@eval function scope_folding()
$(Expr(:tryfinally,
Expr(:block,
Expr(:tryfinally, :(), :(), 2),
:(return Core.current_scope())),
:(), 1))
end
@eval function scope_folding_opt()
$(Expr(:tryfinally,
Expr(:block,
Expr(:tryfinally, :(), :(), :(Base.inferencebarrier(2))),
:(return Core.current_scope())),
:(), :(Base.inferencebarrier(1))))
end
@test (@code_escapes scope_folding()) isa EAUtils.EscapeResult
@test (@code_escapes scope_folding_opt()) isa EAUtils.EscapeResult

end # module test_EA
7 changes: 2 additions & 5 deletions test/compiler/irpasses.jl
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,6 @@ let # lifting `isa` through Core.ifelse
@test count(iscall((src, isa)), src.code) == 0
end


let # lifting `isdefined` through PhiNode
src = code_typed1((Bool,Some{Int},)) do c, x
y = c ? x : nothing
Expand Down Expand Up @@ -1035,8 +1034,7 @@ exc39508 = ErrorException("expected")
end
@test test39508() === exc39508

let
# `typeassert` elimination after SROA
let # `typeassert` elimination after SROA
# NOTE we can remove this optimization once inference is able to reason about memory-effects
src = @eval Module() begin
mutable struct Foo; x; end
Expand All @@ -1051,8 +1049,7 @@ let
@test count(iscall((src, typeassert)), src.code) == 0
end

let
# Test for https://github.com/JuliaLang/julia/issues/43402
let # Test for https://github.com/JuliaLang/julia/issues/43402
# Ensure that structs required not used outside of the ccall,
# still get listed in the ccall_preserves

Expand Down

0 comments on commit 80d67d5

Please sign in to comment.