Skip to content

Commit

Permalink
Fix nothrow modeling of have_fma (#43785)
Browse files Browse the repository at this point in the history
Allows functions that make use of fma to be considered ConstAPI
(so long has both have_fma branches return the same constant).
  • Loading branch information
Keno authored Jan 14, 2022
1 parent 5847647 commit 294b0df
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
5 changes: 3 additions & 2 deletions base/compiler/optimize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ function finish(interp::AbstractInterpreter, opt::OptimizationState,
# otherwise we might skip throwing errors (issue #20704)
# TODO: Improve this analysis; if a function is marked @pure we should really
# only care about certain errors (e.g. method errors and type errors).
if length(ir.stmts) < 10
if length(ir.stmts) < 15
proven_pure = true
for i in 1:length(ir.stmts)
node = ir.stmts[i]
Expand Down Expand Up @@ -624,7 +624,8 @@ function is_pure_intrinsic_infer(f::IntrinsicFunction)
end

# whether `f` is effect free if nothrow
intrinsic_effect_free_if_nothrow(f) = f === Intrinsics.pointerref || is_pure_intrinsic_infer(f)
intrinsic_effect_free_if_nothrow(f) = f === Intrinsics.pointerref ||
f === Intrinsics.have_fma || is_pure_intrinsic_infer(f)

## Computing the cost of a function body

Expand Down
4 changes: 4 additions & 0 deletions base/compiler/tfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1815,6 +1815,10 @@ function intrinsic_nothrow(f::IntrinsicFunction, argtypes::Array{Any, 1})
xty = widenconst(argtypes[2])
return isconcrete && isprimitivetype(ty) && isprimitivetype(xty)
end
if f === Intrinsics.have_fma
ty, isexact, isconcrete = instanceof_tfunc(argtypes[1])
return isconcrete && isprimitivetype(ty)
end
# The remaining intrinsics are math/bits/comparison intrinsics. They work on all
# primitive types of the same type.
isshift = f === shl_int || f === lshr_int || f === ashr_int
Expand Down
4 changes: 4 additions & 0 deletions test/compiler/inline.jl
Original file line number Diff line number Diff line change
Expand Up @@ -880,3 +880,7 @@ end
@test count(iscall((src,UnionAll)), src.code) == 0
end
end

# have_fma elimination inside ^
f_pow() = ^(2.0, -1.0)
@test fully_eliminated(f_pow, Tuple{})

2 comments on commit 294b0df

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Executing the daily package evaluation, I will reply here when finished:

@nanosoldier runtests(ALL, isdaily = true)

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your package evaluation job has completed - possible new issues were detected. A full report can be found here.

Please sign in to comment.