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
Implement alias scopes #31018
Implement alias scopes #31018
Conversation
@maleadt we should probably talk about how we could extend this for CUDAnative. Right now it is based on a compiler intrinsic. Thanks Yingbo, for hacking on this together! |
7806396
to
9a0c203
Compare
std::vector<MDNode*> scope_list_stack; | ||
{ | ||
size_t nstmts = jl_array_len(src->code); | ||
aliasscopes.resize(nstmts + 1, nullptr); |
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.
This block and the for-loop the part that Yingbo and I were the most unsure about. We mimicked the + 1
from the linetable construct above.
current_aliasscope = scope_list_stack.back(); | ||
} | ||
} | ||
aliasscopes[i+1] = current_aliasscope; |
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.
Same with the +1
here.
4059af7
to
63fe6cf
Compare
src/builtins.c
Outdated
@@ -1210,6 +1215,7 @@ void jl_init_primitives(void) JL_GC_DISABLED | |||
|
|||
// array primitives | |||
add_builtin_func("arrayref", jl_f_arrayref); | |||
add_builtin_func("const_arrayref", jl_f_const_arrayref); |
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.
could just call
jl_f_arrayref
here?
FWIW, I remain unconvinced that this is the correct long-term solution, but I of course recognize the short term utility here, so we should perhaps figure out a way to expose this without boxing ourself in with this as a support API (e.g. perhaps add the intrinsics, but only add the supporting definitions in a package that is explicitly disclaimed as unsupported). |
I agree with that, this "feels" a bit odd and I wouldn't want us to have to live with it forever. Right now this PR is relatively minimal and doesn't expose anything besides the AST nodes and the intrinsic. |
It seems very naively to me like what might be needed is the ability to tell the compiler that this is a good point to check if a set of arrays alias each other and allow the compiler to generate code assuming both positive and negative results. That way you get fast behavior in the good case and correct behavior no matter what. |
This is what LLVM does under the hood right now. Sometimes it fails because it can't infer the array bounds (so doing it at the Julia level might help) and sometimes you want to avoid the code size increase. We have |
Co-authored-by: Keno Fischer <kfischer@college.harvard.edu> Co-authored-by: Yingbo Ma <mayingbo5@gmail.com> Co-authored-by: Valentin Churavy <v.churavy@gmail.com>
63fe6cf
to
53405a4
Compare
The CI error seems unrelated
|
@Keno are you okay with merging this as is? |
Question: is this change purely internal or is it a public API? It doesn't add or change any exports, so I'm assuming it's internal not public. In that case, it seems fine to merge it as an experimental feature to learn how to deal with aliasing better. |
I'm ok with this on the understanding that it will definitely go away in the future. |
Completely internal and all I interested parties are okay with this going away :) |
This PR is based on the original PR #20257 by @Keno.
CC: @vchuravy