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.
  • Loading branch information
oscardssmith committed Jul 15, 2022
1 parent 85b895b commit fd70eab
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 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: 3 additions & 1 deletion test/math.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1468,4 +1468,6 @@ for fn in (:sin, :cos, :tan, :log, :log2, :log10, :log1p, :exponent, :sqrt, :cbr
end
end
end
@test Core.Compiler.is_foldable(Base.infer_effects(^, (Float32,Int)))
for T in (Float32, Float64)
@test Core.Compiler.is_foldable(Base.infer_effects(^, (T,Int)))
end

0 comments on commit fd70eab

Please sign in to comment.