Skip to content

Commit 294b0df

Browse files
authored
Fix nothrow modeling of have_fma (#43785)
Allows functions that make use of fma to be considered ConstAPI (so long has both have_fma branches return the same constant).
1 parent 5847647 commit 294b0df

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

base/compiler/optimize.jl

+3-2
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ function finish(interp::AbstractInterpreter, opt::OptimizationState,
408408
# otherwise we might skip throwing errors (issue #20704)
409409
# TODO: Improve this analysis; if a function is marked @pure we should really
410410
# only care about certain errors (e.g. method errors and type errors).
411-
if length(ir.stmts) < 10
411+
if length(ir.stmts) < 15
412412
proven_pure = true
413413
for i in 1:length(ir.stmts)
414414
node = ir.stmts[i]
@@ -624,7 +624,8 @@ function is_pure_intrinsic_infer(f::IntrinsicFunction)
624624
end
625625

626626
# whether `f` is effect free if nothrow
627-
intrinsic_effect_free_if_nothrow(f) = f === Intrinsics.pointerref || is_pure_intrinsic_infer(f)
627+
intrinsic_effect_free_if_nothrow(f) = f === Intrinsics.pointerref ||
628+
f === Intrinsics.have_fma || is_pure_intrinsic_infer(f)
628629

629630
## Computing the cost of a function body
630631

base/compiler/tfuncs.jl

+4
Original file line numberDiff line numberDiff line change
@@ -1815,6 +1815,10 @@ function intrinsic_nothrow(f::IntrinsicFunction, argtypes::Array{Any, 1})
18151815
xty = widenconst(argtypes[2])
18161816
return isconcrete && isprimitivetype(ty) && isprimitivetype(xty)
18171817
end
1818+
if f === Intrinsics.have_fma
1819+
ty, isexact, isconcrete = instanceof_tfunc(argtypes[1])
1820+
return isconcrete && isprimitivetype(ty)
1821+
end
18181822
# The remaining intrinsics are math/bits/comparison intrinsics. They work on all
18191823
# primitive types of the same type.
18201824
isshift = f === shl_int || f === lshr_int || f === ashr_int

test/compiler/inline.jl

+4
Original file line numberDiff line numberDiff line change
@@ -880,3 +880,7 @@ end
880880
@test count(iscall((src,UnionAll)), src.code) == 0
881881
end
882882
end
883+
884+
# have_fma elimination inside ^
885+
f_pow() = ^(2.0, -1.0)
886+
@test fully_eliminated(f_pow, Tuple{})

0 commit comments

Comments
 (0)