Skip to content

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

Merged
jeffschwMSFT merged 10 commits into
release/6.0from
backport/pr-57282-to-release/6.0-rc1
Aug 27, 2021
Merged

[release/6.0] Fix VN incorrect optimizations with a new JitEEInterface function.#58005
jeffschwMSFT merged 10 commits into
release/6.0from
backport/pr-57282-to-release/6.0-rc1

Conversation

@github-actions

@github-actionsgithub-actionsBot commented Aug 24, 2021

Copy link
Copy Markdown
Contributor

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.

publicstaticvoidProblem(){S2s2;S1s1;S0s0;s1=default;s0.F0_UByte=1;s1.F0_S0=s0;s2.F0_S1=s1;Console.WriteLine(s2.F0_S1.F0_S0.F0_UByte);}structS0{publicbyteF0_UByte;}structS1{publicS0F0_S0;publicbyteDummy;}structS2{publicS1F0_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.

Sergeyand 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.
@ghostghost 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
Copy Markdown

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:-

@sandreenkosandreenko added the Servicing-consider Issue for next servicing release review label Aug 24, 2021
@sandreenkosandreenko added this to the 6.0.0 milestone Aug 24, 2021

@jakobbotschjakobbotsch left a comment

Copy link
Copy Markdown
Member

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
Copy Markdown
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
Copy Markdown
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.

@jeffschwMSFTjeffschwMSFT 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.0August 26, 2021 14:54
@sandreenko

Copy link
Copy Markdown
Contributor

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

@jeffschwMSFTjeffschwMSFT left a comment

Copy link
Copy Markdown
Member

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.

@jeffschwMSFTjeffschwMSFT 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
Copy Markdown
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.0Aug 27, 2021
@akoeplinger
akoeplinger deleted the backport/pr-57282-to-release/6.0-rc1 branch August 28, 2021 22:04
@ghostghost locked as resolved and limited conversation to collaborators Sep 27, 2021
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-CodeGen-coreclrCLR 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

@sandreenko@jeffschwMSFT@jakobbotsch@AndyAyersMS@briansull@davidwrighton