-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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: allow some aggressive inlines to go over budget #38163
Conversation
If we have a very small root method that calls a large method that is marked with AggressiveInlining, we may fail to inline because of a budget check. Allow such inlines to bypass the check. Closes dotnet#38106.
@erozenfeld PTAL cc @dotnet/jit-contrib Jit diffs shows 3 diffs, but they're spurious
|
Is there any cheap analysis we can do to know that the method is likely cheaper because the generic constraint is |
We might be able to heuristically recognize type-specializing opcode sequences and branching patterns during our initial IL scan/profitability check. At this level we would not know what methods get called and whether or not they are intrinsic. It would be pretty ad-hoc as we can't even do simple dataflow at that level today. Assuming we could guess right much of the time, we could "discount" the cost of the candidate to be the estimated cost of one of the branch cases plus the cost of any "unconditional" IL, and provisionally accept the inline. I have written heuristics like this in the past and they're tricky to get right without fairly strong models for control flow; we don't have that here either. Similar perhaps for size-specializing patterns. When we actually go to import the inlinee, if it then turned out we were wrong and things didn't simplify, we could reject then to keep code size small. But we'd have burned a fair bit of jit time and memory in the process. So the key would be to get good recognition accuracy, so that jit throughput is not unduly impacted by things that look promising but don't pan out. An alternative is to try and do this recognition either in the language compiler or in some other precompilation tool and just leave breadcrumbs for the jit. |
I'm assuming the JIT time is still a concern for Tier 1 optimizations? Perhaps its something we could leave a breadcrumb on from the initial Tier 0 pass? (Mostly just brainstorming here since its a fairly common pattern for things in numerics land and will impact new things like In either case, I think this will cover the major scenarios around the issue file, so 👍 from me. However, I was wondering for a case like the following,
|
Yeah, not a bad idea. Assuming we start doing intrinsic recognition and opts in Tier0 (which I think is a reasonable idea) then we'd know for sure which methods simplified and roughly by how much. We don't have a general way for Tier0 to feed info to Tier1 currently, but we can work on that in a manner similar to how OSR does things.
I'll look into a case like that -- once we've inlined Method1 the budget expands (see Another option here is to follow the pattern suggested in |
Yeah bool M<T1,T2>() => typeof(T1) == typeof(T2); ^ is 3 calls ( |
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.
LGTM
Co-authored-by: bradmarder <[email protected]>
I suspect this PR has caused new failures like (jitstress=1):
see https://dev.azure.com/dnceng/public/_build/results?buildId=701636&view=ms.vss-test-web.build-test-results-tab&runId=21759702&paneView=debug&resultId=105581 for more examples. |
Suspect the random policy needs a tweak; I'll take a look. |
In dotnet#38163 I added a depth field to one of the inline policy base classes. A derived class already had a similar field. Unify in favor of the base class field. The inline policies implemented by these derived policy classes are sometimes used during jit stress (eg for random inlining). Fixes dotnet#38374.
If we have a very small root method that calls a large method that is marked with
AggressiveInlining, we may fail to inline because of a budget check.
Allow such inlines to bypass the check.
Closes #38106.