Enable allocation hoisting out of loops#43057
Conversation
|
Just as a note, it would be nice with example codes that now optimize with this and potentially benchmarks. As well as perhaps some checks on potential regressions in compile time. |
Example - loop deletionFunction:julia-master: https://godbolt.org/z/Po1cb8bYP -- the IR retains the loop through 1:N and keeps the allocation throughout (O(N)) |
Compile time regressions:julia-masterpost-PRSeems like it's approximately equivalent in terms of compile time. |
So array allocations and object allocations are treated differently. Object allocations are converted to a julia.gc_alloc_obj function which eventually gets lowered to another allocation function as necessary. Array allocations, on the other hand, delegate to one of 4 functions (definitions in Base/boot.jl and src/array.c) for 1D, 2D, 3D, and ND array allocations respectively. Those array allocations are implemented as direct ccalls, which means they aren't currently handled by any escape analysis, SROA, or allocation optimization in general. I'm separately looking into possible ways to also optimize array allocations in similar ways, but that's a much larger change. |
|
551e766 to
7c29406
Compare
vchuravy
left a comment
There was a problem hiding this comment.
Can you add tests that exercise the change in llvm-julia-licm? Preferable in llvmpasses?
7c29406 to
5d9d5e0
Compare
5d9d5e0 to
9805d57
Compare
|
@nanosoldier |
|
Your package evaluation job has completed - possible new issues were detected. A full report can be found here. |
|
@nanosoldier |
|
Something went wrong when running your job: |
|
AWS failure. @nanosoldier |
|
Your package evaluation job has completed - possible new issues were detected. A full report can be found here. |
9805d57 to
b9a9c13
Compare
|
@nanosoldier |
|
@nanosoldier |
|
If nanosoldier comes back happy I am going to merge this this week. |
36abcf3 to
29ae1a1
Compare
Co-authored-by: Shuhei Kadowaki <40514306+aviatesk@users.noreply.github.com>
|
@nanosoldier |
|
@nanosoldier |
|
Your package evaluation job has completed - possible new issues were detected. A full report can be found here. |
|
Something went wrong when running your job: Unfortunately, the logs could not be uploaded. |
|
🎉 |
| jl_alloc::runEscapeAnalysis(call, required, jl_alloc::EscapeAnalysisOptionalArgs().with_valid_set(&L->getBlocksSet())); | ||
| if (use_info.escaped || use_info.addrescaped) { |
There was a problem hiding this comment.
Just an observation: this is depending on more than just escape analysis results, but also is depending on the absence of loop-carried dependencies. Currently, runEscapeAnalysis has no handling implemented for PhiNode, so it looks like it is correct, but if the escape-analysis ever gains the ability to look at the function CFG, we need to fix this usage.
This partially reverts commit 4c45f29.
This partially reverts commit 4c45f29.
Allocations in loops which escape outside of the loop can prevent further optimization of the loop. By eliminating those allocations, we can both reduce memory pressure and enable further loop optimizations.
This PR also separates the escape analysis framework from alloc-opt into its own file and refactors it, which allows it to be called from other passes and be more configurable.