-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Move inlinability determination into cache transform #57979
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
Conversation
Compiler/src/optimize.jl
Outdated
function finishopt!(interp::AbstractInterpreter, opt::OptimizationState, | ||
ir::IRCode, caller::InferenceResult) |
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.
function finishopt!(interp::AbstractInterpreter, opt::OptimizationState, | |
ir::IRCode, caller::InferenceResult) | |
function finishopt!(::AbstractInterpreter, opt::OptimizationState, ir::IRCode) |
Compiler/src/optimize.jl
Outdated
@timeit "optimizer" ir = run_passes_ipo_safe(opt.src, opt) | ||
ipo_dataflow_analysis!(interp, opt, ir, caller) | ||
return finish(interp, opt, ir, caller) | ||
finishopt!(interp, opt, ir, caller) |
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.
finishopt!(interp, opt, ir, caller) | |
finishopt!(interp, opt, ir) |
Compiler/src/typeinfer.jl
Outdated
if !discard_src && codegen !== nothing && uncompressed !== nothing | ||
if !(uncompressed isa CodeInfo) | ||
uncompressed = ir_to_codeinf!(uncompressed) | ||
end |
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 wasn't sure why this part needed to be changed. Perhaps we could use inferred_result
here instead of uncompressed
? That way, if we properly define transform_result_for_cache
, it would also provide support for codegen_cache
.
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.
It is also now missing a check for isa CodeInfo, which may cause problems for other consumers
Compiler/src/typeinfer.jl
Outdated
if may_compress(interp) | ||
return ccall(:jl_compress_ir, String, (Any, Any), def, ci) |
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 transform is very expensive, why is it suddenly not conditional on being useful anymore?
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.
That case doesn't reach here anymore.
uncompressed = result.src | ||
const_flag = is_result_constabi_eligible(result) | ||
discard_src = caller.cache_mode === CACHE_MODE_NULL || const_flag | ||
if !discard_src |
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.
It looks like the implementation of everything after here assumes that transform_result_for_cache
returns a CodeInfo for correctness, and needs to be re-written
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.
It looks like debuginfo may still computed incorrectly on this part of the PR
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.
@serenity4 take a look?
Although independently it does now feel a bit weird from a dataflow perspective that the debuginfo that goes with the optimized source takes a different path.
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.
It would make more sense to me to take di = src.debuginfo
(where src::CodeInfo
is extracted from result.src::Union{CodeInfo, OptimizationState}
) and override it with what we can extract from inferred_result
(essentially doing the same logic as for result.src
).
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.
Perhaps something like that: serenity4@318b9a3
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've rebased this PR and cherry-picked your commit.
Digging into this, it seems that the inlining cost is expected to be set for the source Essentially I think the failures were related to the fact that although
the cache transformation code path may not be taken, and in that case we still need to determine inlineability of the source I have a working version locally, just needs some tree-shaking to see what are the minimally required changes. @Keno feel free to let me know if you'd like to apply the fix yourself and address review comments, or if I should take it from here (opening a new PR I guess). |
Was this PR motivated by a need to customize inlineability determination for |
The primary motivation was to nail down what amount of information needs to be in the cache if you don't use |
I see, I haven't looked into what piece of code required it particularly but will investigate with that perspective. |
Also, once we do figure that out, I think there is an independent investigation to be had as to why not inlining something leads to a miscompile. |
After taking a look I see that the only situation we need to set the inlining cost is when |
Yes, I think a |
Great, here is the diff between my branch and this PR if you'd like to have a look: kf/moveinlinemodel...serenity4:julia:kf/moveinlinemodel |
Excellent, seems to be working! I'll look into if I can figure out why we miscompile if we don't inline those. |
867c6dc
to
f3f6a55
Compare
I tried a bunch of things and found some other issues, but I can't figure out how to make it miscompile without just going back to the previous version. I think I'll leave it be at this point, although it is a bit mysterious. |
Thanks for taking a look, at least the additional fixes are always good to have. |
Currently the inlineability determination is in a bit of an odd spot - just after the optimizers while everything is still in IRCode. It seems more sensible to move this code into the cache transformation code, which is the first place that makes an actual decision based on inlineability. If an external AbstractInterpreter does not need to covert to CodeInfo for compilation purposes this also potentially saves that extra conversion. While we're at it, clean up some naming to deconflict it with other uses.
Jameson's were already addressed in previous commits
f3f6a55
to
e26a8a7
Compare
) * 2.17: Fix `.result` -> `.optresult` change for nightly * Bump version * Adjust to more changes from JuliaLang/julia/pull/57979 * Retrieve `interp` from `OptimizationState` --------- Co-authored-by: Cédric Belmant <[email protected]>
Restores dropping these after #57979
Restores dropping these after #57979
Currently the inlineability determination is in a bit of an odd spot - just after the optimizers while everything is still in IRCode. It seems more sensible to move this code into the cache transformation code, which is the first place that makes an actual decision based on inlineability. If an external AbstractInterpreter does not need to covert to CodeInfo for compilation purposes this also potentially saves that extra conversion. While we're at it, clean up some naming to deconflict it with other uses. --------- Co-authored-by: Cédric Belmant <[email protected]>
Restores dropping these after JuliaLang#57979
JuliaLang#58182) The point of JuliaLang#57979 was to make inference faster, but it made it instead much slower (JuliaLang@83524ac#commitcomment-155658124), so revert back to the fast behavior before it was "optimized" (and revert the bugfixes for the original commit).
JuliaLang#58203) Reverts JuliaLang#58182. The API changes were intentional and desirable. Let's figure out why nansoldier was upset and re-apply this. --------- Co-authored-by: Cédric Belmant <[email protected]>
JuliaLang#58182) The point of JuliaLang#57979 was to make inference faster, but it made it instead much slower (JuliaLang@83524ac#commitcomment-155658124), so revert back to the fast behavior before it was "optimized" (and revert the bugfixes for the original commit).
JuliaLang#58203) Reverts JuliaLang#58182. The API changes were intentional and desirable. Let's figure out why nansoldier was upset and re-apply this. --------- Co-authored-by: Cédric Belmant <[email protected]>
Currently the inlineability determination is in a bit of an odd spot - just after the optimizers while everything is still in IRCode. It seems more sensible to move this code into the cache transformation code, which is the first place that makes an actual decision based on inlineability. If an external AbstractInterpreter does not need to covert to CodeInfo for compilation purposes this also potentially saves that extra conversion. While we're at it, clean up some naming to deconflict it with other uses.