Skip to content
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: Switch StaysWithinManagedObject to peel offsets from VNs #105169

Merged

Conversation

jakobbotsch
Copy link
Member

@jakobbotsch jakobbotsch commented Jul 19, 2024

The SCEV analysis does not care about the value of something once it is seen to be invariant inside the loop we are currently analyzing. This was problematic for this logic that tries to peel offsets away from an array; for arm64, we may have hoisted array + 0x10 outside the loop, which would cause us to fail to get back to the base array.

Switch the reasoning to use VNs and peel the offsets from the VNs instead.

No x64 diffs are expected as we do not hoist the array + 0x10 out of the loop there. Improvements expected on arm64 where we can now prove that a "full" strength reduction is allowable more often.

The SCEV analysis does not care about the value of something once it is
seen to be invariant inside the loop we are currently analyzing. This
was problematic for this logic that tries to peel additions away from
offsets; for arm64, we may have hoisted `array + 0x10` outside the loop,
which would cause us to fail to get back to the base array.

Switch the reasoning to use VNs and peel the offsets from the VNs
instead.

No x64 diffs are expected as we do not hoist the `array + 0x10` out of
the loop there. Improvements expected on arm64 where we can now prove
that a "full" strength reduction is allowable more often.
@dotnet-issue-labeler dotnet-issue-labeler bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Jul 19, 2024
Copy link
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

@jakobbotsch jakobbotsch marked this pull request as ready for review July 19, 2024 21:55
@jakobbotsch
Copy link
Member Author

cc @dotnet/jit-contrib PTAL @AndyAyersMS

Seeing good arm64 diffs from this locally: https://gist.github.com/jakobbotsch/dc38a954c2c6027f469ad1b8324831bf

Looks like JIT-EE GUID changed and the collection isn't done so probably won't get any CI diffs here until tomorrow.


*offset = 0;
VNFuncApp app;
while (GetVNFunc(*vn, &app) && (app.m_func == VNF_ADD))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like VN ought to commute so that constants are (say) rightmost / and or fold chains of constant adds... but I take it you're seeing add chains or mixtures of constants left and right.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest I haven't checked whether we see cases that require the extra unwrapping... I just wrote this one fully generally to match gtPeelOffsets and Scev::PeelAdditions.
We do canonicalize commutative operators, but only in terms of raw VN number, keeping the smallest VN number as op1. Definitely seems like we could make sure constants go to the right.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely seems like we could make sure constants go to the right.

I remember I tried that but found no diffs

@jakobbotsch
Copy link
Member Author

Final diffs here: https://dev.azure.com/dnceng-public/public/_build/results?buildId=748554&view=ms.vss-build-web.run-extensions-tab
Looks like we are missing some key collection for linux-arm64/osx-arm64. Let's see if tomorrow's collection fixes that.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants