diff --git a/base/compiler/tfuncs.jl b/base/compiler/tfuncs.jl index d9649475f2a1d..241c41be8c723 100644 --- a/base/compiler/tfuncs.jl +++ b/base/compiler/tfuncs.jl @@ -1875,6 +1875,30 @@ const _ARGMEM_BUILTINS = Any[ swapfield!, ] +const _INCONSISTENT_INTRINSICS = Any[ + Intrinsics.pointerref, # this one is volatile + Intrinsics.arraylen, # this one is volatile + Intrinsics.sqrt_llvm_fast, # this one may differ at runtime (by a few ulps) + Intrinsics.have_fma, # this one depends on the runtime environment + Intrinsics.cglobal, # cglobal lookup answer changes at runtime + # ... and list fastmath intrinsics: + # join(string.("Intrinsics.", sort(filter(endswith("_fast")∘string, names(Core.Intrinsics)))), ",\n") + Intrinsics.add_float_fast, + Intrinsics.div_float_fast, + Intrinsics.eq_float_fast, + Intrinsics.le_float_fast, + Intrinsics.lt_float_fast, + Intrinsics.mul_float_fast, + Intrinsics.ne_float_fast, + Intrinsics.neg_float_fast, + Intrinsics.rem_float_fast, + Intrinsics.sqrt_llvm_fast, + Intrinsics.sub_float_fast + # TODO needs to revive #31193 to mark this as inconsistent to be accurate + # while preserving the currently optimizations for many math operations + # Intrinsics.muladd_float, # this is not interprocedurally consistent +] + const _SPECIAL_BUILTINS = Any[ Core._apply_iterate, ] @@ -2142,13 +2166,7 @@ function intrinsic_effects(f::IntrinsicFunction, argtypes::Vector{Any}) return Effects() end - consistent = !( - f === Intrinsics.pointerref || # this one is volatile - f === Intrinsics.arraylen || # this one is volatile - f === Intrinsics.sqrt_llvm_fast || # this one may differ at runtime (by a few ulps) - f === Intrinsics.have_fma || # this one depends on the runtime environment - f === Intrinsics.cglobal # cglobal lookup answer changes at runtime - ) ? ALWAYS_TRUE : ALWAYS_FALSE + consistent = contains_is(_INCONSISTENT_INTRINSICS, f) ? ALWAYS_FALSE : ALWAYS_TRUE effect_free = !(f === Intrinsics.pointerset) ? ALWAYS_TRUE : ALWAYS_FALSE nothrow = (!(!isempty(argtypes) && isvarargtype(argtypes[end])) && intrinsic_nothrow(f, argtypes)) diff --git a/test/compiler/effects.jl b/test/compiler/effects.jl index f6b8d2daf4087..bf28bd1c93f17 100644 --- a/test/compiler/effects.jl +++ b/test/compiler/effects.jl @@ -301,6 +301,9 @@ end |> !Core.Compiler.is_nothrow Core.svec(nothing, 1, "foo") end |> Core.Compiler.is_consistent +# fastmath operations are inconsistent +@test !Core.Compiler.is_consistent(Base.infer_effects((a,b)->@fastmath(a+b), (Float64,Float64))) + # issue 46122: @assume_effects for @ccall @test Base.infer_effects((Vector{Int},)) do a Base.@assume_effects :effect_free @ccall jl_array_ptr(a::Any)::Ptr{Int}