-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
add LoopInfo + LICM #36832
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
base: master
Are you sure you want to change the base?
add LoopInfo + LICM #36832
Conversation
With this PR:
turns into:
Instead of:
|
For sure. Though I wouldn't use one to replace the other as long as we still uses any LLVM loop passes. In the llvm pass, I'm counting on LLVM LICM to hoist some generation of the pointer value out of the loop (e.g. loading from a array/object that is loop invariant). Also, there are some julia specific LICM that can only be done at LLVM level, including everything GC/allocation related. It can certainly be done in julia code in the future but it'll require a much lower level IR. |
Also, I feel like it wouldn't hurt to mark some functions that are believed to be "pure"/LICM safe with some custom metadata so that our own LLVM pass can pick it up. |
FWIW, the issue was that many of our uses of |
I’m not really commenting on what is safe to LICM, I just mean that whatever identified here as safe should also be safe to do so in llvm. I assume there isn't a case where the code is safe to licm in Julia but not in llvm? |
Co-authored-by: Ian Atol <[email protected]>
Co-authored-by: Shuhei Kadowaki <[email protected]>
Co-authored-by: Shuhei Kadowaki <[email protected]>
Now that we have effect analysis this is now feasible and thanks #45305 added the gnarly details of how to do CFG manipulations. Still some details to figure out, in particular how to deal with loop-nests and multiple loops in a function since the act of mutating the CFG invalidates the collect loop information. Also need to check multiple invariant statements doing the right thing. Developed this out-of-tree in https://github.com/vchuravy/Loops.jl and https://vchuravy.dev/talks/licm/ Will fix the long-standing #29285 |
In recent discussion as well as in the past the topic came up that LLVM LICM pass is currently not effectual for calls to Julia code and Julia specific constructs. In #36786 (comment) I explained my understanding that we don't need to change the semantics of math functions to enable LICM. In general it seems that informing LLVM about the pureness of Julia functions might not be valid (#29566 (comment), #32368) since Julia and LLVM have differing definitions, this will fixe #29285
We could also do #36809 (Custom-LICM pass for
GC.@preserve
on the LLVM level) as part of this pass.In order to make this more useful we might want to track more properties of Julia methods. For simplicity for now I have limited myself to
@pure
functions.TODO:
cc: @yhls, @jpsamaroo
@timholy Together with a Loop Induction Variables deduction pass the loopinfo pass could be used to implement #35074 without special casing
CartesianIndices
I am putting this up mostly to get help with figuring out the CFG manipulation part. I looked through inlining, but it seems we could make the insertion of BBs an independent util.