From fd70eabc1dd6c79149edb82da9e9c37d89e249d9 Mon Sep 17 00:00:00 2001 From: Oscar Smith Date: Thu, 14 Jul 2022 21:39:32 -0700 Subject: [PATCH] mark two_mul as consistent (#46022) should let the compiler prove that float64^int always gives the same result. --- base/math.jl | 4 ++-- test/math.jl | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/base/math.jl b/base/math.jl index 5616721edff50..af193f996dbf5 100644 --- a/base/math.jl +++ b/base/math.jl @@ -42,7 +42,7 @@ 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) @@ -50,7 +50,7 @@ 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) diff --git a/test/math.jl b/test/math.jl index 8938b6a8864ab..d788e0c939a05 100644 --- a/test/math.jl +++ b/test/math.jl @@ -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