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

[release/6.0] Fix VN incorrect optimizations with a new JitEEInterface function. #58005

Merged
merged 10 commits into from
Aug 27, 2021

Conversation

github-actions[bot]
Copy link
Contributor

@github-actions github-actions bot commented Aug 24, 2021

Backport of #57282 to release/6.0

/cc @sandreenko

Customer Impact

If the issue is not fixed it could lead to bad codegen on a simple C# code.

public static void Problem()
{
    S2 s2;
    S1 s1;
    S0 s0;

    s1 = default;
    s0.F0_UByte = 1;
    s1.F0_S0 = s0;
    s2.F0_S1 = s1;

    Console.WriteLine(s2.F0_S1.F0_S0.F0_UByte);
}

struct S0
{
    public byte F0_UByte;
}

struct S1
{
    public S0 F0_S0;
    public byte Dummy;
}

struct S2
{
    public S1 F0_S1;
}

There are cases where crossgen2 images could have worse code because crossgen can use both canon- and exact fieldHndl and we accept only canon. The regressions are very small, in libs there is only 1 library out of 272 where it happens:

Top file regressions (bytes):
          37 : Microsoft.CodeAnalysis.CSharp.dasm (0.00% of base)

1 total files with Code Size differences (0 improved, 1 regressed), 271 unchanged.

Testing

There are many tests that were failing without this fix (#42517, #49954, #54102, #56980) + many more fizzling cases.
The main PR has passed jitstress/outerloop/libraries-jitstress + all the failing tests.

Regression

Yes - #48377

Risk

Low - we have many tests cases, we understand the issue and the fix is conservative. The fix uses VM that we understand well and min changes in the Value Numbering. We have manually analyzed dozens of CI test failures, all look like CI infra noise.

Sergey and others added 10 commits August 24, 2021 10:01
with a naive implementation so far.
It appeared that we have many trees where we generate unique VN for rhs and don't inform `fgValueNumberBlockAssignment` about it.
For example, for
```
N005 ( 10,  8) [000033] -A--G---R---              *  ASG       struct (copy)
N004 (  3,  2) [000031] D------N----              +--*  LCL_VAR   struct<eightByteStruct, 8> V01 loc1         d:2
N003 (  6,  5) [000030] n---G-------              \--*  IND       struct
N002 (  3,  3) [000043] ------------                 \--*  ADDR      byref
N001 (  3,  2) [000044] -------N----                    \--*  LCL_VAR   struct<largeStruct, 32> V00 loc0         u:6 (last use)
```
we will generate unique rhs but then `fgValueNumberBlockAssignment` will still try to work it as with a non-unique one.
For a tree like:
```
N005 ( 11, 10) [001400] -A------R----             *  ASG       long
N004 (  6,  5) [001401] *------N-----             +--*  IND       long
N003 (  3,  3) [001402] -------------             |  \--*  ADDR      byref  Zero Fseq[_00]
N002 (  3,  2) [001403] U------N-----             |     \--*  LCL_VAR   struct<System.Runtime.Intrinsics.Vector128`1[Byte], 16> V45 tmp38        ud:3->4
N001 (  1,  1) [001404] -------------             \--*  LCL_VAR   long   V69 tmp62        u:2 (last use)
```
SSA was working correctly and printing that `001403` is using SSA-3 and defining SSA-4. However, this code, for some reason, was writing result as a define for SSA-3.
@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 Aug 24, 2021
@ghost
Copy link

ghost commented Aug 24, 2021

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

Issue Details

Backport of #57282 to release/6.0-rc1

/cc @sandreenko

Customer Impact

Testing

Risk

Author: github-actions[bot]
Assignees: -
Labels:

area-CodeGen-coreclr

Milestone: -

@sandreenko sandreenko added the Servicing-consider Issue for next servicing release review label Aug 24, 2021
@sandreenko sandreenko added this to the 6.0.0 milestone Aug 24, 2021
@sandreenko sandreenko requested a review from jakobbotsch August 24, 2021 10:16
Copy link
Member

@jakobbotsch jakobbotsch left a comment

Choose a reason for hiding this comment

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

LGTM. I checked several hundred more examples with main and all of them are fixed.


haveCorrectFieldForVN =
compiler->info.compCompHnd->doesFieldBelongToClass(field->gtFldHnd, clsHnd);
noway_assert(haveCorrectFieldForVN);
Copy link
Contributor

Choose a reason for hiding this comment

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

The new method doesFieldBelongToClass has to return true here otherwise we will terminate the program.

The only place that doesFieldBelongToClass can return false is above at line 276.

Copy link
Contributor

Choose a reason for hiding this comment

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

we won't terminate the program, we will terminate the current method compilation and recompile in minopts.

@jeffschwMSFT jeffschwMSFT removed the Servicing-consider Issue for next servicing release review label Aug 24, 2021
@sandreenko sandreenko changed the base branch from release/6.0-rc1 to release/6.0 August 26, 2021 14:54
@sandreenko
Copy link
Contributor

I have changed the target branch from 6.0-RC1 to 6.0 (RC2).

Copy link
Member

@jeffschwMSFT jeffschwMSFT left a comment

Choose a reason for hiding this comment

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

Approved. Once we have a green CI we can merge.

@jeffschwMSFT jeffschwMSFT changed the title [release/6.0-rc1] Fix VN incorrect optimizations with a new JitEEInterface function. [release/6.0] Fix VN incorrect optimizations with a new JitEEInterface function. Aug 26, 2021
@jeffschwMSFT
Copy link
Member

@Anipik can you help merge this? The CI is green, but the build analysis shows red.

@jeffschwMSFT jeffschwMSFT merged commit e209402 into release/6.0 Aug 27, 2021
@akoeplinger akoeplinger deleted the backport/pr-57282-to-release/6.0-rc1 branch August 28, 2021 22:04
@ghost ghost locked as resolved and limited conversation to collaborators Sep 27, 2021
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.

6 participants