-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
floating point div
differs in optimized code
#14089
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
Comments
That looks like constant folding to me: julia> @code_llvm f()
define double @julia_f_21524() {
top:
%0 = call double @llvm.rint.f64(double 3.000000e+01)
ret double %0
} compared to julia> f(x, y) = x ÷ y
f (generic function with 2 methods)
julia> f(0.3, 0.01)
29.0
julia> @code_llvm f(0.3, 0.01)
define double @julia_f_21540(double, double) {
top:
%2 = frem double %0, %1
%3 = fsub double %0, %2
%4 = fdiv double %3, %1
%5 = call double @llvm.rint.f64(double %4)
ret double %5
} |
julia> rem(0.3, 0.01)
0.009999999999999983
julia> f() = rem(0.3, 0.01)
f (generic function with 1 method)
julia> f()
0.0 |
And seems like a LLVM bug (unless we are optimizing julia> function k()
Base.llvmcall("""
%1 = frem double 3.000000e-01, 1.000000e-02
ret double %1
""", Float64, Tuple{})
end
k (generic function with 1 method)
julia> @code_llvm k()
define double @julia_k_22866() #0 {
top:
ret double 0.000000e+00
}
julia> k()
0.0
julia> function k2(a, b)
Base.llvmcall("""
%3 = frem double %0, %1
ret double %3
""", Float64, Tuple{Float64,Float64}, a, b)
end
k2 (generic function with 1 method)
julia> @code_llvm k2(0.3, 0.01)
define double @julia_k2_22867(double, double) #0 {
top:
%2 = frem double %0, %1
ret double %2
}
julia> k2(0.3, 0.01)
0.009999999999999983 |
Also seems to happen on llvm-svn. |
Possibly related: https://llvm.org/bugs/show_bug.cgi?id=3316 |
Still happens. |
I've reopened the upstream issue with an example. |
Okay, I've put together a fix here: simonbyrne/llvm@2718254 @Keno how do I go about actually getting this into LLVM? |
Paste your diff here: https://reviews.llvm.org/differential/diff/create/ (Ideally with |
Submitted here: https://reviews.llvm.org/D29346 |
Found you some reviewers. Lets hope they know what they're doing. |
Now fixed upstream: llvm-mirror/llvm@872b505 |
Do we want to carry that patch, rebased for LLVM 3.9 if necessary? Have our tests just been working around this? |
I think we've just been ignoring it, since it is a pretty weird edge case (calling |
When will the fix to llvm be out then ? julia> div(1,0.2)
4.0 Should be 5.
Will the |
0.2 can't be represented exactly as a binary floating point value, so it's reasonable for 2.999998 is not an integer so Further discussion about the nature of floating point arithmetics should go on the Discourse forum since it's off-topic for this particular issue. |
This is not random, however: there is only one |
Also, fix is now in master, so can be closed. |
Master of Julia, or only master of llvm? Is it tested, if fixed here? |
Ah, I forgot I had compiled with LLVM-svn. |
Fixed in release now. |
I ran into this trying to get tests to pass on jb/functions. Also happens on master:
The text was updated successfully, but these errors were encountered: