julia
julia copied to clipboard
Make DemoteFloat16 a conditional pass
Attempt at #40216 For now it's just an if statement, which might be enough. I wasn't sure if the check should be inside the pass or if the pass should be conditional. For now it's outside it.
julia> a = Float16(1)
Float16(1.0)
julia> b = Float16(2)
Float16(2.0)
julia> f(a,b) = a + b
f (generic function with 1 method)
#before
@code_llvm f(a,b)
; @ REPL[4]:1 within `f`
define half @julia_f_127(half %0, half %1) #0 {
top:
; ┌ @ float.jl:397 within `+`
%2 = fpext half %0 to float
%3 = fpext half %1 to float
%4 = fadd float %2, %3
%5 = fptrunc float %4 to half
; └
ret half %5
}
julia> @btime sum(x) setup = x = rand(Float16,100000)
56.083 μs (0 allocations: 0 bytes)
Float16(5.002e4)
#after
julia> @code_llvm f(a,b)
; @ REPL[5]:1 within `f`
define half @julia_f_155(half %0, half %1) #0 {
top:
; ┌ @ float.jl:397 within `+`
%2 = fadd half %0, %1
; └
ret half %2
}
julia> @btime sum(x) setup = x = rand(Float16,100000)
4.018 μs (0 allocations: 0 bytes)
Float16(4.992e4)
For this to work on the m1 #41924 needs to be merged
This needs to integrate with multiversioning so that we can create a sysimage in which this is enabled and disabled and then loaded conditionally https://github.com/JuliaLang/julia/issues/40216#issuecomment-809612778
The multiversioning stuff is a bit out of my water so what I did was kind of pattern matching.
Bump :)