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

Valuetype ref return x64jit fix #1301

Merged
merged 2 commits into from
Jun 2, 2020

Conversation

jvalenzu
Copy link

@jvalenzu jvalenzu commented May 31, 2020

When we have the following sequence:

    ldloc n
    ldfld valuetype [Unity.Mathematics]Unity.Mathematics.int2 Foo::bar

and local n is a reference to value, when walking the instructions in
mono_method_to_ir, we generally try to avoid loading a whole value
type just to load one of the fields. I believe this is an
optimization.

The test here is not quite complete, though, as we have ref valuetypes
where the object stored at the location is actually an address, in
which case we still need to treat it as we would a normal reference.

This optimization isn't present in the ldloc.n coded forms and is
written in a slightly more robust way in ldloc.s, so no changes are
necessary there.

As an alternative to this commit, we might adopt a simplified version of the ldloc.s test for
ldloc as well, or merge in
mono@29428d9/mono/mini/method-to-ir.c
from master which encapsulates much the same intent.

Associated bug: https://fogbugz.unity3d.com/f/cases/1252663/

When we have the following sequence:

    ldloc n
    ldfld valuetype [Unity.Mathematics]Unity.Mathematics.int2 Foo::bar

and local n is a reference to value, when walking the instructions in
mono_method_to_ir, we generally try to avoid loading a whole value
type just to load one of the fields.  I believe this is an
optimization.

The test here is not quite complete, though, as we have ref valuetypes
where the object stored at the location is actually an address, in
which case we still need to treat it as we would a normal reference.

This optimization isn't present in the ldloc.n coded forms and is
written in a slightly more robust way in ldloc.s, so no changes are
necessary there.

As an alternative to this commit, we might adopt the ldloc.s test for
ldloc as well, or merge in
mono@29428d9/mono/mini/method-to-ir.c
from master which encapsulates much the same intent.
@joncham joncham requested review from joncham and removed request for jonathan-unity June 2, 2020 12:49
@jvalenzu jvalenzu changed the base branch from master to unity-master June 2, 2020 13:01
@jvalenzu jvalenzu marked this pull request as ready for review June 2, 2020 13:02
Same method that ldloc.s uses, which incorporates the byref test.
Copy link

@midopooler midopooler left a comment

Choose a reason for hiding this comment

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

LGTM

@joncham joncham merged commit 79a0da3 into unity-master Jun 2, 2020
@joncham joncham deleted the valuetype-ref-return-x64jit-fix branch June 2, 2020 18:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants