-
-
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
propagate inbounds in a few more places for memoryref #56151
base: master
Are you sure you want to change the base?
Conversation
Thanks for looking into this! However on this branch with function f!(v)
for idx in eachindex(v)
v[idx] = 1.0
end
end
code_llvm(f!, (Memory{Float64},)) I still see boundschecking branches, which aren't there with code_llvm(f!, (Vector{Float64},)) However |
So one thing I don't understand is why |
First note: The issue @giordano is seeing is not due to So Memory does a fair bit more complicated check than Vector... For array:
For
My hypothesis is that likely somethhing with the overflow and byte length is tripping LLVM up:
|
When I last looked at it, my understanding was that the only difference is that |
One possible approach is to remove the boundscheck from the memoryref* intrinsics and make them the responsibility of Julia. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SGTM. Though I also agree with Oscar that it may make sense to make this intrinsic specify that OOB access is always UB for the intrinsic itself, then apply no-ub
as a function attribute around it when known to be absolutely safe?
return A | ||
end | ||
|
||
function setindex!(A::Memory{T}, x, i1::Int, i2::Int, I::Int...) where {T} | ||
@inline | ||
@_propagate_inbounds_meta |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this is a silly question, but does the @inbounds if destp < srcp || destp > endp
above (in unsafe_copyto!
) apply @inbounds
to the else
branch, too? Also, shouldn't the inbounds/prop inbounds pattern be applied to getindex
, too?
874bc4a
to
e1205b1
Compare
e1205b1
to
c7cd406
Compare
It took me three attempts, but I think now I managed to rebase this PR correctly 🙂 |
@@ -281,7 +281,7 @@ the same manner as C. | |||
""" | |||
function unsafe_copyto!(dest::Array, doffs, src::Array, soffs, n) | |||
n == 0 && return dest | |||
unsafe_copyto!(memoryref(dest.ref, doffs), memoryref(src.ref, soffs), n) | |||
@inbounds unsafe_copyto!(memoryref(dest.ref, doffs), memoryref(src.ref, soffs), n) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is correct.
memoryref(A, ind)
does an internal boundscheck and if we want@inbounds
to ellide all boundscheckwe must use
@propagate_inbounds
.Follow-up to #55902