Skip to content

Commit

Permalink
inference: fix #41450, replace constant-folded muladd with fma
Browse files Browse the repository at this point in the history
So that we can get more accurate results when performance doesn't matter
  • Loading branch information
aviatesk committed Jul 13, 2021
1 parent e422467 commit 6e367fa
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
5 changes: 5 additions & 0 deletions base/compiler/tfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1522,6 +1522,11 @@ function builtin_tfunction(interp::AbstractInterpreter, @nospecialize(f), argtyp
if isa(f, IntrinsicFunction)
if is_pure_intrinsic_infer(f) && _all(@nospecialize(a) -> isa(a, Const), argtypes)
argvals = anymap(a::Const -> a.val, argtypes)
# https://github.com/JuliaLang/julia/issues/41450
# enforce no rounding for better accuracy
if f === muladd_float
f = fma_float
end
try
return Const(f(argvals...))
catch
Expand Down
6 changes: 6 additions & 0 deletions test/compiler/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3395,3 +3395,9 @@ end
x.x
end) == Any[Int]
end

# https://github.com/JuliaLang/julia/issues/41450
@test (@eval Module() begin
foo(x=1.0) = muladd(1 + eps(x), 1 - eps(x), -1)
foo() == foo(1.0)
end)
3 changes: 1 addition & 2 deletions test/mpfr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -606,8 +606,7 @@ end
@test log(x) == log(42)
@test isinf(log(BigFloat(0)))
@test_throws DomainError log(BigFloat(-1))
# issue #41450
@test_skip log2(x) == log2(42)
@test log2(x) == log2(42)
@test isinf(log2(BigFloat(0)))
@test_throws DomainError log2(BigFloat(-1))
@test log10(x) == log10(42)
Expand Down

0 comments on commit 6e367fa

Please sign in to comment.