-
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 code optimization inconsistency #51587
Comments
Same issue as in #41692. The method is large (~900+ bytes of IL) and runs afoul of the budget check.
|
… opportunities Look for IL patterns in an inlinee that are indicative of type folding. Also track when an inlinee has calls that are intrinsics. Use this to boost the inlinee profitability estimate. Also, allow an aggressive inline inline candidate method to go over the budget when it contains type folding or intrinsics (and so the method may be simpler than it appears). Remove the old criteria (top-level inline) which was harder to reason about. Closes dotnet#43761. Closes dotnet#41692. Closes dotnet#51587. Closes dotnet#47434.
@EgorBo perhaps you can follow up here? |
Seems like we should now have the extended default policy override One way to model this is to try and guestimate the effective IL size up front, and just use that for the existing budget check: assume each foldable reduces the amount of IL by some fixed heuristic fraction f. Then if there are N foldables, the effective IL size is something like (1 - f)^N. So, for instance, with IL size of 100, 3 foldables, f = 0.25; we'd have effective IL size of 100 * (1 - 0.25) ^ 3 = 42. (Note we don't have a flow based model to project how much each folding opportunity would "save" in terms of imported IL, and building such models is somewhat tricky). Another option would be to keep the budget check as is but allow going over budget under more conditions, related to the relative amount of foldables per byte of IL, or some other similar measure. |
That is exactly what I wanted to try, I just didn't include it in my pr because "run out of budget" didn't pop up in TE benchmarks for me, but still worth doing of course. Without analyzing the IL, we can at least count on "NonGeneric calls Generic" and const arg is passed. |
Not sure we're going to get to this in 6.0. So moving to future. |
Description
Whenever we have a type switch in a method, and the type is known compile-time, then the wrong cases get jitted away.
Indeed this happens for the following implementations:
JIT code:
AddIfs
properly gets inlined,AddSwitch
does not.Version using
AddIfs
:Version using
AddSwitch
:The complete example can be found in SharpLab in the following link: Click me
Expected behavior:
both get inlined.
The text was updated successfully, but these errors were encountered: