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: Fix reordering of call args on x86 #70931

Merged
merged 2 commits into from
Jun 21, 2022

Conversation

jakobbotsch
Copy link
Member

On x86 we skipped checking stack arguments for side effects with a
comment that such arguments do not need to be evaluated into temps.
While this is true a large part of the logic that follows is responsible
for evaluating previous arguments into temps, and we must still do this.

On x86 we skipped checking stack arguments for side effects with a
comment that such arguments do not need to be evaluated into temps.
While this is true a large part of the logic that follows is responsible
for evaluating previous arguments into temps, and we must still do this.
@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 Jun 18, 2022
@ghost ghost assigned jakobbotsch Jun 18, 2022
@ghost
Copy link

ghost commented Jun 18, 2022

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

Issue Details

On x86 we skipped checking stack arguments for side effects with a
comment that such arguments do not need to be evaluated into temps.
While this is true a large part of the logic that follows is responsible
for evaluating previous arguments into temps, and we must still do this.

Author: jakobbotsch
Assignees: -
Labels:

area-CodeGen-coreclr

Milestone: -

Comment on lines -793 to -796
#ifdef FEATURE_FIXED_OUT_ARGS
|| arg.m_isTmp // Protect this by "FEATURE_FIXED_OUT_ARGS" to preserve the property
// that we only have late non-register args when that feature is on.
#endif
Copy link
Member Author

Choose a reason for hiding this comment

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

FEATURE_FIXED_OUT_ARGS is defined even on x86, just with value 0, so this #ifdef was always true. The point of this check is to catch when fgMakeOutgoingStructArgCopy has left a non-value node, and it only does this for FEATURE_FIXED_OUT_ARGS, so I have fixed the logic.

@jakobbotsch
Copy link
Member Author

We will have test coverage for this once we loosen up the restrictions on forward subbing into function args. I expect we can do that once this and #70893 are merged.

@jakobbotsch
Copy link
Member Author

/azp run runtime-coreclr superpmi-diffs

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jakobbotsch
Copy link
Member Author

jakobbotsch commented Jun 21, 2022

The regressions look more reasonable now after #70986:

benchmarks.run.windows.x86.checked.mch:

Summary of Code Size diffs:
(Lower is better)

Total bytes of base: 8959310 (overridden on cmd)
Total bytes of diff: 8961437 (overridden on cmd)
Total bytes of delta: 2127 (0.02 % of base)
    diff is a regression.
    relative diff is a regression.
Detail diffs
coreclr_tests.pmi.windows.x86.checked.mch:

Summary of Code Size diffs:
(Lower is better)

Total bytes of base: 108583802 (overridden on cmd)
Total bytes of diff: 108588041 (overridden on cmd)
Total bytes of delta: 4239 (0.00 % of base)
    diff is a regression.
    relative diff is a regression.
Detail diffs
libraries.crossgen2.windows.x86.checked.mch:

Summary of Code Size diffs:
(Lower is better)

Total bytes of base: 26746067 (overridden on cmd)
Total bytes of diff: 26747642 (overridden on cmd)
Total bytes of delta: 1575 (0.01 % of base)
    diff is a regression.
    relative diff is a regression.
Detail diffs
libraries.pmi.windows.x86.checked.mch:

Summary of Code Size diffs:
(Lower is better)

Total bytes of base: 39964335 (overridden on cmd)
Total bytes of diff: 39965543 (overridden on cmd)
Total bytes of delta: 1208 (0.00 % of base)
    diff is a regression.
    relative diff is a regression.
Detail diffs
libraries_tests.pmi.windows.x86.checked.mch:

Summary of Code Size diffs:
(Lower is better)

Total bytes of base: 98150856 (overridden on cmd)
Total bytes of diff: 98162012 (overridden on cmd)
Total bytes of delta: 11156 (0.01 % of base)
    diff is a regression.
    relative diff is a regression.

I've spot checked a few and they were cases where we were unsafely reordering things. In some cases we were reordering field accesses with static constructor initialization, which seems could cause observable behavior differences. In some other cases the reordering we did was ok but we do not have the necessary analysis to determine that it is ok (e.g. if stack arguments contained embedded assignments we could previously reorder them with register arguments without doing any checks, which is unsafe).

cc @dotnet/jit-contrib PTAL @AndyAyersMS

@jakobbotsch
Copy link
Member Author

jakobbotsch commented Jun 21, 2022

For example:

using System;

public class Program
{
    public static string[] Array = new string[1];

    static Program()
    {
        Array[0] = Foo.Before; // Turns into CORINFO_HELP_ARRADDR_ST call, for which we reordered args on x86 before
    }

    public static void Main()
    {
        Console.WriteLine(Array[0]);
    }

    static class Foo
    {
        public static string Before = "Before";
        static Foo()
        {
            Program.Array = new[] { "After" };
        }
    }
}

non-x86 output: After
x86 output before this change: Before

This kind of reordering is the cause of the majority of the diffs in benchmarks: a single method (MessagePack.MessagePackBinary.cctor) had extensive reordering of this form before this change.

@jakobbotsch jakobbotsch merged commit 43be83a into dotnet:main Jun 21, 2022
@jakobbotsch jakobbotsch deleted the fix-args-morphing-x86 branch June 21, 2022 16:03
@ghost ghost locked as resolved and limited conversation to collaborators Jul 21, 2022
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.

2 participants