Skip to content

Commit d587f9d

Browse files
authored
fix #37558, allow optimizing calls to functions that throw (#37572)
1 parent 2944f38 commit d587f9d

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

base/compiler/utilities.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,17 +269,17 @@ function find_throw_blocks(code::Vector{Any}, ir = RefValue{IRCode}())
269269
push!(stmts, i)
270270
end
271271
elseif s.head === :return
272-
elseif is_throw_call(s) || s.head === :unreachable
272+
elseif is_throw_call(s)
273273
if try_depth == 0
274274
push!(stmts, i)
275275
end
276276
elseif i+1 in stmts
277277
push!(stmts, i)
278278
end
279279
elseif isa(s, ReturnNode)
280-
if try_depth == 0 && !isdefined(s, :val)
281-
push!(stmts, i)
282-
end
280+
# NOTE: it potentially makes sense to treat unreachable nodes
281+
# (where !isdefined(s, :val)) as `throw` points, but that can cause
282+
# worse codegen around the call site (issue #37558)
283283
elseif isa(s, GotoNode)
284284
tgt = s.label
285285
if isassigned(ir)

doc/src/devdocs/inference.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,12 @@ Each statement gets analyzed for its total cost in a function called
101101
as follows:
102102
```jldoctest; filter=r"tuple.jl:\d+"
103103
julia> Base.print_statement_costs(stdout, map, (typeof(sqrt), Tuple{Int},)) # map(sqrt, (2,))
104-
map(f, t::Tuple{Any}) in Base at tuple.jl:169
104+
map(f, t::Tuple{Any}) in Base at tuple.jl:179
105105
0 1 ─ %1 = Base.getfield(_3, 1, true)::Int64
106106
1 │ %2 = Base.sitofp(Float64, %1)::Float64
107107
2 │ %3 = Base.lt_float(%2, 0.0)::Bool
108108
0 └── goto #3 if not %3
109-
0 2 ─ Base.Math.throw_complex_domainerror(:sqrt, %2)::Union{}
109+
0 2 ─ invoke Base.Math.throw_complex_domainerror(:sqrt::Symbol, %2::Float64)::Union{}
110110
0 └── unreachable
111111
20 3 ─ %7 = Base.Math.sqrt_llvm(%2)::Float64
112112
0 └── goto #4

0 commit comments

Comments
 (0)