-
-
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
range function not eliding with constant arguments #35022
Comments
I don't think this will be optimized easily, many things are not inlined. Your
then steprangelen_hp does not inline
etc etc. It's just very complex code. Maybe @timholy can comment on whether it could be simplified to make it easier on the compiler. |
What are you doing with the range inside your loop? Why would you expect this to get elided? Edit: Oh, I think you're after constant propagation to move the constructor to compile-time? |
I don't think we need a separate issue for every function / constructor that doesn't constant propagate. |
Maybe it's not so much about constant propagation, but about the complexity of the range constructor?
Probably if the range function was more trivial (it's very niche) |
Ah, the words you're after there are LICM (loop-invariant code motion) or hoisting. |
Ref #26770. |
I guess the thing that catches me off guard is that those are all literals and
Fair enough, feel free to close if this is inappropriate. |
It's complicated because some people really want exact arithmetic. Use julia> collect(-0.1:0.1:0.3)
5-element Array{Float64,1}:
-0.1
0.0
0.1
0.2
0.3
julia> collect(LinRange(-0.1, 0.3, 5))
5-element Array{Float64,1}:
-0.1
-1.3877787807814457e-17
0.09999999999999999
0.19999999999999998
0.3 |
I've tried this on the master branch and
1.4.2-rc2
. I'd expect this function call to be completely elided, but it's not which can induce a pretty hefty performance cost sometimes in hot loops.I wonder if there's anything we can do to make this infer more easily.
@haampie on Slack tracked the problem down to
function Base._linspace(::Type{T}, start_n::Integer, stop_n::Integer, len::Integer, den::Integer) where T<:IEEEFloat
which he speculated is overwhelming the optimizer with its very complex logic.The text was updated successfully, but these errors were encountered: