Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mark fastmath operations as not :consistent #46143

Merged
merged 1 commit into from
Aug 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
mark fastmath operations as not :consistent
We also need to mark `muladd` as not IPO-`:consistent, but it requires
to revive #31193 to preserve the currently available optimizations so
I left it as TODO for now.
  • Loading branch information
aviatesk committed Jul 23, 2022
commit 94f1071b6d18f70862bd7deeb456cae187444d67
32 changes: 25 additions & 7 deletions base/compiler/tfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1795,6 +1795,30 @@ const _CONSISTENT_BUILTINS = Any[
throw
]

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
]
Expand Down Expand Up @@ -2017,13 +2041,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)) ?
ALWAYS_TRUE : ALWAYS_FALSE
Expand Down
3 changes: 3 additions & 0 deletions test/compiler/effects.jl
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,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}
Expand Down