-
-
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
[NewOptimizer] Union Split during Inlining #26900
Conversation
opt_check_bounds == 0 && return :default | ||
opt_check_bounds == 1 && return :on | ||
return :off | ||
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.
editor issue?
base/compiler/ssair/inlining2.jl
Outdated
case === nothing | ||
@assert !isa(metharg, UnionAll) | ||
cond = true | ||
for (i, (a, m)) in Iterators.drop(enumerate(zip(atype.parameters, metharg.parameters)), 1) |
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.
don't put Types in Tuples
base/compiler/ssair/inlining2.jl
Outdated
return_value | ||
end | ||
|
||
function ir_inline_unionsplit!(compact, idx, argexprs, linetable, item, boundscheck, todo_bbs) |
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.
annotate your argument types
base/compiler/ssair/inlining2.jl
Outdated
cond = insert_node_here!(compact, and_expr, Bool, line) | ||
end | ||
end | ||
atype = typesubtract(atype, metharg) |
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.
attempting this operation is wrong, although since atype
is a DataType, it's at least a no-op
base/compiler/ssair/inlining2.jl
Outdated
has_generic = false | ||
@assert length(item.bbs) > length(item.cases) | ||
for ((metharg, case), next_cond_bb) in zip(item.cases, item.bbs) | ||
case === nothing |
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.
dead code
base/compiler/ssair/inlining2.jl
Outdated
val = ir_inline_item!(compact, idx, argexprs, linetable, case, boundscheck, todo_bbs) | ||
elseif isa(case, MethodInstance) | ||
# Make it an Expr(:invoke) | ||
error() |
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.
need to fix error()
this
base/compiler/ssair/inlining2.jl
Outdated
elseif isa(case, ConstantCase) | ||
val = case.val | ||
else | ||
error() |
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.
need to fix this
2cfee6c
to
6a6b96e
Compare
I've been running this branch locally and it seems to work fine, so I'm planning to merge this in a bit. As always comments are still open afterwards. |
Seems like this design will probably regress our ability to do union-splitting a bit (this can only handle cases that intersect to create dispatch tuples, while the approach of the existing code can handle more general cases with fewer |
base/compiler/ssair/inlining2.jl
Outdated
isa(methsp[i], TypeVar) && return nothing | ||
end | ||
|
||
# Find the linfo for this methods (Generated functions are expanded here if necessary) |
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 hope not: the last parameter (true
) means "do not expand generated functions"
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.
Right, we discussed that on a past review. I'll separately fix the comment.
ast = copy_exprargs(inferred.code) | ||
else | ||
src = ccall(:jl_uncompress_ast, Any, (Any, Any), method, inferred::Vector{UInt8})::CodeInfo | ||
# TODO: It seems like PhiNodes are shared between compressed codeinfos, making this copy necessary |
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 is a serious bug with the serializer, if (still) true
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 suspect this got fixed.
base/compiler/ssair/inlining2.jl
Outdated
found_any = false | ||
for (i, match) in enumerate(meth) | ||
(metharg, methsp, method) = (match[1]::Type, match[2]::SimpleVector, match[3]::Method) | ||
metharg′ <: metharg || continue |
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.
type-intersect
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.
Isn't that equivalent, since metharg′
is a dispatch tuple?
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.
ah yes, although note that metharg
is not relevant to whether the method will actually match at runtime
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 you elaborate that statement?
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.
metharg is typeintersect(method.sig, atypes)
, so it's unpredictable whether it's method.sig
, atypes
, or something wider or narrower. basically, just assume that it's Tuple
and you should be OK.
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.
Ok, so should that be method.sig on the RHS of this check then?
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.
yeah, that should work
Examples of which cases you don't like with the new behavior would be good. Last time we discussed this you and @JeffBezanson told me that you'd prefer to go through the dynamic dispatch for everything that's not a dispatchtuple. In any case, we can do all of that later. |
We'd like to also be able to generate direct calls in the presence of |
This adds union splitting optimizations to the inliner. This works a bit differently from the old optimizer, which did union splitting on the bail out path. Instead, we try to run the full inliner on any union split case that's a dispatch tuple (and record what to do in that case). Doing that allows an effective resolution of #23338, though this PR doesn't quite do that yet, since some further (minor) fixes are needed.
This adds union splitting optimizations to the inliner.
This works a bit differently from the old optimizer, which
did union splitting on the bail out path. Instead, we try
to run the full inliner on any union split case that's a
dispatch tuple (and record what to do in that case). Doing
that allows an effective resolution of #23338, though this
PR doesn't quite do that yet, since some further (minor) fixes
are needed.