diff --git a/base/compiler/abstractinterpretation.jl b/base/compiler/abstractinterpretation.jl index 0e57f01bfbd12..99f3742a8f13f 100644 --- a/base/compiler/abstractinterpretation.jl +++ b/base/compiler/abstractinterpretation.jl @@ -1153,8 +1153,11 @@ function semi_concrete_eval_call(interp::AbstractInterpreter, # that are newly resovled by irinterp # state = InliningState(interp) # ir = ssa_inlining_pass!(irsv.ir, state, propagate_inbounds(irsv)) - new_effects = Effects(result.effects; nothrow) - return ConstCallResults(rt, SemiConcreteResult(mi, ir, new_effects), new_effects, mi) + effects = result.effects + if !is_nothrow(effects) + effects = Effects(effects; nothrow) + end + return ConstCallResults(rt, SemiConcreteResult(mi, ir, effects), effects, mi) end end end diff --git a/test/compiler/effects.jl b/test/compiler/effects.jl index 2cf421073a166..44554690b1b98 100644 --- a/test/compiler/effects.jl +++ b/test/compiler/effects.jl @@ -1010,3 +1010,16 @@ end |> !Core.Compiler.is_nothrow @test Base.infer_effects() do getglobal(@__MODULE__, :my_defined_var, :foo, nothing) end |> !Core.Compiler.is_nothrow + +# irinterp should refine `:nothrow` information only if profitable +Base.@assume_effects :nothrow function irinterp_nothrow_override(x, y) + z = sin(y) + if x + return "julia" + end + return z +end +@test Base.infer_effects((Float64,)) do y + isinf(y) && return zero(y) + irinterp_nothrow_override(true, y) +end |> Core.Compiler.is_nothrow