Skip to content

Commit

Permalink
mark two_mul as consistent (#46022)
Browse files Browse the repository at this point in the history
should let the compiler prove that float64^int always gives the same result.

(cherry picked from commit fd70eab)
  • Loading branch information
oscardssmith authored and KristofferC committed Jul 20, 2022
1 parent 6d7539b commit d6e8e5d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions base/math.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ end

# non-type specific math functions

@inline function two_mul(x::Float64, y::Float64)
@assume_effects :consistent @inline function two_mul(x::Float64, y::Float64)
if Core.Intrinsics.have_fma(Float64)
xy = x*y
return xy, fma(x, y, -xy)
end
return Base.twomul(x,y)
end

@inline function two_mul(x::T, y::T) where T<: Union{Float16, Float32}
@assume_effects :consistent @inline function two_mul(x::T, y::T) where T<: Union{Float16, Float32}
if Core.Intrinsics.have_fma(T)
xy = x*y
return xy, fma(x, y, -xy)
Expand Down
4 changes: 4 additions & 0 deletions test/math.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1421,3 +1421,7 @@ end
# the compiler ever gets good enough to figure
# that out by itself, move this to inference).
@test code_typed(x->Val{x^0.0}(), Tuple{Float64})[1][2] == Val{1.0}

for T in (Float32, Float64)
@test Core.Compiler.is_foldable(Base.infer_effects(^, (T,Int)))
end

0 comments on commit d6e8e5d

Please sign in to comment.