Skip to content

Commit

Permalink
Merge pull request #38034 from JuliaLang/tb/fast_half
Browse files Browse the repository at this point in the history
Let Float16 participate in at-fastmath.
  • Loading branch information
maleadt authored Oct 16, 2020
2 parents 995002a + 966f2a7 commit 389d819
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion base/fastmath.jl
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ end

# Basic arithmetic

const FloatTypes = Union{Float32,Float64}
const FloatTypes = Union{Float16,Float32,Float64}

sub_fast(x::FloatTypes) = neg_float_fast(x)

Expand Down
5 changes: 5 additions & 0 deletions src/llvm-demote-float16.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ bool DemoteFloat16Pass::runOnFunction(Function &F)
continue;
}

// skip @fastmath operations
// TODO: more fine-grained check (afn?)
if (I.isFast())
continue;

IRBuilder<> builder(&I);

// extend Float16 operands to Float32
Expand Down
16 changes: 16 additions & 0 deletions test/llvmpasses/fastmath.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,19 @@ import Base.FastMath

# CHECK: call fast float @llvm.sqrt.f32(float %0)
emit(FastMath.sqrt_fast, Float32)


# Float16 operations should be performed as Float32, unless @fastmath is specified
# TODO: this is not true for platforms that natively support Float16

foo(x::T,y::T) where T = x-y == zero(T)
# LOWER: fsub half %0, %1
# FINAL: %2 = fpext half %0 to float
# FINAL: %3 = fpext half %1 to float
# FINAL: fsub half %2, %3
emit(foo, Float16, Float16)

@fastmath foo(x::T,y::T) where T = x-y == zero(T)
# LOWER: fsub fast half %0, %1
# FINAL: fsub fast half %0, %1
emit(foo, Float16, Float16)

0 comments on commit 389d819

Please sign in to comment.