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
JIT: consider doing some type opts earlier #7815
Comments
We abuse inlining + constrained non-ref types a lots. Would give us a huge boost if it able to catch some of the methods that are currently non inlineable!! |
Did some initial prototyping to refactor the type equality optimizations so they can be run during importation (right now they're embedded in morph). There are two main optimizations:
See master...AndyAyersMS:EarlyTypeOpt However during importation we're only opportunistically folding a small subset of trees as we build them, and the folding is done via At any rate, unless we arrange to aggressively or opportunistically fold subtrees, higher level folding may be blocked because subtrees haven't been simplified. In particular if we push both the folding optimizations above forward, we still miss early folding in cases like: static bool IsInt<T>()
{
if (typeof(T) == typeof(int))
{
return true;
}
else
{
return false;
}
}
IsInt<int>(); Because we only fold trees at conditional branches, we end up trying to fold a tree like the following:
and top-down folding doesn't simplify this case, since it does not recurse down and simplify the call. Also if we don't fold during importation in expression contexts we miss out on early folding for non-branch cases like static bool IsInt<T>()
{
return (typeof(T) == typeof(int));
} The upshot is that it might be interesting and worthwhile to invoke folding much more frequently during importation, to prune subtrees sooner and to enable knock-on effects. |
The changes in dotnet/coreclr#14244 add some selective eager folding for type equality tests. We still can't optimize cases where one of the types comes from a runtime lookup: static bool IsInt<T>()
{
return (typeof(T) == typeof(int));
}
static bool IsString<T>()
{
return (typeof(T) == typeof(string));
}
|
dotnet/coreclr#14317 can optimize the |
I've often wondered if there could be an option to configure that with a form of So code like The example is more complex as its via an interface |
All this may be particularly relevant for improving the speed of a Tier0 jit. Presumably prejitting has punted on most generic cases and those are the ones amenable to fairly radical jit-time simplification via early type opts, so enabling those opts in Tier0 would seem to hit a sweet spot. |
The jit should now be able to optimize many of the common type specialization checks during importation. Since the jit can also do some rudimentary branch opts during importation, early type specialization check optimization would allow the jit to skip importing chunks of IL guarded by type checks that are known to fail.
For example consider any non-intrinsic vector method, eg
Vector<T>:op_Multiply
. SinceT
is constrained to non-ref types this method's instantiation parameter is always a known class at jit time. So roughly 90% of the IL in this method is unreachable by any particular instantiation and doesn't need to be imported.This should provide a throughput boost. It might also make it easier for the jit to consider inlining such methods, because the jit can more accurately assess the "true" size of the method.
category:throughput
theme:importer
skill-level:expert
cost:medium
The text was updated successfully, but these errors were encountered: