-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
f() = 2^5
not compiled all the way to result
#30126
Comments
Slightly better on master, but inference's purity analysis should be able to just figure this out. |
Is there any update? On my system, I get nice results of julia> versioninfo()
Julia Version 1.5.0-beta1.0
Commit 6443f6c95a (2020-05-28 17:42 UTC)
Platform Info:
OS: Linux (x86_64-pc-linux-gnu)
CPU: Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-9.0.1 (ORCJIT, skylake)
Environment:
JULIA_NUM_THREADS = 1
julia> foo(x) = x^4
foo (generic function with 1 method)
julia> @code_llvm foo(5.0)
; @ REPL[24]:1 within `foo'
define double @julia_foo_3022(double) {
top:
; ┌ @ intfuncs.jl:300 within `literal_pow'
; │┌ @ math.jl:905 within `^'
%1 = call double @llvm.pow.f64(double %0, double 4.000000e+00)
; └└
ret double %1
}
julia> bar(x) = (x^2)^2
bar (generic function with 1 method)
julia> @code_llvm bar(5.0)
; @ REPL[26]:1 within `bar'
define double @julia_bar_3030(double) {
top:
; ┌ @ intfuncs.jl:296 within `literal_pow'
; │┌ @ float.jl:405 within `*'
%1 = fmul double %0, %0
%2 = fmul double %1, %1
; └└
ret double %2
}
julia> using BenchmarkTools
julia> @benchmark foo($(Ref(5.0))[])
BenchmarkTools.Trial:
memory estimate: 0 bytes
allocs estimate: 0
--------------
minimum time: 11.585 ns (0.00% GC)
median time: 12.096 ns (0.00% GC)
mean time: 12.148 ns (0.00% GC)
maximum time: 41.651 ns (0.00% GC)
--------------
samples: 10000
evals/sample: 999
julia> @benchmark bar($(Ref(5.0))[])
BenchmarkTools.Trial:
memory estimate: 0 bytes
allocs estimate: 0
--------------
minimum time: 1.057 ns (0.00% GC)
median time: 1.058 ns (0.00% GC)
mean time: 1.061 ns (0.00% GC)
maximum time: 4.052 ns (0.00% GC)
--------------
samples: 10000
evals/sample: 1000 In mathematical code, it is quite handy to be able to write |
@ranocha That is a different issue. That's because |
Fixed on master (presumably #45613) |
Have a look at:
This behaviour is weird. Since the result is completely fixed, shouldn't it compile all the way down to "return this predefined number" instead of requiring a new function call?
To make things weirder, the following functions do compile down to "return this number":
m() = 2^8; n() = 3^4; g() = 2.0^5; h() = 2^5.0, k() = 1<<5
In practice, this means that running
k()
is unnecessarily ~3x faster thanf()
. Is this a bug that should be fixed?Environment:
The text was updated successfully, but these errors were encountered: